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 */
017package org.nuxeo.functionaltests.pages.usermanagement.compat;
018
019import static org.junit.Assert.assertNotNull;
020
021import org.nuxeo.functionaltests.Required;
022import org.nuxeo.functionaltests.pages.AbstractPage;
023import org.openqa.selenium.WebDriver;
024import org.openqa.selenium.WebElement;
025import org.openqa.selenium.support.FindBy;
026
027/**
028 * Nuxeo User and Groups Base page.
029 */
030public class UsersGroupsBasePage extends AbstractPage {
031    @FindBy(xpath = "//div[@class=\"tabsBar\"]/form/ul/li[@class=\"selected\"]/a[text()=\"Users\" or text()=\"Groups\"]")
032    public WebElement selectedTab;
033
034    @Required
035    @FindBy(xpath = "//div[@class=\"tabsBar\"]/form/ul/li/a[text()=\"Users\"]")
036    public WebElement usersTabLink;
037
038    protected void clickOnLinkIfNotSelected(WebElement tabLink) {
039        assertNotNull(tabLink);
040        assertNotNull(selectedTab);
041
042        if (!selectedTab.equals(tabLink)) {
043            tabLink.click();
044        }
045    }
046
047    public UsersGroupsBasePage(WebDriver driver) {
048        super(driver);
049    }
050
051    /**
052     * View the Users tab.
053     */
054    public UsersTabSubPage getUsersTab(boolean force) {
055        if (force) {
056            usersTabLink.click();
057        } else {
058            clickOnLinkIfNotSelected(usersTabLink);
059        }
060        return asPage(UsersTabSubPage.class);
061    }
062
063    public UsersTabSubPage getUsersTab() {
064        return getUsersTab(false);
065    }
066
067}