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