-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optional Vis-tests with browserstack (#15111)
- Loading branch information
Showing
6 changed files
with
246 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import cp from "child_process"; | ||
import BrowserStackLocal from "browserstack-local"; | ||
const clientPlaywrightVersion = cp.execSync("npx playwright --version").toString().trim().split(" ")[1]; | ||
|
||
// BrowserStack Specific Capabilities. | ||
// Set 'browserstack.local:true For Local testing | ||
const caps = { | ||
browser: "chrome", | ||
os: "osx", | ||
os_version: "catalina", | ||
name: "My first playwright test", | ||
build: "playwright-build", | ||
"browserstack.username": process.env.BROWSERSTACK_USERNAME, | ||
"browserstack.accessKey": process.env.BROWSERSTACK_ACCESS_KEY, | ||
"browserstack.local": process.env.BROWSERSTACK_LOCAL || false, | ||
"client.playwrightVersion": clientPlaywrightVersion, | ||
}; | ||
|
||
// replace YOUR_ACCESS_KEY with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY". | ||
export const BS_LOCAL_ARGS = { | ||
key: process.env.BROWSERSTACK_ACCESS_KEY, | ||
}; | ||
|
||
export const bsLocal = new BrowserStackLocal.Local(); | ||
|
||
// Patching the capabilities dynamically according to the project name. | ||
const patchCaps = (name, title) => { | ||
let combination = name.split(/@browserstack/)[0]; | ||
let [browerCaps, osCaps] = combination.split(/:/); | ||
let [browser, browser_version] = browerCaps.split(/@/); | ||
let osCapsSplit = osCaps.split(/ /); | ||
let os = osCapsSplit.shift(); | ||
let os_version = osCapsSplit.join(" "); | ||
caps.browser = browser ? browser : "chrome"; | ||
caps.os_version = browser_version ? browser_version : "latest"; | ||
caps.os = os ? os : "osx"; | ||
caps.os_version = os_version ? os_version : "catalina"; | ||
caps.name = title; | ||
}; | ||
|
||
export const getCdpEndpoint = (name: string, title: string) => { | ||
patchCaps(name, title); | ||
const cdpUrl = `wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent(JSON.stringify(caps))}`; | ||
return cdpUrl; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { BS_LOCAL_ARGS, bsLocal } from "./browserstack.config"; | ||
import { promisify } from "util"; | ||
const sleep = promisify(setTimeout); | ||
const redColour = "\x1b[31m"; | ||
const whiteColour = "\x1b[0m"; | ||
export default async () => { | ||
console.log("Starting BrowserStackLocal ..."); | ||
// Starts the Local instance with the required arguments | ||
let localResponseReceived = false; | ||
bsLocal.start(BS_LOCAL_ARGS, (err) => { | ||
if (err) { | ||
console.error(`${redColour}Error starting BrowserStackLocal${whiteColour}`); | ||
} else { | ||
console.log("BrowserStackLocal Started"); | ||
} | ||
localResponseReceived = true; | ||
}); | ||
while (!localResponseReceived) { | ||
await sleep(1000); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// global-teardown.js | ||
import { bsLocal } from "./browserstack.config"; | ||
import { promisify } from "util"; | ||
const sleep = promisify(setTimeout); | ||
export default async () => { | ||
// Stop the Local instance after your test run is completed, i.e after driver.quit | ||
let localStopped = false; | ||
|
||
if (bsLocal && bsLocal.isRunning()) { | ||
bsLocal.stop(() => { | ||
localStopped = true; | ||
console.log("Stopped BrowserStackLocal"); | ||
}); | ||
while (!localStopped) { | ||
await sleep(1000); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters