From 149b8bafa8d3587f160ca2b8cac7d01a66eb123b Mon Sep 17 00:00:00 2001 From: Tom Herold Date: Wed, 6 Nov 2024 10:31:44 +0100 Subject: [PATCH] add browserstack session ID to every test run --- .../test/puppeteer/dataset_rendering_helpers.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/javascripts/test/puppeteer/dataset_rendering_helpers.ts b/frontend/javascripts/test/puppeteer/dataset_rendering_helpers.ts index 2c8cdd456e..d10fbe67d9 100644 --- a/frontend/javascripts/test/puppeteer/dataset_rendering_helpers.ts +++ b/frontend/javascripts/test/puppeteer/dataset_rendering_helpers.ts @@ -374,16 +374,19 @@ export function setupBeforeEachAndAfterEach() { browser_version: "latest", os: "os x", os_version: "mojave", + name: t.title, // add test name to BrowserStack session "browserstack.username": process.env.BROWSERSTACK_USERNAME, "browserstack.accessKey": process.env.BROWSERSTACK_ACCESS_KEY, }; - t.context.browser = await puppeteer.connect({ + const browser = await puppeteer.connect({ browserWSEndpoint: `ws://cdp.browserstack.com/puppeteer?caps=${encodeURIComponent( JSON.stringify(caps), )}`, }); + t.context.browser = browser; console.log(`\nRunning chrome version ${await t.context.browser.version()}\n`); + console.log(`\nBrowserStack Session Id ${await getBrowserstackSessionId(browser)}\n`); global.Headers = Headers; global.fetch = fetch; global.Request = Request; @@ -397,6 +400,17 @@ export function setupBeforeEachAndAfterEach() { }); } +async function getBrowserstackSessionId(browser: Browser) { + const page = await browser.newPage(); + const response = (await page.evaluate( + (_) => {}, + `browserstack_executor: ${JSON.stringify({ action: "getSessionDetails" })}`, + )) as unknown as string; + + const sessionDetails = await JSON.parse(response); + return sessionDetails.hashed_id; +} + export function checkBrowserstackCredentials() { if (process.env.BROWSERSTACK_USERNAME == null || process.env.BROWSERSTACK_ACCESS_KEY == null) { throw new Error(