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