mlison/protractor-jasmine2-screenshot-reporter

Force take screenshot at the end of the it() block

Closed this issue · 3 comments

Currently, it seems like screenshot for a failed spec is taken after the afterEach() or afterAll() methods are executed. This means that if you have some clean-up in the afterEach() which opens a new page, the screenshot of this page, instead of the failed one will be taken.

Is there a way to force taking the screenshot at the end of each it() block?

I also have this problem. Could you please take screenshots immediately after expectation failure?
Thanks

Unfortunately I think this is not possible at the moment. Jasmine only lets us subscribe to the "specDone" event - and this will only occur once the whole "lifecycle" of the spec is carried out - including beforeEach / afterEach hooks.

The only way how to do something like this, although very cumbersome, is to wrap such test in it's own suite, and run the cleanup from afterEach of said suite. Something in this sense:

describe('some suite', function() {

  afterEach(function() {
    // Execute clean up on this level, after each _suite_, not after each _spec_
    // As long as each suite contains only one spec, it is effectively the same
    // but it allows the reporter to take the screenshot _before_ executing cleanup tasks
  })

  describe('spec wrapper', function() {
    it('spec', function() {
      expect(true).toBe(false);
      // The screenshot will be executed after spec is carried out, and since the
      // cleanup task is attached to the suite rather than to this spec, jasmine will
      // consider this spec as done and trigger the reporter which takes the screenshot
    });
  })

});

As I say, not pretty, but nothing better comes to mind considering current state of things.