001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     <a href="mailto:grenard@nuxeo.com">Guillaume</a>
018 */
019package org.nuxeo.functionaltests.pages;
020
021import org.nuxeo.functionaltests.AjaxRequestManager;
022import org.nuxeo.functionaltests.Locator;
023import org.nuxeo.functionaltests.Required;
024import org.openqa.selenium.By;
025import org.openqa.selenium.WebDriver;
026import org.openqa.selenium.WebElement;
027import org.openqa.selenium.support.FindBy;
028
029/**
030 * @since 5.9.3
031 */
032public class HomePage extends DocumentBasePage {
033
034    static final String USERS_GROUPS_LABEL = "Users & Groups";
035
036    static final String COLLECTIONS_LABEL = "Collections";
037
038    static final String SEARCHES_LABEL = "Searches";
039
040    @Required
041    @FindBy(id = "nxw_homeTabs_panel")
042    protected WebElement menu;
043
044    public HomePage(WebDriver driver) {
045        super(driver);
046    }
047
048    /**
049     * @since 8.3
050     */
051    public UsersGroupsHomePage goToUsersGroupsHomePage() {
052        goTo(USERS_GROUPS_LABEL);
053        return asPage(UsersGroupsHomePage.class);
054    }
055
056    public CollectionsPage goToCollections() {
057        goTo(COLLECTIONS_LABEL);
058        return asPage(CollectionsPage.class);
059    }
060
061    /**
062     * @since 8.1
063     */
064    public HomePage goToSavedSearches() {
065        goTo(SEARCHES_LABEL);
066        return asPage(HomePage.class);
067    }
068
069    /**
070     * @since 8.3
071     */
072    public void goTo(String tabLabel) {
073        if (useAjaxTabs()) {
074            AjaxRequestManager arm = new AjaxRequestManager(driver);
075            arm.begin();
076            Locator.findElementWaitUntilEnabledAndClick(menu, By.linkText(tabLabel));
077            arm.end();
078        } else {
079            Locator.findElementWaitUntilEnabledAndClick(menu, By.linkText(tabLabel));
080        }
081    }
082
083}