Search code examples
seleniumselenium-webdriverwebdriver-iocucumberjssaucelabs

WebdriverIO/Cucumber-js/SauceLabs: Set up a hook to send pass/fail of build


I have a couple of feature files with step definitions, also I've connected to SauceLabs and my builds are running, but I can't figure out how to properly send pass or fail of builds.

Curently I have the following hooks setup in wdio.conf.js

```

  afterTest: function afterTest(test) {
    browser.deleteCookie();
    browser.localStorage('DELETE');
    browser.end();
  },
  before() {
    global.expect = require('jest-matchers');
    global.browser.execute(`sauce:job-name=End-to-End tests at ` + `${jobName}`);
  },
  after() {
    global.browser.execute('sauce:job-result=passed');
  }

``` Also found out that there are also specific hooks for cucumber like afterScenario, afterFeature etc. but still with those I was not able to solve the issue.

To sum up: I need to send that the job passed when it passed and when one of the scenarios at least failed I need to send that the job failed.


Solution

  • There is a passed property on the test object passed into the afterTest function. You can just use it like this...

    //define this stuff at the top of your config
    var SauceLabs = require('saucelabs');
    
    var myAccount = new SauceLabs({
      username: "your-sauce-username",
      password: "your-sauce-api-key"
    });
    
    ....
    
    //then use it like this
    afterTest: function(test) {
        saucelabs.updateJob(browser.session().sessionId, {
          name: test.title,
          passed: test.passed
        }, done);
      });
    }