Protractor: how to retrieve pass fail status of each test in protractor

Created on 19 Jun 2015  Â·  6Comments  Â·  Source: angular/protractor

I need to write pass fail status into a csv file . Is there any way to check the status of each test case post execuction of test cases so that appropriate action can be taken

Most helpful comment

All 6 comments

I think you can this,

jasmine.getEnv().addReporter(new function() {
    this.specDone = function(result) {
      if (result.failedExpectations.length > 0) {
       // Test FAILURE ACTION GOES HERE
     }
   };
  });

Hi Shanmuga,
I tried your code, and it is giving Pass|Fail status first time, but not sure in the end it is giving Pass again if it was a failed test. Is it if() block has the issue or the function getting called two times?
Here is my code -

    it("To verify, xxxx", function () {
        try{
            expect(1).toMatch(2);
            notes = "Success";
        }catch(err){
            //logger.info("catch : " + err);
            status = "Fail";
            notes = err.message;
            //logger.info(err.message);
        }finally{
            jasmine.getEnv().addReporter(new function() {
                this.specDone = function(result) {
                    //status = result.failedExpectations.length > 0 ? "Fail" : "Pass";
                    console.log('Name: ' + result.fullName);
                    if (result.failedExpectations.length > 0) {
                        console.log('I am Failed: it01');
                        status = "Fail";
                        notes = result.failedExpectations;
                    }else{
                        console.log('I am Passed: it01');
                        status = "Pass";
                        notes = "";
                    }
                };
            });
            adminPage.addTestCaseResult('"To verify, xxxx"', status, notes);
        }
    })

OUTPUT:

I am Failed: it01
.Name: To verify, xxxx.
I am Passed: it01

Can you try including the pass/fail check in the afterEach?
On Tue, 23 Jun 2015 at 11:45, BobyAbraham [email protected] wrote:

Hi Shanmuga,
I tried your code, and it is giving Pass|Fail status first time, but not
sure in the end it is giving Pass again if it was a failed test. Is it if()
block has the issue or the function getting called two times?
Here is my code -
it("To verify, xxxx", function () {
try{
expect(1).toMatch(2);
notes = "Success";
}catch(err){
//logger.info("catch : " + err);
status = "Fail";
notes = err.message;
//logger.info(err.message);
}finally{
jasmine.getEnv().addReporter(new function() {
this.specDone = function(result) {
//status = result.failedExpectations.length > 0 ? "Fail" : "Pass";
console.log('Name: ' + result.fullName);
if (result.failedExpectations.length > 0) {
console.log('I am Failed: it01');
status = "Fail";
notes = result.failedExpectations;
}else{
console.log('I am Passed: it01');
status = "Pass";
notes = "";
}
};
});
adminPage.addTestCaseResult('"To verify, xxxx"', status, notes);
}
})
OUTPUT:
I am Failed: it01
.Name: To verify, xxxx.
I am Passed: it01

—
Reply to this email directly or view it on GitHub
https://github.com/angular/protractor/issues/2270#issuecomment-114374748
.

Sounds like everyone's problems have been sorted

Hi, @ BobyAbraham ,

How to include the custom reporter

Was this page helpful?
0 / 5 - 0 ratings