我在protractor框架上工作,我需要使用脚本将文件上传到应用程序中,我知道如何在java中做,但不知道如何在javascript中做。谁能帮帮我。
Java代码。
public static void fileUpload(String script, String filePath) {
try {
Process proc = Runtime.getRuntime().exec("script " + script + " " + filePath);
BufferedReader read = new BufferedReader(new InputStreamReader(proc.getInputStream()));
try {
proc.waitFor();
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
}catch (IOException e) {
System.out.println(e.getMessage());
}
}
谢谢!
不知道你这里说的脚本是什么意思。在protractor中,使用sendkeys与上传输入元素应该可以工作。
像..: var path = require('path');
var fileToUpload = '../test-resources/filetoupload'; //(the example relative path of the file )
var absolutePath = path.resolve(__dirname, fileToUpload);
element(by.css('input[type="file"]')).sendKeys(absolutePath);
uploadButton().click();