Get Puppeteer Session Details
When a Puppeteer test runs on TestingBot, it will generate various artifacts such as logs, video, screenshots and other files.
TestingBot will save these files for later retrieval, through our member dashboard or the TestingBot REST API.
To fetch these details through our REST API, you will need to know the unique identifier for each test.
TestingBot provides a sessionId
which you can retrieve during your test, to use in REST API calls.
Fetch the sessionId
To fetch the sessionId in your Puppeteer script, you can use the custom TestingBot command:
const testingBotResponse = await page.evaluate(_ => {}, `testingbot_executor: ${JSON.stringify({action: 'getSessionDetails'})}`)
The response will contain a sessionId
, which is a unique identifier for this test.
You can then use this sessionId with the TestingBot REST-API.
const puppeteer = require('puppeteer-core')
(async () => {
const capabilities = {
'tb:options': {
key: process.env.TB_KEY,
secret: process.env.TB_SECRET
},
browserName: 'chrome',
browserVersion: 'latest'
}
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://cloud.testingbot.com/puppeteer?capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`
})
const page = await browser.newPage()
await page.goto('https://testingbot.com')
const testingBotResponse = await page.evaluate(_ => {}, `testingbot_executor: ${JSON.stringify({action: 'setSessionStatus',arguments: {passed: true, reason: 'Title matched'}})}`)
const sessionId = testingBotResponse.sessionId
console.log(`Your unique TestingBot SessionId is ${sessionId}`)
browser.close()
})()