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 * Sun Seng David TAN <[email protected]> 018 * Antoine Taillefer 019 */ 020package org.nuxeo.functionaltests.pages.forms; 021 022import java.io.IOException; 023 024import org.apache.commons.lang3.StringUtils; 025import org.nuxeo.functionaltests.forms.FileWidgetElement; 026import org.nuxeo.functionaltests.forms.LayoutElement; 027import org.nuxeo.functionaltests.pages.FileDocumentBasePage; 028import org.openqa.selenium.WebDriver; 029 030/** 031 * @author Sun Seng David TAN <[email protected]> 032 */ 033public class FileCreationFormPage extends DublinCoreCreationDocumentFormPage { 034 035 public FileCreationFormPage(WebDriver driver) { 036 super(driver); 037 } 038 039 public FileDocumentBasePage createFileDocument(String title, String description, boolean uploadBlob, 040 String filePrefix, String fileSuffix, String fileContent) throws IOException { 041 titleTextInput.sendKeys(title); 042 descriptionTextInput.sendKeys(description); 043 044 if (uploadBlob) { 045 uploadBlob(filePrefix, fileSuffix, fileContent); 046 } 047 048 create(); 049 return asPage(FileDocumentBasePage.class); 050 } 051 052 /** 053 * Create a file document referencing an existing file path. 054 * 055 * @since 9.1 056 */ 057 public FileDocumentBasePage createFileDocument(String title, String description, String filePath) 058 throws IOException { 059 titleTextInput.sendKeys(title); 060 descriptionTextInput.sendKeys(description); 061 062 if (!StringUtils.isBlank(filePath)) { 063 FileWidgetElement fileWidget = getFileWidgetElement(); 064 fileWidget.uploadFile(filePath); 065 } 066 067 create(); 068 return asPage(FileDocumentBasePage.class); 069 } 070 071 protected FileWidgetElement getFileWidgetElement() { 072 LayoutElement layout = new LayoutElement(driver, "document_create:nxl_file"); 073 // on file document, a widget template is used => standard file 074 // widget is wrapped, hence the duplicate nxw_file id 075 return layout.getWidget("nxw_file:nxw_file_file", FileWidgetElement.class); 076 } 077 078 protected void uploadBlob(String filePrefix, String fileSuffix, String fileContent) throws IOException { 079 FileWidgetElement fileWidget = getFileWidgetElement(); 080 fileWidget.uploadTestFile(filePrefix, fileSuffix, fileContent); 081 } 082 083 /** 084 * @since 7.1 085 */ 086 public FileCreationFormPage createFileDocumentWithoutTitle(String filePrefix, String fileSuffix, String fileContent) 087 throws IOException { 088 uploadBlob(filePrefix, fileSuffix, fileContent); 089 create(); 090 return asPage(FileCreationFormPage.class); 091 } 092 093 /** 094 * @since 7.1 095 */ 096 public String getSelectedOption() { 097 FileWidgetElement fileWidget = getFileWidgetElement(); 098 return fileWidget.getEditChoice(); 099 } 100 101 /** 102 * @since 7.1 103 */ 104 public String getSelectedFilename() { 105 FileWidgetElement fileWidget = getFileWidgetElement(); 106 return fileWidget.getFilename(true); 107 } 108 109 /** 110 * Returns the element error message if any. 111 * 112 * @since 10.1 113 */ 114 public String getSelectedFileErrorMessage() { 115 LayoutElement layout = new LayoutElement(driver, "document_create:nxl_file"); 116 return layout.getSubElement("nxw_file:nxw_file_message").getText(); 117 } 118 119}