001/*
002 * (C) Copyright 2011 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 *     Benoit Delbosc
016 */
017package org.nuxeo.functionaltests.pages.usermanagement.compat;
018
019import org.nuxeo.functionaltests.Required;
020import org.openqa.selenium.By;
021import org.openqa.selenium.NoSuchElementException;
022import org.openqa.selenium.WebDriver;
023import org.openqa.selenium.WebElement;
024import org.openqa.selenium.support.FindBy;
025
026/**
027 * View user details
028 */
029public class UserEditFormPage extends UsersGroupsBasePage {
030
031    @Required
032    @FindBy(id = "editUser:nxl_user:nxw_firstname")
033    WebElement firstnameInput;
034
035    @Required
036    @FindBy(id = "editUser:nxl_user:nxw_lastname")
037    WebElement lastnameInput;
038
039    @Required
040    @FindBy(id = "editUser:nxl_user:nxw_company")
041    WebElement companyInput;
042
043    @Required
044    @FindBy(id = "editUser:nxl_user:nxw_email")
045    WebElement emailInput;
046
047    @Required
048    @FindBy(id = "editUser:nxl_user:nxw_groups_suggest")
049    WebElement groupInput;
050
051    @Required
052    @FindBy(xpath = "//form[@id=\"editUser\"]//input[@value=\"Save\"]")
053    WebElement saveButton;
054
055    public UserEditFormPage(WebDriver driver) {
056        super(driver);
057    }
058
059    /**
060     * Edit a user, only update non null value.
061     *
062     * @param firstname
063     * @param lastname
064     * @param company
065     * @param email
066     * @param password
067     * @param group
068     * @throws NoSuchElementException
069     */
070    public UserViewTabSubPage editUser(String firstname, String lastname, String company, String email, String group)
071            throws NoSuchElementException {
072        updateInput(firstnameInput, firstname);
073        updateInput(lastnameInput, lastname);
074        updateInput(companyInput, company);
075        updateInput(emailInput, email);
076        if (group != null) {
077            groupInput.sendKeys(group);
078            WebElement ajaxUserListElement = findElementWithTimeout(By.xpath("//table[@id='editUser:nxl_user:nxw_groups_suggestionBox:suggest']/tbody/tr[1]/td[2]"));
079            ajaxUserListElement.click();
080        }
081        saveButton.click();
082        return asPage(UserViewTabSubPage.class);
083    }
084
085    private void updateInput(WebElement elem, String value) {
086        if (value != null) {
087            elem.clear();
088            elem.sendKeys(value);
089        }
090    }
091
092}