-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1046 from gemini-testing/TESTPLANE-386.latest_loc…
…al_browser feat: add ability to run local browsers without specified browserVersion
- Loading branch information
Showing
23 changed files
with
653 additions
and
189 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import _ from "lodash"; | ||
import { exec } from "child_process"; | ||
import { BrowserPlatform } from "@puppeteer/browsers"; | ||
import { getBrowserPlatform } from "../utils"; | ||
|
||
const extractBrowserVersion = (cmd: string): Promise<string> => | ||
new Promise<string>((resolve, reject) => { | ||
exec(cmd, (err, stdout) => { | ||
if (err) { | ||
const errorMessage = "Couldn't retrive edge version. Looks like its not installed"; | ||
|
||
reject(new Error(errorMessage)); | ||
|
||
return; | ||
} | ||
|
||
const edgeVersionRegExp = /\d+\.\d+\.\d+\.\d+/; | ||
const version = edgeVersionRegExp.exec(stdout); | ||
|
||
if (version && version[0]) { | ||
resolve(version[0]); | ||
} else { | ||
const errorMessage = `Couldn't retrive edge version. Expected browser version, but got "${stdout}"`; | ||
|
||
reject(new Error(errorMessage)); | ||
} | ||
}); | ||
}); | ||
|
||
const resolveLinuxEdgeVersion = (): Promise<string> => { | ||
const getMsEdgeStableVersion = "which microsoft-edge-stable > /dev/null && microsoft-edge-stable --version"; | ||
const getMsEdgeVersion = "which microsoft-edge > /dev/null && microsoft-edge --version"; | ||
|
||
return extractBrowserVersion(`${getMsEdgeStableVersion} || ${getMsEdgeVersion}`); | ||
}; | ||
|
||
const resolveWindowsEdgeVersion = (): Promise<string> => { | ||
const getMsEdgeVersion = 'reg query "HKEY_CURRENT_USER\\Software\\Microsoft\\Edge\\BLBeacon" /v version'; | ||
|
||
return extractBrowserVersion(getMsEdgeVersion); | ||
}; | ||
|
||
const resolveMacEdgeVersion = (): Promise<string> => { | ||
const getMsEdgeVersion = "/Applications/Microsoft\\ Edge.app/Contents/MacOS/Microsoft\\ Edge --version"; | ||
|
||
return extractBrowserVersion(getMsEdgeVersion); | ||
}; | ||
|
||
export const resolveEdgeVersion = _.once(async () => { | ||
const platform = getBrowserPlatform(); | ||
|
||
switch (platform) { | ||
case BrowserPlatform.LINUX: | ||
return resolveLinuxEdgeVersion(); | ||
|
||
case BrowserPlatform.WIN32: | ||
case BrowserPlatform.WIN64: | ||
return resolveWindowsEdgeVersion(); | ||
|
||
case BrowserPlatform.MAC: | ||
case BrowserPlatform.MAC_ARM: | ||
return resolveMacEdgeVersion(); | ||
|
||
default: | ||
throw new Error(`Unsupported platform: "${platform}"`); | ||
} | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { installBrowser, installBrowsersWithDrivers, BrowserInstallStatus } from "./install"; | ||
export { runBrowserDriver } from "./run"; | ||
export { resolveBrowserVersion } from "./resolve-browser-version"; | ||
export type { SupportedBrowser, SupportedDriver } from "./utils"; |
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
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,14 @@ | ||
import { BrowserName, type W3CBrowserName } from "../browser/types"; | ||
|
||
export const resolveBrowserVersion = (browserName: W3CBrowserName, { force = false } = {}): Promise<string> => { | ||
switch (browserName) { | ||
case BrowserName.CHROME: | ||
return import("./chrome").then(module => module.resolveLatestChromeVersion(force)); | ||
case BrowserName.FIREFOX: | ||
return import("./firefox").then(module => module.resolveLatestFirefoxVersion(force)); | ||
case BrowserName.EDGE: | ||
return import("./edge").then(module => module.resolveEdgeVersion()); | ||
case BrowserName.SAFARI: | ||
return import("./safari").then(module => module.resolveSafariVersion()); | ||
} | ||
}; |
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,24 @@ | ||
import _ from "lodash"; | ||
import { exec } from "child_process"; | ||
|
||
export const resolveSafariVersion = _.once( | ||
() => | ||
new Promise<string>((resolve, reject) => { | ||
const getSafariVersionError = new Error("Couldn't retrive safari version."); | ||
|
||
exec("mdls -name kMDItemVersion /Applications/Safari.app", (err, stdout) => { | ||
if (err) { | ||
reject(getSafariVersionError); | ||
return; | ||
} | ||
|
||
const regExpResult = /kMDItemVersion = "(.*)"/.exec(stdout); | ||
|
||
if (regExpResult && regExpResult[1]) { | ||
resolve(regExpResult[1]); | ||
} else { | ||
reject(getSafariVersionError); | ||
} | ||
}); | ||
}), | ||
); |
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
Oops, something went wrong.