2017-08-29 54 views
1

我想上传与NightwatchJS图像,但设置值输入不起作用。我正在使用DropzoneJS作为上传部分。模拟一个文件上传(DropzoneJS)与NightwatchJS

我已经尝试从溶液: NIghtwatch.js File Upload with Dropzone.js

HTML

<input type="file" multiple="multiple" style="visibility: hidden; 
position: absolute; top: 0px; left: 0px; height: 0px; width: 0px;"> 

的JavaScript

module.exports = { 
    "Upload test": function(browser) { 
    browser 
     .url('localhost:8080') 
     .assert.elementPresent('form > div:nth-of-type(2) > div > div:nth-of-type(3) > div:nth-of-type(2) > div > input') 
     .execute('document.querySelectorAll("input[type=file]")[0].style.display = "block";')   
     .setValue('form > div:nth-of-type(2) > div > div:nth-of-type(3) > div:nth-of-type(2) > div > input', require('path').resolve(__dirname + '/img.jpg')) 
     .assert.valueContains('form > div:nth-of-type(2) > div > div:nth-of-type(3) > div:nth-of-type(2) > div > input', require('path').resolve(__dirname + '/img.jpg')) 
     .end(); 
    } 
} 

Nightwatch正在截图时,测试失败,然后将截图表明我没有上前广告任何东西,这就是为什么最后的断言失败。

回答

0

使用Google Chrome浏览器驱动程序正在上传文件!只需使用:

.setValue("input[type=file]",`/path/to/file`) 
0

将其更改为:

<input type="file" multiple="multiple" style="position: absolute; left: -9999px;"> 

输入将被认为是可见的,但它实际上不是在屏幕上可见。