Skip to content

Commit

Permalink
add browserstack session ID to every test run
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzenklotz committed Nov 6, 2024
1 parent 41a2af7 commit 149b8ba
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion frontend/javascripts/test/puppeteer/dataset_rendering_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down

0 comments on commit 149b8ba

Please sign in to comment.