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.Required;
020import org.nuxeo.functionaltests.forms.Select2WidgetElement;
021import org.openqa.selenium.NoSuchElementException;
022import org.openqa.selenium.WebDriver;
023import org.openqa.selenium.WebElement;
024import org.openqa.selenium.support.FindBy;
025
026/**
027 * Group creation form page.
028 *
029 * @since 7.2
030 */
031public class GroupCreationFormPage extends UsersGroupsBasePage {
032
033
034    @FindBy(id = "createGroupView:createGroup:nxl_group:nxw_group_name")
035    WebElement nameInput;
036
037    @FindBy(id = "createGroupView:createGroup:nxl_group:nxw_group_label")
038    WebElement labelInput;
039
040    @Required
041    @FindBy(id = "s2id_createGroupView:createGroup:nxl_group:nxw_group_members_select2")
042    WebElement membersSelect;
043
044    @Required
045    @FindBy(id = "s2id_createGroupView:createGroup:nxl_group:nxw_group_subgroups_select2")
046    WebElement subgroupsSelect;
047
048    @FindBy(id = "createGroupView:createGroup:button_save")
049    WebElement createButton;
050
051    @Required
052    @FindBy(xpath = "//div[@class=\"tabsContent\"]//input[@value=\"Cancel\"]")
053    WebElement cancelButton;
054
055    public GroupCreationFormPage(WebDriver driver) {
056        super(driver);
057    }
058
059    public UsersGroupsBasePage createGroup(String name, String label, String[] members, String[] subgroups)
060            throws NoSuchElementException {
061        nameInput.sendKeys(name);
062        labelInput.sendKeys(label);
063        if (members != null) {
064            new Select2WidgetElement(driver, membersSelect, true).selectValues(members);
065        }
066        if (subgroups != null) {
067            new Select2WidgetElement(driver, subgroupsSelect, true).selectValues(subgroups);
068        }
069        createButton.click();
070        return asPage(UsersGroupsBasePage.class);
071    }
072
073    public GroupsTabSubPage cancelCreation() {
074        cancelButton.click();
075        return asPage(GroupsTabSubPage.class);
076    }
077}