Sid
Sid

Reputation: 645

Protractor capture screenshot on failure

I have written below code in afterEach method to capture screenshot on failure

afterEach(function() {
  var passed = jasmine.getEnv().currentSpec.results().passed();
  if (!passed) {
    browser.takeScreenshot().then(function(png) {
      //capturing screenshot here

    };
  }
});

But while executing getting below error..

 Message:
   Failed: Cannot read property 'results' of undefined
 Stack:
   TypeError: Cannot read property 'results' of undefined

how to remove above error...

Upvotes: 0

Views: 1939

Answers (1)

alecxe
alecxe

Reputation: 473873

currentSpec is not going to work with jasmine2.

Please see if protractor-jasmine2-screenshot-reporter fits your use case.

There is also jasmine-test-container-support library that extends jasmine2 and provides you with all of the meta information you would need about the currently executed test.

Upvotes: 1

Related Questions