Search code examples
javascripttypescriptprotractordom-eventsdata-driven-tests

Protractor failure and browser handling on data driven approach


We are developing data driven protractor framework (jasmine), I need help in handling certain failure scenario.

I will be iterating same test with different data set, my Page module will handle the all verification.

If any it blocks fails, I want to run the certain function to clear cookies, capture session details and re-start the browser (I do have all the functions )

but ,

I am not sure how to get the it block failure and trigger the specific function, also I want to make sure next loop iteration is triggered.

browser.restart() - never worked in data driven in before or after all .....

If am running this data driven in parallel (we can run same test in parallel browser, but we can't distribute each data in to multiple browser), is there any way to distribute?

var dData = requireFile('testData/data.json');

using(dData,async function(data, description) {
   describe( scenario 1++  , function() { 

         it('Load URL' , async function() { })

         it('validate Page1' , async function() { xxxxx })
         it('validate Page2' , async function() { xxxxx })
         it('validate Page3' , async function() { xxxxx })

   }) }

Solution

  • If I understood everything right, you have like 3 questions. I'll answer only the first, general one - how to handle results of each it block

    It sounds like for what you are trying to implement you should use advantage of custom reporter in jasmine

    More precisely, what you want to do is to:

    • create a module with custom reporter
    • register it in your config. This would be a good place to think ahead of time if there are any parameters that you want to pass to the reporter
    • there are different hooks: jasmine-started, suite-started (describe), spec-started (it), suite-done, jasmine-done. Not sure if you all of them, but one particular for sure: spec-done. This should be a function that will be called after each it block. It will be taking spec object as a parameter. You can explore it on your own, but what you'll need from it is status property (spec.status). It's value can be 'passed', 'failed' and I believe others. So your logic will be like
    if (spec.status === 'passed') {
      // ...
    } else if (spec.status === 'failed') {
      // ...
    } else {
      // ...
    }