Search code examples
javascriptprotractorchaie2e-testingbrowserstack

Browserstack protractor ignores expect


I am using Mocha and Chai. my e2e runs on browser stack and record nicely (video and all) BUT browser stack always marks the session as completed and no error when I know that some specs failed.

I have tried the example here: https://github.com/browserstack/protractor-browserstack and same result (test marked as completed even when there is an error).

I have tried using 'updateJob' from 'driverProviders/browserStack'...

this is my test:

describe('bbbb', () => {
  it('aaa', () => {
    expect(true).to.equal(false);
  });
});

Solution

  • as @BountyHunter suggested, I have used the api to mark tests. this is the jest of the code (might be some syntax errors)

    afterEach(function() {
      if (this.currentTest.state === 'failed') {
        //collect error data into array
        //this.currentTest.title, this.currentTest['err']
      }
    });
    
    after(function () {
      //after all is done if errors array is not empty, report to browserstack 
      protractor.browser.driver.getSession().then((session) => {
        var request = require("request");
        request({uri: "https://USERNAME:ACCESS_KEY@api.browserstack.com/automate/sessions/"+session['id_']+".json", method:"PUT", form:{"status":"failed","reason":errorsArrayStringified }})
      });
    
    })
    

    full repo here: https://github.com/zeevgl/protractor-browserstack