Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor Pause On Failure

I am new to protractor and I am trying to figure out how to make the test/runner pause on failure. Ideally I would love to transition to the nodejs debugger but am open to any suggestion.

My use case is basically, when a test fails I would like to see what state the UI is in to help understand why the test failed.

Nick.

like image 644
Nix Avatar asked Mar 10 '14 19:03

Nix


2 Answers

You can also add to the jasmine config, to stop when spec fails: (same as how protractor-screenshot-reporter works)

for jasmine 1:

onPrepare: function () {
    exports.config = {
        onPrepare: function () {
            jasmine.getEnv().addReporter({
                reportSpecResults: function (spec) {
                    if (!spec.results().passed()) {
                        spec.results().items_.forEach(function (v) {
                            console.log(v.trace.stack);
                        });
                        browser.pause();
                    }
                }
            });
        }
    }
}

for jasmine2:

onPrepare: function () {
    jasmine.getEnv().addReporter({
        specDone: function (spec) {
            if (spec.status === 'failed') {
                console.dir(spec.failedExpectations.length);
                console.log(spec.failedExpectations[0].message);
                console.log(spec.failedExpectations[0].stack);
                browser.pause();
            }
        }
    });
}

then by typing "repl" in the console you switch to interactive mode, so you can try out the protractor commands.

like image 127
holdfenytolvaj Avatar answered Nov 12 '22 23:11

holdfenytolvaj


You can put browser to sleep after or before your expect line to see what's going on.

browser.sleep(20000); // sleep 20 seconds

Update:

protractor now supports .pause() method.

browser.pause()

Read the docs here: https://angular.github.io/protractor/#/api?view=Protractor.prototype.pause

like image 3
Mohsen Avatar answered Nov 13 '22 00:11

Mohsen