-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ability to run local browsers without specified browserVersion #1046
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
export const CHROMEDRIVER_STORAGE_API = "https://chromedriver.storage.googleapis.com"; | ||
|
||
const CHROME_FOR_TESTING_VERSIONS_API_URL = "https://googlechromelabs.github.io/chrome-for-testing"; | ||
export const CHROME_FOR_TESTING_MILESTONES_API_URL = `${CHROME_FOR_TESTING_VERSIONS_API_URL}/latest-versions-per-milestone.json`; | ||
export const CHROME_FOR_TESTING_LATEST_STABLE_API_URL = `${CHROME_FOR_TESTING_VERSIONS_API_URL}/LATEST_RELEASE_STABLE`; | ||
|
||
export const GECKODRIVER_CARGO_TOML = "https://raw.githubusercontent.com/mozilla/geckodriver/release/Cargo.toml"; | ||
|
||
const FIREFOX_VERSIONS_VERSIONS_API_URL = "https://product-details.mozilla.org/1.0"; | ||
export const FIREFOX_VERSIONS_ALL_VERSIONS_API_URL = `${FIREFOX_VERSIONS_VERSIONS_API_URL}/firefox.json`; | ||
export const FIREFOX_VERSIONS_LATEST_VERSIONS_API_URL = `${FIREFOX_VERSIONS_VERSIONS_API_URL}/firefox_versions.json`; | ||
Comment on lines
+3
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут использую еще пару ручек тех же самых хостов |
||
|
||
export const MSEDGEDRIVER_API = "https://msedgedriver.azureedge.net"; | ||
|
||
export const SAFARIDRIVER_PATH = "/usr/bin/safaridriver"; | ||
export const MIN_CHROME_FOR_TESTING_VERSION = 113; | ||
export const MIN_CHROMEDRIVER_FOR_TESTING_VERSION = 115; | ||
|
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}"`); | ||
} | ||
}); | ||
Comment on lines
+49
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут вычисляем, какая версия edge локально установлена на компьютере |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import _ from "lodash"; | ||
import { canDownload, install as puppeteerInstall } from "@puppeteer/browsers"; | ||
import { browserInstallerDebug, getBrowserPlatform, getBrowsersDir, type DownloadProgressCallback } from "../utils"; | ||
import { | ||
browserInstallerDebug, | ||
getBrowserPlatform, | ||
getBrowsersDir, | ||
retryFetch, | ||
type DownloadProgressCallback, | ||
} from "../utils"; | ||
import registry from "../registry"; | ||
import { getFirefoxBuildId, normalizeFirefoxVersion } from "./utils"; | ||
import { installLatestGeckoDriver } from "./driver"; | ||
import { installUbuntuPackageDependencies } from "../ubuntu-packages"; | ||
import { BrowserName } from "../../browser/types"; | ||
import { FIREFOX_VERSIONS_LATEST_VERSIONS_API_URL } from "../constants"; | ||
|
||
const installFirefoxBrowser = async (version: string, { force = false } = {}): Promise<string> => { | ||
const platform = getBrowserPlatform(); | ||
|
@@ -59,3 +67,21 @@ export const installFirefox = async ( | |
|
||
return browserPath; | ||
}; | ||
|
||
export const resolveLatestFirefoxVersion = _.memoize(async (force = false): Promise<string> => { | ||
if (!force) { | ||
const platform = getBrowserPlatform(); | ||
const existingLocallyBrowserVersion = registry.getMatchedBrowserVersion(BrowserName.FIREFOX, platform); | ||
|
||
if (existingLocallyBrowserVersion) { | ||
return existingLocallyBrowserVersion; | ||
} | ||
} | ||
|
||
return retryFetch(FIREFOX_VERSIONS_LATEST_VERSIONS_API_URL) | ||
.then(res => res.json()) | ||
.then(({ LATEST_FIREFOX_VERSION }) => LATEST_FIREFOX_VERSION) | ||
.catch(() => { | ||
throw new Error("Couldn't resolve latest firefox version"); | ||
}); | ||
}); | ||
Comment on lines
+71
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Аналогично "chrome" |
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"; |
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()); | ||
} | ||
}; |
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); | ||
} | ||
}); | ||
}), | ||
); | ||
Comment on lines
+4
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Аналогично edge: достаем локально имеющуюся версию safari |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Достаем либо "какую-то локально имеющуюся".
Если "какой-то" локально нет, ходим в АПИ-шку и достаем последнюю оттуда.
Также всегда ходим в АПИ-шку при явном вызове
install-deps
(force === true, если вызвалиnpx testplane install-deps
)