0

I am trying to write an automated test script which simply takes screenshots of a web page every x seconds until killed. This is kind of a "catch all" for test scenarios that are not common enough to want to automate fully. Someone can manually go back into the screenshots and see how long the web UI took to accomplish some task (these will be minutes or hours in length typically).

This is my code:

it('should monitor a page taking a screenshot every once in a while', function() {
    browser.get("www.google.com");

    while (true) {
        //filename logic is here
        var date = new Date().toISOString();
        var fileName = location + date + ".png";
        console.log('filename is:  ' + fileName);

        //screenshot saving logic is here

        browser.takeScreenshot()
            .then(function(png) {
                console.log('taking screenshot');
                console.log(png);
                writeScreenShot(png, fileName);
            })
            .catch(function(error) {
                console.error(error);
            });

        //delay logic is here
    }
});

Everything inside the "browser.takeScreenshot()" promise resolution never gets called, and I'm not sure why. I followed the tutorial here:

http://blog.ng-book.com/taking-screenshots-with-protractor/

Isaak
  • 41
  • 2
  • 2
  • I'm curious what the `delay logic` is. the only way you can prevent short circuit while loop is to do blocking code, that will block all code and prevent any of your code being called: `Promise.resolve(22).then(x=>console.log(x));alert("block, no console.log until you click ok")` you run that in the console and notice you won't get the log until you click "ok" in the alert because alert is blocking. – HMR Dec 05 '17 at 05:22
  • And if you have async code in your spec don't you need to pass and call `done` when you're done? – HMR Dec 05 '17 at 05:25
  • The delay logic is basically a while loop that blocks until time = start time + delay param. – Isaak Dec 06 '17 at 16:06
  • Ok, just answered another question about asynchronous JavaScript. You cannot `pause` your functions. The while loop basically just blocks all other script from running (probably including the screen shot). https://stackoverflow.com/a/47678417/1641941 The way to do it is by using `done`: https://jasmine.github.io/2.0/introduction.html#section-Asynchronous_Support – HMR Dec 06 '17 at 16:11

0 Answers0