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 *     Antoine Taillefer
017 */
018package org.nuxeo.functionaltests.pages.admincenter.usermanagement;
019
020import org.nuxeo.functionaltests.AbstractTest;
021import org.nuxeo.functionaltests.Required;
022import org.openqa.selenium.By;
023import org.openqa.selenium.NoSuchElementException;
024import org.openqa.selenium.WebDriver;
025import org.openqa.selenium.WebElement;
026import org.openqa.selenium.support.FindBy;
027
028/**
029 * Users Tab Page of the users & groups management (New one in the admin center)
030 *
031 * @since 5.4.2
032 */
033public class UsersTabSubPage extends UsersGroupsBasePage {
034
035    @Required
036    @FindBy(id = "usersListingView:createUserActionsForm:createUserButton")
037    WebElement createNewUserLink;
038
039    @FindBy(id = "usersListingView:searchForm:searchText")
040    WebElement searchInput;
041
042    @FindBy(id = "usersListingView:searchForm:searchButton")
043    WebElement searchButton;
044
045    public UsersTabSubPage(WebDriver driver) {
046        super(driver);
047    }
048
049    public UserCreationFormPage getUserCreatePage() {
050        createNewUserLink.click();
051        return asPage(UserCreationFormPage.class);
052    }
053
054    public UsersTabSubPage searchUser(String query) {
055        searchInput.clear();
056        searchInput.sendKeys(query);
057        searchButton.submit();
058        return asPage(UsersTabSubPage.class);
059    }
060
061    /**
062     * Is the username was found in the last search result page.
063     */
064    public boolean isUserFound(String username) {
065        try {
066            findElementWithTimeout(By.linkText(username), AbstractTest.LOAD_SHORT_TIMEOUT_SECONDS * 1000);
067        } catch (NoSuchElementException e) {
068            return false;
069        }
070        return true;
071    }
072
073    public UserViewTabSubPage viewUser(String username) {
074        findElementWithTimeout(By.linkText(username)).click();
075        return asPage(UserViewTabSubPage.class);
076    }
077
078}