001/*
002 * (C) Copyright 2015 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 *     Nelson Silva
018 */
019package org.nuxeo.functionaltests.pages.admincenter.usermanagement;
020
021import org.nuxeo.functionaltests.AbstractTest;
022import org.nuxeo.functionaltests.AjaxRequestManager;
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 * Groups Tab Page of the users & groups management
032 *
033 * @since 7.2
034 */
035public class GroupsTabSubPage extends UsersGroupsBasePage {
036
037    @Required
038    @FindBy(id = "groupsListingView:createGroupActionsForm:createGroupButton")
039    WebElement createNewGroupLink;
040
041    @FindBy(id = "groupsListingView:searchForm:searchText")
042    WebElement searchInput;
043
044    @FindBy(id = "groupsListingView:searchForm:searchButton")
045    WebElement searchButton;
046
047    public GroupsTabSubPage(WebDriver driver) {
048        super(driver);
049    }
050
051    public GroupCreationFormPage getGroupCreatePage() {
052        createNewGroupLink.click();
053        return asPage(GroupCreationFormPage.class);
054    }
055
056    public GroupsTabSubPage searchGroup(String query) {
057        searchInput.clear();
058        searchInput.sendKeys(query);
059        AjaxRequestManager arm = new AjaxRequestManager(driver);
060        arm.begin();
061        searchButton.click();
062        arm.end();
063        return asPage(GroupsTabSubPage.class);
064    }
065
066    /**
067     * Checks if the group was found in the last search result page.
068     */
069    public boolean isGroupFound(String groupname) {
070        try {
071            findElementWithTimeout(By.linkText(groupname), AbstractTest.LOAD_SHORT_TIMEOUT_SECONDS * 1000);
072        } catch (NoSuchElementException e) {
073            return false;
074        }
075        return true;
076    }
077
078    public GroupViewTabSubPage viewGroup(String groupname) {
079        findElementWithTimeout(By.linkText(groupname)).click();
080        return asPage(GroupViewTabSubPage.class);
081    }
082
083}