Protractor takes blank screenshots when “restartBr

2019-08-06 05:14发布

问题:

I'm trying to use protractor-jasmine2-html-reporter to take screenshots of my tests as they run, but it appears to be taking them directly after the browser is restarted due to the "restartBrowserBetweenTests" flag in conf.js being set to "true".

I need to use that flag to restart the browser because it seems to be the only way to clear the session sufficiently so that subsequent tests can use the sign in page, rather than the application assuming it's the same user and redirecting them to the home page. Clearing cookies is not enough.

Screenshot of the html report output with restartBrowserBetweenTests set to true

Screenshot of the html report output with restartBrowserBetweenTests set to false

This is my conf.js file:

    var HtmlScreenshotReporter = require('protractor-jasmine2-html-reporter');

    exports.config = {
        seleniumAddress: 'http://localhost:4444/wd/hub',
        specs: ['./tmp/specs/*.spec.js'],
        restartBrowserBetweenTests: true,

        onPrepare: function() {
          jasmine.getEnv().addReporter(
              new HtmlScreenshotReporter({
                  savePath: 'tmp/screenshots/'
              })
          );
        }

    };

Is there a way I can initiate the screenshot being taken before the browser is restarted? Alternatively, is there a way I can clear the browser's local storage without having to resort to restarting the browser between tests?

Thanks in advance.