Get session ID
BrowserStack automatically generates a unique session ID for every test run. A session ID is used to perform actions on a session, such as updating the status of a session, getting Appium logs of a session, etc.
Check out the session’s REST API requests section to learn about API requests that require the session ID.
Use the following sample code snippets to retrieve session ID programmatically in your tests:
// start a remote browser with the desired capabilities
RemoteWebDriver driver = new RemoteWebDriver(new URL(URL), caps);
// ... run some tests
// get the session ID
driver.getSessionId();
// performing actions using the session ID
// ... continue with your tests
// initialize the driver
driver = wd.promiseRemote("https://hub-cloud.browserstack.com/wd/hub");
// perform test actions
driver
.then(function () {
// print the session ID in the IDE's console
console.log(driver.sessionID);
})
// other test functions
// initialize the driver
RemoteWebDriver driver = new RemoteWebDriver(new Uri("https://hub-cloud.browserstack.com/wd/hub/"), capability);
// run some tests
// store the session ID in a variable
string sessionId = driver.SessionId.ToString();
// print session ID in the IDE's console
Console.WriteLine(sessionID);
// performe actions using the session ID
// continue your tests
// initialize the driver
$driver = RemoteWebDriver::create("https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub", $caps);
// store the session ID in a variable
$sessionID = $driver->getSessionID();
// print the session ID in the IDE's console
print($sessionID);
// perform actions using the session ID
# initialize the driver
driver = webdriver.Remote("https://" + userName + ":" + accessKey + "@hub-cloud.browserstack.com/wd/hub", desired_caps)
# print the session ID in the IDE's console
print(driver.session_id)
# perform actions using the session ID
# initialize the driver
appium_driver = Appium::Driver.new({
'caps' => desired_caps,
'appium_lib' => {
:server_url => "https://#{username}:#{access_key}@hub-cloud.browserstack.com/wd/hub"
}}, true)
driver = appium_driver.start_driver
#print the session ID in the IDE's console
puts driver.session_id
# perform actions using the session ID
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!