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