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