question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to get browser session ID?

See original GitHub issue

What are you trying to achieve?

I am trying to migrate a python WebDriver test to a Codeceptjs test. When the test finishes, it posts a link to the suacelabs session like this:

def tearDown(self):
    if is_travis():
        print("Link to your job: https://saucelabs.com/jobs/%s" % self.driver.session_id)
        try:
            if sys.exc_info() == (None, None, None):
                sauce.jobs.update_job(self.driver.session_id, passed=True)
            else:
                sauce.jobs.update_job(self.driver.session_id, passed=False)
        finally:
            self.driver.quit()
    else:
self.driver.close()

Is there an equivalent to self.driver.session_id I can use to get the sessionID in codeceptjs?

Details

  • CodeceptJS version: v0.4.13
  • NodeJS Version: 6.9.2
  • WebDriverIO

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
DavertMikcommented, Jan 13, 2017

Oh, looks like it returns a promise, not an array as I expected.

_after() {
  return this.helpers['WebDriverIO'].browser.sessions().then((sessions) => {
    // do everything you need
  });
}

2reactions
DavertMikcommented, Jan 11, 2017

I think you need a custom helper

Run:

codeceptjs gh

to create SauceLabs helper

Then your helper should look like:

class SauceLab extends Helper {

  // after corresponds to teardown in your code
  _after() {
     var sessions = this.helpers['WebDriverIO'].browser.sessions(); 
     var session_id = sessions[0].id;
     // do your stuff
  }
}

Please see webdriverio session reference for session id, as I can be wrong in this part.

It is important to make your helper to be declared before WebDriverIO in codecept.json so this.browser to be available inside _after.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get Session ID in browser - New Relic Explorers Hub
You should be able to copy that ID and use it via NRQL queries as the “session” attribute in a WHERE clause.
Read more >
Read Session Id using Javascript - Stack Overflow
Yes. As the session ID is either transported over the URL ( document.location.href ) or via a cookie ( document.cookie ), you could...
Read more >
[Question] How to get browser session ID? · Issue #362 - GitHub
What are you trying to achieve? I am trying to migrate a python WebDriver test to a Codeceptjs test. When the test finishes,...
Read more >
Question about "Unique Session ID" per Browser instance.
The SessionID property is used to uniquely identify a browser with session data on the server. The SessionID value is randomly generated by...
Read more >
Get session id from users? - Discussions on Python.org
I'm developing a distributed software (in python) that I intend to run on the web (browser) and I came across a question about...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found