Tag: file upload

上传文件时出现NullPointerException

上传文件时,出现以下错误: Struts Problem Report Struts has detected an unhandled exception: Messages: File: java/io/File.java Line number: 317 Stacktraces java.lang.NullPointerException java.io.File.(File.java:317) example.uploadFile.execute(uploadFile.java:36) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav‌​a:43) java.lang.reflect.Method.invoke(Method.java:483) 的index.jsp Upload your file uploadFile.java package example; import java.io.File; import org.apache.commons.io.FileUtils; import java.io.IOException; import com.opensymphony.xwork2.ActionSupport; public class uploadFile extends ActionSupport { private File myFile; private String myFileContentType; private String myFileFileName; […]

如何使用selenium或webdriver处理测试自动化中的文件上载

我认为每个人如何使用Webdriver进行测试自动化必须意识到它对Web开发的巨大优势。 但是,如果文件上传是您的Webflow的一部分,则存在一个巨大的问题。 它不再是测试自动化。 浏览器的安全限制(调用文件选择)实际上使得无法自动化测试。 Afaik唯一的选择是让webdriver单击文件上传按钮,睡眠线程,让开发人员/测试人员手动选择文件,然后完成其余的Web流程。 如何解决这个问题,是否有解决方法呢? 因为它真的不能这样做。 这没有意义。 这是我所知道的浏览器安全限制不适用的唯一情况: function window.onload(){ document.all.attachment.focus(); var WshShell=new ActiveXObject(“WScript.Shell”) WshShell.sendKeys(“D:\MyFile.doc”) }

如何在使用chrome driver / firefox驱动程序时更改Webdriver中的文件下载位置

我试图通过在特定文件夹中使用另存为选项来保存图像。 我找到了一种方法,通过该选项,我可以右键单击要保存的图像。 但我遇到的问题是在获取os窗口后询问保存文件的位置,我无法发送所需的位置,因为我不知道该怎么做。 我经历了在这个论坛上提出的类似问题,但到目前为止他们没有帮助过。 代码是 – 对于Firefox- public class practice { public void pic() throws AWTException{ WebDriver driver; //Proxy Setting FirefoxProfile profile = new FirefoxProfile(); profile.setAssumeUntrustedCertificateIssuer(false); profile.setEnableNativeEvents(false); profile.setPreference(“network.proxy.type”, 1); profile.setPreference(“network.proxy.http”, “localHost”); profile.setPreference(“newtwork.proxy.http_port”,3128); //Download setting profile.setPreference(“browser.download.folderlist”, 2); profile.setPreference(“browser.helperapps.neverAsk.saveToDisk”,”jpeg”); profile.setPreference(“browser.download.dir”, “C:\\Users\\Admin\\Desktop\\ScreenShot\\pic.jpeg”); driver = new FirefoxDriver(profile); driver.navigate().to(“http://stackoverflow.com/users/2675355/shantanu”); driver.findElement(By.xpath(“//*[@id=’large-user-info’]/div[1]/div[1]/a/div/img”)); Actions action = new Actions(driver); action.moveToElement(driver.findElement(By.xpath(“//*[@id=’large-user-info’]/div[1]/div[1]/a/div/img”))).perform(); action.contextClick().perform(); Robot robo = […]

Spring MVC – AngularJS – 文件上传 – org.apache.commons.fileupload.FileUploadException

我有一个Java Spring MVC Web应用程序作为服务器。 而基于AngularJS的应用程序作为客户端。 在AngularJS中,我必须上传文件并发送到服务器。 这是我的HTML Submit 这是我的UploadController.js ‘use strict’; var mainApp=angular.module(‘mainApp’, [‘ngCookies’]); mainApp.controller(‘FileUploadController’, function($scope, $http) { $scope.document = {}; $scope.setTitle = function(fileInput) { var file=fileInput.value; var filename = file.replace(/^.*[\\\/]/, ”); var title = filename.substr(0, filename.lastIndexOf(‘.’)); $(“#title”).val(title); $(“#title”).focus(); $scope.document.title=title; }; $scope.uploadFile=function(){ var formData=new FormData(); formData.append(“file”,file.files[0]); $http({ method: ‘POST’, url: ‘/serverApp/rest/newDocument’, headers: { ‘Content-Type’: ‘multipart/form-data’}, […]

如何处理MaxUploadSizeExceededException

当我上传大小超过允许的最大值的文件时,会出现MaxUploadSizeExceededExceptionexception。 我想在出现此exception时显示错误消息(如validation错误消息)。 如何在Spring 3中处理此exception以执行此类操作? 谢谢。