无法在量角器中删除带有nodejs的文件

时间:2021-08-21 01:21:33

I'm trying to delete the file with nodejs fs and I notice that file has been generated then trying to delete (failed to delete the file) while the file is not even uploaded on browser with protractor. Generate and delete file functions are created using nodejs fs.

我正在尝试使用nodejs fs删除该文件,我注意到该文件已生成然后尝试删除(无法删除文件),而文件甚至没有上传到带有量角器的浏览器上。使用nodejs fs创建和删除文件功能。

So how can I put them in a way then wait until file is uploaded then delete the file?

那么我该如何将它们置于某种方式然后等到文件上传然后删除文件呢?

helper.generateFile(filePath);
helper.uploadFile(UploadButtonElement, filePath);
uploadButtonElm.click();
helper.deleteFile(filePath); 

Is there a way to execute deleteFile only when below two actions are completed.

有没有办法只在完成以下两个操作时执行deleteFile。

helper.uploadFile(UploadButtonElement, filePath);
uploadButtonElm.click();

Thanks.

1 个解决方案

#1


2  

Protractor operations schedule promises to do things. They do not actually do them. Thus, your helper functions will end up running well before any of the protractor code actually accomplishes what you asked. Use then to chain your dependencies explicitly. Like so:

量角器操作计划承诺做事。他们实际上并没有这样做。因此,在任何量角器代码实际完成您的要求之前,您的帮助函数将最终运行良好。然后使用显式链接您的依赖项。像这样:

helper.generateFile(filePath);
helper.uploadFile(UploadButtonElement, filePath);
uploadButtonElm.click().then(function() {
   helper.deleteFile(filePath);
});

Please read https://github.com/angular/protractor/blob/master/docs/control-flow.md and https://code.google.com/p/selenium/wiki/WebDriverJs#Understanding_the_API

请阅读https://github.com/angular/protractor/blob/master/docs/control-flow.md和https://code.google.com/p/selenium/wiki/WebDriverJs#Understanding_the_API

#1


2  

Protractor operations schedule promises to do things. They do not actually do them. Thus, your helper functions will end up running well before any of the protractor code actually accomplishes what you asked. Use then to chain your dependencies explicitly. Like so:

量角器操作计划承诺做事。他们实际上并没有这样做。因此,在任何量角器代码实际完成您的要求之前,您的帮助函数将最终运行良好。然后使用显式链接您的依赖项。像这样:

helper.generateFile(filePath);
helper.uploadFile(UploadButtonElement, filePath);
uploadButtonElm.click().then(function() {
   helper.deleteFile(filePath);
});

Please read https://github.com/angular/protractor/blob/master/docs/control-flow.md and https://code.google.com/p/selenium/wiki/WebDriverJs#Understanding_the_API

请阅读https://github.com/angular/protractor/blob/master/docs/control-flow.md和https://code.google.com/p/selenium/wiki/WebDriverJs#Understanding_the_API