【发布时间】:2017-08-29 13:00:22
【问题描述】:
我正在尝试使用 NightwatchJS 上传图像,但将值设置为输入不起作用。我在上传部分使用 DropzoneJS。
我已经尝试过以下解决方案: 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 在测试失败时进行截图,截图显示我没有上传任何东西,这就是最后一个断言失败的原因。
【问题讨论】:
标签: javascript file-upload dropzone.js nightwatch.js