2

Why the Protractor do steps not one by one?

The code example:

browser.get('http://mywebpage.com');
element(by.css('[ng-click="fileCtrl.saveFile()"]')).click();
var today = new Date();
var todayPlus = new Date();
while(todayPlus.valueOf()<today.valueOf()+7000){
     todayPlus = new Date();
}
browser.driver.sleep(2000);
var fs = require('fs');
var util = require('util');
var c = fs.exists('C:\\Users\\volodymyr.nabok\\Downloads\\file.txt', function(ex){ util.debug(ex ? "Yes." : "No-p"); });

In my case the Protractor firstly check if the 'file.txt' exists then download it. As you see I tried to freeze script for 7 seconds and freeze the browser for 2 seconds but it didn't help.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Volodymyr Nabok
  • 415
  • 1
  • 4
  • 11

1 Answers1

1

The problem is that it takes time for a file to be downloaded. You can approach it with hardcoded wait intervals, but a more reliable approach would be to wait until the file is downloaded using browser.wait(), see this solution.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Seems it help. Thank you. Interesting that yesterday the same solution did not work (Protractor said something like: "Error: Wait timed out after 3000 ms"). Anyway, now it is working. Thanks once more. – Volodymyr Nabok Jun 18 '15 at 08:24