jasmine reporter conflict with afterEach

137 views
Skip to first unread message

jonbjohns

unread,
Oct 4, 2019, 4:00:35 PM10/4/19
to Jasmine
Hello,

I followed steps from this guide to create a jasmine reporter to trigger protractor to take a screenshot. (Essentially following this: http://www.webdriverjs.com/take-screenshot-every-failed-spec-protractorjasmine/ ). However, from testing this, I've found that Jasmine always triggers after our afterEach method completes. Fortunately for now, I can switch afterEach to beforeEach with no impact, but in the future if I need both, this would quickly break. 

At least for the near future, I won't need another work around, but for future reference, if i need both a before and after each method with this reporter, is there a way to make it work?

Gregg Van Hove

unread,
Oct 10, 2019, 7:58:15 PM10/10/19
to jasmi...@googlegroups.com
You've mentioned a couple of different things here and I just want to make sure I'm understanding your problem correctly. You mention using a custom reporter to take a screenshot after failed tests, but the `beforeEach` and  `afterEach` functions you mention aren't part of the reporter interface (https://jasmine.github.io/api/edge/Reporter.html). The reporter interface has methods call `specStarted` and `specDone` that are fired just before and just after a given spec runs respectively. All of these callbacks will be called for every spec they are configured for, but `specDone` on a custom reporter will include information about the success or failure of the spec in question. You will probably need to inspect the `SpecResult` (https://jasmine.github.io/api/edge/global.html#SpecResult) that is passed in to figure out whether the spec that just finished was successful or not. You can also check out our doc on how to build a custom reporter (https://jasmine.github.io/tutorials/custom_reporter) for a bit more detail around how this all comes together.

Hope this helps. Thanks for using Jasmine!

- Gregg

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jasmine-js/9d9c8ac7-91b9-4f7b-a87f-8173ba5803d3%40googlegroups.com.

Sean Fitzgerald

unread,
Oct 11, 2019, 11:55:03 AM10/11/19
to Jasmine
It is important here to understand the execution order of the hooks in both Jasmine and Protractor. When you say 'Jasmine starts after our afterEach method completes' you are probably referring to either specDone, or suiteDone as Gregg has already suggested.
Therefore if your afterEach is altering the state of the browser then your screenshots within your suiteDone and specDone will capture that altered state.

--- beforeLaunch           
    --- onPrepare          
      --- jasmineStarted   (set in jasmine reporter)
        --- beforeAll
         --- suiteStarted  (set in jasmine reporter)
          --- specStarted  (set in jasmine reporter)
           --- beforeEach  
           +++ afterEach   
          +++ specDone     (set in jasmine reporter)
         +++ suiteDone     (set in jasmine reporter)
        +++ afterAll
      +++ jasmineDone      (set in jasmine reporter)
    +++ onComplete         
+++ afterLaunch
Reply all
Reply to author
Forward
0 new messages