0

I've faced with issue using Webdriver.io+Browserstack. When I'm running tests in browser (Automate service) it's ok, I see a correct statuses http://prntscr.com/ijw1rr , but when I'm running for mobile apps tests (App Automate) it shows me always Completed http://prntscr.com/ijw277

Where in wdio.conf.js I should paste this request from REST API documentation REST API? Also I've found here something similar, but don't know how can I use it. Browserstack reports successful even when test fails in Nightwatchjs

Here is an example when it works for me

afterTest: function (test) {
     var session = browser.sessionId;
     var request = require("request");
     request({uri: "https:/<user>:<key>@api.browserstack.com/app-automate/sessions/"+session+".json", method:"PUT", form:{"status":"completed","reason":""}});
 }

But it is like hard coded (every time will completed or failed, depends on what I specified), I need somehow populate this value depends on if assert or test fails.

1 Answers1

1

You could use the following code block to mark tests as failed on browserstack

afterTest: test => {
   if (!test.passed) {
        request({
        uri: `https://${user}:${key}@api.browserstack.com/app-automate/sessions/${browser.sessionId}.json`,
        method:'PUT',
        form:{ 'status':'error','reason': errors.join(' | ') },
    })
}

This api call will be invoked only upon test failures. So all test that are completed will be green and the ones that failed will be marked red/error/failed.

BountyHunter
  • 1,325
  • 15
  • 30
  • Thank you for help, it complains that ‘errors’ is not defined http://prntscr.com/iofi9v . But when I’ve changed reason it start working good for me. – Konstantin Zalutskyi Mar 08 '18 at 09:49
  • 'errors' is when working with multiple API calls in the generic after block. Please mark the answer as accepted if this helped. – BountyHunter Mar 08 '18 at 09:52
  • The updated api url should be: "api-cloud.browserstack.com/app-automate/sessions/{yourSessionID}.json" – gorbysbm Apr 20 '20 at 00:07