Browserstack reports successful even when test fails in Nightwatchjs

  1. A session on BrowserStack has only three types of statuses: Completed, Error or Timeout. Selenium (and hence, BrowserStack) does not have a way of understanding, if a test has passed or failed. Its by the multiple assertions in your tests that appear on your console, that you infer if a test has passed / failed. These assertions however, do not reach BrowserStack. As you rightly identified, you can use the REST-API, to change the status of the session to 'Error', if you see a failure in your console.

  2. I would suggest fetching the session ID of the test as the test is being executed, since fetching the session ID after the test execution is a lengthy process. In Nightwatch, you can fetch session ID as follows:

browser.session(function(session) {
    console.log(session.sessionId);
});
  1. Yes, you can certainly change the status of the session once it is completed. That's where the REST-API comes to help!