[英]Uploading multiple images using Protractor
I have a scenario in my test suite, where I need to 我的测试套件中有一个场景,我需要
How can I achieve this - uploading an array of images, or a group of images, in specified folder, one by one. 如何实现-在指定的文件夹中一张一张地上传一组图像或一组图像。 The test also includes the check that an image should not have been uploaded before.
该测试还包括检查,确认之前不应该上传图像。 I am able to upload a single file using the code below -
我可以使用以下代码上传单个文件-
var fileUpload = 'path_to_file';
absolutePath = path.resolve(__dirname,fileUpload);
console.log(absolutePath);
this.file_Upload2.sendKeys(absolutePath);
browser.actions().sendKeys(protractor.Key.ENTER).perform();
browser.sleep(20000);
Please note that there is only a single button for uploading the images and it remains constant. 请注意,只有一个按钮可以上传图像,并且保持不变。
If you change your fileUpload variable to point to the directory where the files are held, rather than the file itself, you can just loop over everything in the directory. 如果您将fileUpload变量更改为指向文件所在的目录,而不是文件本身,则可以遍历目录中的所有内容。 Something like this:
像这样:
var fileUpload = 'path_to_directory';
var file_Upload2 = this.file_Upload2;
var absolutePath = path.resolve(__dirname, fileUpload);
fs.readdir(absolutePath, (err, files) => {
for (i = 0; i < files.length; i++) {
var fullPath = path.resolve(absolutePath, files[i]);
file_Upload2.clear().sendKeys(fullPath);
browser.actions().sendKeys(protractor.Key.ENTER).perform();
browser.sleep(20000);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.