001/* 002 * (C) Copyright 2014 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-2.1.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 * <a href="mailto:grenard@nuxeo.com">Guillaume</a> 016 */ 017package org.nuxeo.functionaltests.fragment; 018 019import java.util.Arrays; 020 021import org.nuxeo.functionaltests.Locator; 022import org.nuxeo.functionaltests.Required; 023import org.openqa.selenium.By; 024import org.openqa.selenium.WebDriver; 025import org.openqa.selenium.WebElement; 026import org.openqa.selenium.support.FindBy; 027 028/** 029 * @since 5.9.3 030 */ 031public class NewVocabularyEntryForm extends WebFragmentImpl { 032 033 @FindBy(id = "addEntryView:addEntryForm:nxl_l10nsubjects_vocabulary:nxw_l10nxvocabulary_label_en") 034 @Required 035 private WebElement englishLabelInput; 036 037 @FindBy(id = "addEntryView:addEntryForm:nxl_l10nsubjects_vocabulary:nxw_l10nxvocabulary_label_fr") 038 @Required 039 private WebElement frenchLabelInput; 040 041 @FindBy(id = "addEntryView:addEntryForm:nxl_l10nsubjects_vocabulary:nxw_l10nxvocabulary_id") 042 @Required 043 private WebElement idInput; 044 045 @FindBy(id = "nxw_parent_openPopup") 046 private WebElement newParentPopup; 047 048 @FindBy(id = "addEntryView:addEntryForm:nxl_l10nsubjects_vocabulary:nxw_l10nxvocabulary_obsolete_checkbox") 049 @Required 050 private WebElement notObsoleteInput; 051 052 @FindBy(id = "addEntryView:addEntryForm:nxl_l10nsubjects_vocabulary:nxw_l10nxvocabulary_obsolete_checkbox") 053 @Required 054 private WebElement obsoleteInput; 055 056 @FindBy(id = "addEntryView:addEntryForm:nxl_l10nsubjects_vocabulary:nxw_l10nxvocabulary_order") 057 @Required 058 private WebElement orderInput; 059 060 public NewVocabularyEntryForm(WebDriver driver, WebElement element) { 061 super(driver, element); 062 } 063 064 private void findParentNodeAndSelect(final WebElement selectParentFancyBox, final String[] path) { 065 if (path.length == 1) { 066 selectParentFancyBox.findElement(By.linkText(path[0])).click(); 067 } else { 068 WebElement node = selectParentFancyBox.findElement(By.xpath("//table[contains(text(),'" + path[0] + "')]")); 069 node.findElement(By.xpath("tbody/tr[1]/td[1]/div/a")).click(); 070 findParentNodeAndSelect(selectParentFancyBox, Arrays.copyOfRange(path, 1, path.length)); 071 } 072 } 073 074 public void save() { 075 getElement().findElement(By.xpath("//input[@value='Create']")).click(); 076 } 077 078 public void setNewVocabularyEnglishLabel(final String vocabularyEnglishLabel) { 079 englishLabelInput.sendKeys(vocabularyEnglishLabel); 080 } 081 082 public void setNewVocabularyFrenchLabel(final String vocabularyFrenchLabel) { 083 frenchLabelInput.sendKeys(vocabularyFrenchLabel); 084 } 085 086 public void setNewVocabularyId(final String vocabularyId) { 087 idInput.sendKeys(vocabularyId); 088 } 089 090 public void setNewVocabularyObsolete(final boolean obsolete) { 091 if (obsolete) { 092 obsoleteInput.click(); 093 } else { 094 notObsoleteInput.click(); 095 } 096 } 097 098 public void setNewVocabularyOrder(final int vocabularyOrder) { 099 orderInput.clear(); 100 orderInput.sendKeys(vocabularyOrder + ""); 101 } 102 103 public void setNewVocabularyParentId(final String parentLabelPath) { 104 newParentPopup.click(); 105 WebElement selectParentFancyBox = Locator.findElementWithTimeout(By.id("fancybox-content")); 106 String[] split = parentLabelPath.split("/"); 107 findParentNodeAndSelect(selectParentFancyBox, split); 108 } 109 110}