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 <stan@nuxeo.com> 018 * Antoine Taillefer 019 */ 020package org.nuxeo.functionaltests.pages.forms; 021 022import java.io.IOException; 023 024import org.nuxeo.functionaltests.forms.FileWidgetElement; 025import org.nuxeo.functionaltests.forms.LayoutElement; 026import org.nuxeo.functionaltests.pages.FileDocumentBasePage; 027import org.openqa.selenium.WebDriver; 028 029/** 030 * @author Sun Seng David TAN <stan@nuxeo.com> 031 */ 032public class FileCreationFormPage extends DublinCoreCreationDocumentFormPage { 033 034 public FileCreationFormPage(WebDriver driver) { 035 super(driver); 036 } 037 038 public FileDocumentBasePage createFileDocument(String title, String description, boolean uploadBlob, 039 String filePrefix, String fileSuffix, String fileContent) throws IOException { 040 titleTextInput.sendKeys(title); 041 descriptionTextInput.sendKeys(description); 042 043 if (uploadBlob) { 044 uploadBlob(filePrefix, fileSuffix, fileContent); 045 } 046 047 create(); 048 return asPage(FileDocumentBasePage.class); 049 } 050 051 protected FileWidgetElement getFileWidgetElement() { 052 LayoutElement layout = new LayoutElement(driver, "document_create:nxl_file"); 053 // on file document, a widget template is used => standard file 054 // widget is wrapped, hence the duplicate nxw_file id 055 return layout.getWidget("nxw_file:nxw_file_file", FileWidgetElement.class); 056 } 057 058 protected void uploadBlob(String filePrefix, String fileSuffix, String fileContent) throws IOException { 059 FileWidgetElement fileWidget = getFileWidgetElement(); 060 fileWidget.uploadTestFile(filePrefix, fileSuffix, fileContent); 061 } 062 063 /** 064 * @since 7.1 065 */ 066 public FileCreationFormPage createFileDocumentWithoutTitle(String filePrefix, String fileSuffix, String fileContent) 067 throws IOException { 068 uploadBlob(filePrefix, fileSuffix, fileContent); 069 create(); 070 return asPage(FileCreationFormPage.class); 071 } 072 073 /** 074 * @since 7.1 075 */ 076 public String getSelectedOption() { 077 FileWidgetElement fileWidget = getFileWidgetElement(); 078 return fileWidget.getEditChoice(); 079 } 080 081 /** 082 * @since 7.1 083 */ 084 public String getSelectedFilename() { 085 FileWidgetElement fileWidget = getFileWidgetElement(); 086 return fileWidget.getFilename(true); 087 } 088 089}