I need to get the job ID / session ID from a protractor run into a file so I can create links to screenshots / videos at Saucelabs . Is there a correct way to do this?
One approach I'm looking at is to get the session ID from the browser
object then pass to a custom reporter that writes it to a file:
// protractor.conf.js
onPrepare: function () {
var sessionIdP = q.defer();
browser.getSession().then(function(session) {
sessionIdP.resolve(session.getId());
});
jasmine.getEnv().addReporter(new SessionIdWriter({
sessionId: sessionIdP
});
}
Should work but can this be done more cleanly?
I'm aware that Saucelabs offers a REST api that can return the latest job ID, but this presents a race condition with other users of the account. Besides the ID is known locally so a call shouldn't be needed.