Question

Is it possible to leave the test browser windows open after Angular Protractor tests run? I have a tough test failing in FireFox and it'd be useful to access the state of the web page to see what's going on.

Was it helpful?

Solution

You can use Protractor debug/pause feature to pause the e2e run which will ultimately leave the browser open: more info here

To do so, add this line on your protractor test before the failing one

browser.pause();

There is also a very useful tool called elementor that you may want to take a look later on.

OTHER TIPS

browser.pause no longer works with current Node v8.1.0, see here, but you could use browser.sleep(10000); to keep the browser open for e.g. 10 seconds

If you configured the test script to run using grunt, you could use the following code:

grunt.initConfig({
    // ...
    protractor: {
      options: {
        configFile: "protractor.conf.js",
        keepAlive: true, // If false, the grunt process stops when the test fails.
        noColor: false // If true, protractor will not use colors in its output.
      },
      run: {}
    },
    // ...
  });

If you have Node 8+, bumped into issue "Error: Cannot find module '_debugger'" while attempting browser.pause solution from the accepted answer and you couldn't fix it using this github solution then you can workaround it as follows:

  1. Install protractor as a module of the automation framework (i.e. without -g flag)

    npm install protractor
    
  2. Run webdriver-manager update for this protractor instance as well:

    node ./node_modules/protractor/bin/webdriver-manager update
    
  3. Where you have browser.pause(); in your code, replace it with debugger; statement

  4. Run your code as follows:

     node inspect ./node_modules/protractor/bin/protractor protractorConf.js
    

    Where protractorConf.js is the config file of your protractor instance

  5. If debugger waits for an input from you at the command line, just type cont and hit enter (to continue the execution)

super simple solution, that does exactly what's needed

The idea is that you don't really want to keep alive the session but rather pause it for a very long time when tests are done and be able to resume on-close procedures at any time

So just add this to your config.js

    async onComplete() {
        await browser.waitForAngularEnabled(false);
        await browser.wait(
            async () => {
                let url = await browser.getCurrentUrl();
                return url.includes('close/');
            },
            5 * 60 * 1000,
            'Keep-alive timeout reached, closing the session...',
        );
    },

What the code does is, after all tests passed or failed, it waits until you type and submit close/ in browser's url field, or times out itself in 5 mins.

enter image description here

The reason await browser.waitForAngularEnabled(false); is needed here, because the browser opens an empty page when you type close/ which is non angular

You can even improve it and make it conditional, based on a parameter you pass to protractor config

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top