001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thierry Delprat
016 */
017package org.nuxeo.functionaltests.pages.admincenter;
018
019import java.util.ArrayList;
020import java.util.List;
021
022import org.nuxeo.functionaltests.Required;
023import org.nuxeo.functionaltests.pages.AbstractPage;
024import org.nuxeo.functionaltests.pages.DocumentBasePage;
025import org.nuxeo.functionaltests.pages.admincenter.activity.ActivityPage;
026import org.nuxeo.functionaltests.pages.admincenter.monitoring.MonitoringPage;
027import org.nuxeo.functionaltests.pages.admincenter.usermanagement.UsersGroupsBasePage;
028import org.openqa.selenium.By;
029import org.openqa.selenium.WebDriver;
030import org.openqa.selenium.WebElement;
031import org.openqa.selenium.support.FindBy;
032
033public class AdminCenterBasePage extends AbstractPage {
034
035    // for ajax refresh wait until by adding required element
036    @Required
037    @FindBy(linkText = "System Information")
038    public WebElement systemInformationLink;
039
040    @FindBy(linkText = "Users & Groups")
041    public WebElement userAndGroupsLink;
042
043    @FindBy(linkText = "WORKSPACE")
044    public WebElement documentManagementLink;
045
046    @FindBy(linkText = "Update Center")
047    public WebElement updateCenterLink;
048
049    @FindBy(linkText = "Monitoring")
050    public WebElement monitoringLink;
051
052    @FindBy(linkText = "Nuxeo Online Services")
053    public WebElement nuxeoConnectLink;
054
055    @FindBy(linkText = "Vocabularies")
056    public WebElement vocabulariesLink;
057
058    @FindBy(linkText = "Workflow")
059    public WebElement worflowsLink;
060
061    @FindBy(linkText = "Activity")
062    public WebElement activityLink;
063
064    public AdminCenterBasePage(WebDriver driver) {
065        super(driver);
066    }
067
068    protected void clickOnTab(WebElement tab) {
069        clickOnTab(tab, useAjaxTabs());
070    }
071
072    protected void clickOnTab(WebElement tab, boolean useAjax) {
073        clickOnTabIfNotSelected("nxw_adminCenterTabs_panel", tab, useAjax);
074    }
075
076    public UsersGroupsBasePage getUsersGroupsHomePage() {
077        clickOnTab(userAndGroupsLink);
078        return asPage(UsersGroupsBasePage.class);
079    }
080
081    public ConnectHomePage getConnectHomePage() {
082        clickOnTab(nuxeoConnectLink);
083        return asPage(ConnectHomePage.class);
084    }
085
086    public UpdateCenterPage getUpdateCenterHomePage() {
087        clickOnTab(updateCenterLink);
088        return asPage(UpdateCenterPage.class);
089    }
090
091    public MonitoringPage getMonitoringPage() {
092        clickOnTab(monitoringLink);
093        return asPage(MonitoringPage.class);
094    }
095
096    public SystemHomePage getSystemHomePage() {
097        clickOnTab(systemInformationLink);
098        return asPage(SystemHomePage.class);
099    }
100
101    public VocabulariesPage getVocabulariesPage() {
102        clickOnTab(vocabulariesLink);
103        return asPage(VocabulariesPage.class);
104    }
105
106    public WorkflowsPage getWorkflowsPage() {
107        clickOnTab(worflowsLink);
108        return asPage(WorkflowsPage.class);
109    }
110
111    public ActivityPage getActivityPage() {
112        // not ajaxified
113        clickOnTab(activityLink, false);
114        return asPage(ActivityPage.class);
115    }
116
117    public String getSelectedSubTab() {
118        WebElement tab = findElementWithTimeout(By.xpath("//div[@id='nxw_adminCenterSubTabs_panel']//li[@class='selected']//a"));
119        if (tab != null) {
120            return tab.getText();
121        }
122        return null;
123    }
124
125    public AdminCenterBasePage selectSubTab(String text) {
126        WebElement tab = findElementWithTimeout(By.xpath("//div[@id='nxw_adminCenterSubTabs_panel']//li/form/a/span[text()='"
127                + text + "']"));
128        if (tab != null) {
129            tab.click();
130            return asPage(AdminCenterBasePage.class);
131
132        }
133        return null;
134    }
135
136    public List<String> getAvailableSubTabs() {
137        List<WebElement> elements = driver.findElements(By.xpath("//div[@id='nxw_adminCenterSubTabs_panel']//li/form/a/span"));
138        List<String> tabs = new ArrayList<String>();
139
140        for (WebElement el : elements) {
141            tabs.add(el.getText());
142        }
143        return tabs;
144    }
145
146    public DocumentBasePage exitAdminCenter() {
147        documentManagementLink.click();
148        return asPage(DocumentBasePage.class);
149    }
150}