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