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 *     Benoit Delbosc
016 *     Nelson Silva
017 */
018package org.nuxeo.functionaltests.pages.admincenter.usermanagement;
019
020import static org.junit.Assert.assertNotNull;
021
022import org.nuxeo.functionaltests.Required;
023import org.nuxeo.functionaltests.pages.admincenter.AdminCenterBasePage;
024import org.openqa.selenium.WebDriver;
025import org.openqa.selenium.WebElement;
026import org.openqa.selenium.support.FindBy;
027
028/**
029 * Nuxeo User and Groups Base page. (New one in the admin center)
030 *
031 * @since 5.4.2
032 */
033public class UsersGroupsBasePage extends AdminCenterBasePage {
034
035    @FindBy(xpath = "//div[@id=\"nxw_adminCenterSubTabs_panel\"]/ul/li[@class=\"selected\"]/form/a")
036    public WebElement selectedTab;
037
038    @Required
039    @FindBy(xpath = "//a[@id=\"nxw_UsersManager_form:nxw_UsersManager\"]")
040    public WebElement usersTabLink;
041
042    @Required
043    @FindBy(xpath = "//a[@id=\"nxw_GroupsManager_form:nxw_GroupsManager\"]")
044    public WebElement groupsTabLink;
045
046    protected void clickOnLinkIfNotSelected(WebElement tabLink) {
047        assertNotNull(tabLink);
048        assertNotNull(selectedTab);
049
050        if (!selectedTab.equals(tabLink)) {
051            tabLink.click();
052        }
053    }
054
055    public UsersGroupsBasePage(WebDriver driver) {
056        super(driver);
057    }
058
059    /**
060     * View the Users tab.
061     */
062    public UsersTabSubPage getUsersTab(boolean force) {
063        if (force) {
064            usersTabLink.click();
065        } else {
066            clickOnLinkIfNotSelected(usersTabLink);
067        }
068        return asPage(UsersTabSubPage.class);
069    }
070
071    public UsersTabSubPage getUsersTab() {
072        return getUsersTab(false);
073    }
074
075    /**
076     * View the Groups tab.
077     */
078    public GroupsTabSubPage getGroupsTab(boolean force) {
079        if (force) {
080            groupsTabLink.click();
081        } else {
082            clickOnLinkIfNotSelected(groupsTabLink);
083        }
084        return asPage(GroupsTabSubPage.class);
085    }
086
087    public GroupsTabSubPage getGroupsTab() {
088        return getGroupsTab(false);
089    }
090}