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