    001/*
    002    Licensed to the Apache Software Foundation (ASF) under one
    003    or more contributor license agreements.  See the NOTICE file
    004    distributed with this work for additional information
    005    regarding copyright ownership.  The ASF licenses this file
    006    to you under the Apache License, Version 2.0 (the
    007    "License"); you may not use this file except in compliance
    008    with the License.  You may obtain a copy of the License at
    009
    010       http://www.apache.org/licenses/LICENSE-2.0
    011
    012    Unless required by applicable law or agreed to in writing,
    013    software distributed under the License is distributed on an
    014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015    KIND, either express or implied.  See the License for the
    016    specific language governing permissions and limitations
    017    under the License.
    018 */
    019package org.apache.wiki.pages.haddock;
    020
    021import org.apache.wiki.pages.Page;
    022import org.openqa.selenium.By;
    023
    024import com.codeborne.selenide.Condition;
    025import com.codeborne.selenide.Selenide;
    026import com.codeborne.selenide.SelenideElement;
    027
    028import java.time.Duration;
    029
    030/**
    031 * Actions available on the View page.
    032 */
    033public class ViewWikiPage implements HaddockPage {
    034
    035    /**
    036     * Open a given page for view.
    037     *
    038     * @param pageName Wiki page name to View.
    039     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
    040     */
    041    public static ViewWikiPage open(final String pageName ) {
    042        return Page.withUrl( Page.baseUrl() + "/Wiki.jsp?page=" + pageName ).openAs( new ViewWikiPage() );
    043    }
    044
    045    /**
    046     * Returns the authenticated user text.
    047     *
    048     * @return the authenticated user text.
    049     */
    050    public String authenticatedText() {
    051        return Selenide.$( By.className( "wikipage" ) ).text().trim();
    052    }
    053
    054    /**
    055     * Clicks on the login button.
    056     *
    057     * @return {@link LoginPage} instance, to allow chaining of actions.
    058     */
    059    public LoginPage clickOnLogin() {
    060        hoverLoginArea();
    061        Selenide.$( By.className( "icon-signin" ) ).click();
    062        return new LoginPage();
    063    }
    064
    065    /**
    066     * Clicks on the show reader view link.
    067     *
    068     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
    069     */
    070    public ViewWikiPage clickOnShowReaderView() {
    071        Selenide.$( By.linkText( "Show Reader View" ) ).click();
    072        return this;
    073    }
    074
    075    /**
    076     * Hover's the user's icon, so the login area gets visible.
    077     *
    078     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
    079     */
    080    public ViewWikiPage hoverLoginArea() {
    081        Selenide.$( By.className( "icon-user" ) ).hover();
    082        return this;
    083    }
    084
    085    /**
    086     * Hover's the More tab, making its associated pane visible.
    087     *
    088     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
    089     */
    090    public ViewWikiPage hoverMoreArea() {
    091        Selenide.$( By.id( "more" ) ).hover();
    092        return this;
    093    }
    094
    095    /**
    096     * Clicks the edit link.
    097     *
    098     * @return {@link EditWikiPage} instance, to allow chaining of actions.
    099     */
    100    public EditWikiPage editPage() {
    101        Selenide.$( By.cssSelector( "li#edit a" ) ).shouldBe( Condition.visible, Duration.ofSeconds( 1L ) ).click();
    102        return new EditWikiPage();
    103    }
    104
    105    /**
    106     * Searches for a given text.
    107     *
    108     * @param text text to search for.
    109     * @return {@link SearchResultsPage} instance, to allow chaining of actions.
    110     */
    111    public SearchResultsPage searchFor( final String text ) {
    112        Selenide.$( By.className( "icon-search" ) ).hover();
    113        Selenide.$( By.id( "query" ) ).click();
    114        Selenide.$( By.id( "query" ) ).val( text );
    115        Selenide.$( By.id( "searchSubmit" ) ).click();
    116        return new SearchResultsPage();
    117    }
    118
    119    /**
    120     * Logs the user out.
    121     *
    122     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
    123     */
    124    public ViewWikiPage clickOnLogout() {
    125        hoverLoginArea();
    126        Selenide.$( By.linkText( "Log out" ) ).click();
    127        Selenide.$( By.className( "btn-success" ) ).shouldBe( Condition.visible, Duration.ofSeconds( 1L ) ).click();
    128        return this;
    129    }
    130
    131    /**
    132     * Navigates to a given view page.
    133     *
    134     * @param wikiPageName wikipage name to navigate to.
    135     * @return {@link ViewWikiPage} instance, to allow chaining of actions.
    136     */
    137    public ViewWikiPage navigateTo(final String wikiPageName ) {
    138        Selenide.$( By.linkText( wikiPageName ) ).click();
    139        return this;
    140    }
    141
    142    /**
    143     * Returns the sidebar element.
    144     *
    145     * @return the sidebar element.
    146     */
    147    public SelenideElement sidebar() {
    148        return Selenide.$( By.className( "sidebar" ) );
    149    }
    150
    151}