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