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    @FindBy(id = "groupsListingView:createGroupActionsForm:createGroupButton")
038    WebElement createNewGroupLink;
039
040    @Required
041    @FindBy(id = "groupsListingView:searchForm:searchText")
042    WebElement searchInput;
043
044    @Required
045    @FindBy(id = "groupsListingView:searchForm:searchButton")
046    WebElement searchButton;
047
048    public GroupsTabSubPage(WebDriver driver) {
049        super(driver);
050    }
051
052    public GroupCreationFormPage getGroupCreatePage() {
053        createNewGroupLink.click();
054        return asPage(GroupCreationFormPage.class);
055    }
056
057    public GroupsTabSubPage searchGroup(String query) {
058        searchInput.clear();
059        searchInput.sendKeys(query);
060        AjaxRequestManager arm = new AjaxRequestManager(driver);
061        arm.begin();
062        searchButton.click();
063        arm.end();
064        return asPage(GroupsTabSubPage.class);
065    }
066
067    /**
068     * Checks if the group was found in the last search result page.
069     */
070    public boolean isGroupFound(String groupname) {
071        try {
072            findElementWithTimeout(By.linkText(groupname), AbstractTest.LOAD_SHORT_TIMEOUT_SECONDS * 1000);
073        } catch (NoSuchElementException e) {
074            return false;
075        }
076        return true;
077    }
078
079    public GroupViewTabSubPage viewGroup(String groupname) {
080        findElementWithTimeout(By.linkText(groupname)).click();
081        return asPage(GroupViewTabSubPage.class);
082    }
083
084}