Get Session Details of Playwright Tests
A guide to getting all the details related to a Playwright test session running on BrowserStack
Details of a Playwright test session on BrowserStack
When a Playwright test runs on BrowserStack, a lot of logs are generated including Video, Text Logs, Network Logs etc. and also each session that runs on BrowserStack has a unique identifier that can be used to invoke multiple different REST API calls to achieve different purposes.
We’ve created a simple executor that you can run from within your Playwright test script and get all the relevant details of that session as a JSON response that you can later use even after the script has completed its execution.
How to get the details of a Playwright session?
You can use the snippet provided below anywhere in any of your Playwright scripts and you would get the details as a JSON response as shown in the next section.
const resp = await JSON.parse(await page.evaluate(_ => {}, `browserstack_executor: ${JSON.stringify({action: 'getSessionDetails'})}`));
console.log(resp); // This prints the entire JSON response on the console. You can use the data in this variable even outside the test script if you save it appropriately
You can also see the sample script where the getSessionDetails
executor is shown in action.
Session details JSON
The JSON response that you would get on executing the above script is as shown below:
{ name: 'My first playwright test',
duration: null,
os: 'OS X',
os_version: 'Catalina',
browser_version: '89.0',
browser: 'playwright-firefox',
device: null,
status: 'running',
hashed_id: '562bf091e9fe5f9c33d2c7f9f06d651bc4be960c',
reason: null,
build_name: 'Sample Playwright build 1',
project_name: 'Untitled Project',
build_hashed_id: '4ea7d29797059caac02f82a4101eb39142d6f9a8',
test_priority: null,
logs: 'https://automate.browserstack.com/builds/4ea7d29797059caac02f82a4101eb39142d6f9a8/sessions/562bf091e9fe5f9c33d2c7f9f06d651bc4be960c/logs',
browserstack_status: 'running',
created_at: '2021-08-13T12:25:06.000Z',
browser_url: 'https://automate.browserstack.com/builds/4ea7d29797059caac02f82a4101eb39142d6f9a8/sessions/562bf091e9fe5f9c33d2c7f9f06d651bc4be960c',
public_url: 'https://automate.browserstack.com/builds/4ea7d29797059caac02f82a4101eb39142d6f9a8/sessions/562bf091e9fe5f9c33d2c7f9f06d651bc4be960c?auth_token=3b5267c44af1757b012841f0e0cc83ba034714fea1809ef5a563bc1b5676c9e8',
video_url: 'https://automate.browserstack.com/sessions/562bf091e9fe5f9c33d2c7f9f06d651bc4be960c/video?token=cndDMFBRMVZ4YTlGUHU3L3A2WW00YlR2R1M0NWg1Q1h1NzYxcWtMdllxYmRuRzRsemR1aDNKTmpLV0llaUpubnNuNFV5MVBWRUhWZzlnOE5YNkdid1E9PS0tSFdRd0pWYUhRRkN5VUV3YjFFLzBCZz09--8e34433eb229f1c54487ab559319d97dbcaa3c4e&source=rest_api&diff=-1',
browser_console_logs_url: 'https://automate.browserstack.com/s3-upload/bs-selenium-logs-use/s3/562bf091e9fe5f9c33d2c7f9f06d651bc4be960c/562bf091e9fe5f9c33d2c7f9f06d651bc4be960c-console-logs-v2.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2XUQHUQMLMBQZEP4%2F20210813%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210813T122514Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=6026406b5f7663557a0ec866a54c647ea9eeb61615b2917bd5b59687e044e2fb',
har_logs_url: 'https://automate.browserstack.com/s3-upload/bs-selenium-logs-use/s3/562bf091e9fe5f9c33d2c7f9f06d651bc4be960c/562bf091e9fe5f9c33d2c7f9f06d651bc4be960c-har-logs.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2XUQHUQMLMBQZEP4%2F20210813%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210813T122514Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=e17feb0c7341d55c275311a8c3762a75ca1a4b3d201177978809142d577c23d2',
playwright_logs_url: 'https://automate.browserstack.com/s3-upload/bs-selenium-logs-use/s3/562bf091e9fe5f9c33d2c7f9f06d651bc4be960c/562bf091e9fe5f9c33d2c7f9f06d651bc4be960c-playwright-logs.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIA2XUQHUQMLMBQZEP4%2F20210813%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210813T122514Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=50962c15b3d287475f2cd67c63f614301dcba7a8a43adfe96ebf0b444e8a6103' }
You can use the hashed_id
and build_hashed_id
to invoke the REST APIs. You can read more in the Playwright REST API documentation for BrowserStack.
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
- RESOURCES
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!