Get protractor sessionId into a file

1.8k views Asked by At

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.

1

There are 1 answers

1
Chris Matheson On

I think what you are looking for are build: 'some build number' and name: 'my awesome webpage' properties in the capabilities section of your config file. these parameters will be pass through to your SL account and show up in the test run table

more info available https://docs.saucelabs.com/reference/test-configuration/#job-annotation