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