Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore(bidi): use channel for preinstalled browsers, env for downloaded (#35523)
Yury Semikhatsky9d30505472e9
diff --git a/.github/workflows/tests_bidi.yml b/.github/workflows/tests_bidi.ymlindex 0d8640268f..bf8815b42c 100644--- a/.github/workflows/tests_bidi.yml+++ b/.github/workflows/tests_bidi.yml@@ -39,12 +39,17 @@ jobs:- run: npm run build- run: npx playwright install --with-deps chromiumif: matrix.channel == 'bidi-chromium'- - run: npx -y @puppeteer/browsers install firefox@nightly- if: matrix.channel == 'bidi-firefox-nightly'+ - if: matrix.channel == 'bidi-firefox-nightly'+ id: install_firefox+ run: |+ npx -y @puppeteer/browsers install firefox@nightly |\+ awk 'END { $1=""; sub(/^ /,""); print "bidi_ffpath="$0 }' |\+ tee -a $GITHUB_OUTPUT- name: Run testsrun: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run biditest -- --project=${{ matrix.channel }}*env:PWTEST_USE_BIDI_EXPECTATIONS: '1'+ BIDI_FFPATH: ${{ steps.install_firefox.outputs.bidi_ffpath }}- name: Upload csv report to GitHubif: ${{ !cancelled() }}uses: actions/upload-artifact@v4diff --git a/packages/playwright-core/src/server/registry/index.ts b/packages/playwright-core/src/server/registry/index.tsindex 1af32cb1c6..3b3e90720a 100644--- a/packages/playwright-core/src/server/registry/index.ts+++ b/packages/playwright-core/src/server/registry/index.ts@@ -683,27 +683,27 @@ export class Registry {}));this._executables.push(this._createBidiFirefoxChannel('bidi-firefox-stable', {- 'linux': '/firefox/firefox',- 'darwin': '/Firefox.app/Contents/MacOS/firefox',- 'win32': '\\core\\firefox.exe',+ 'linux': '/snap/bin/firefox',+ 'darwin': '/Applications/Firefox.app/Contents/MacOS/firefox',+ 'win32': '\\Mozilla Firefox\\firefox.exe',}));this._executables.push(this._createBidiFirefoxChannel('bidi-firefox-beta', {- 'linux': '/firefox/firefox',- 'darwin': '/Firefox.app/Contents/MacOS/firefox',- 'win32': '\\core\\firefox.exe',+ 'linux': '/opt/firefox-beta/firefox',+ 'darwin': '/Applications/Firefox.app/Contents/MacOS/firefox',+ 'win32': '\\Mozilla Firefox\\firefox.exe',}));this._executables.push(this._createBidiFirefoxChannel('bidi-firefox-nightly', {- 'linux': '/firefox/firefox',- 'darwin': '/Firefox Nightly.app/Contents/MacOS/firefox',- 'win32': '\\firefox\\firefox.exe',+ 'linux': '/opt/firefox-nightly/firefox',+ 'darwin': '/Applications/Firefox Nightly.app/Contents/MacOS/firefox',+ 'win32': '\\Mozilla Firefox\\firefox.exe',}));- this._executables.push(this._createBidiChannel('bidi-chrome-stable', {+ this._executables.push(this._createBidiChromiumChannel('bidi-chrome-stable', {'linux': '/opt/google/chrome/chrome','darwin': '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome','win32': `\\Google\\Chrome\\Application\\chrome.exe`,}));- this._executables.push(this._createBidiChannel('bidi-chrome-canary', {+ this._executables.push(this._createBidiChromiumChannel('bidi-chrome-canary', {'linux': '','darwin': '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary','win32': `\\Google\\Chrome SxS\\Application\\chrome.exe`,@@ -903,24 +903,22 @@ export class Registry {throw new Error(`Firefox distribution '${name}' is not supported on ${process.platform}`);return undefined;}- const folder = path.resolve('firefox');- let channelName = 'stable';- if (name.includes('beta'))- channelName = 'beta';- else if (name.includes('nightly'))- channelName = 'nightly';- const installedVersions = fs.readdirSync(folder);- const found = installedVersions.filter(e => e.includes(channelName));- if (found.length === 1)- return path.join(folder, found[0], suffix);- if (found.length > 1) {- if (shouldThrow)- throw new Error(`Multiple Firefox installations found for channel '${name}': ${found.join(', ')}`);- else- return undefined;+ const prefixes = (process.platform === 'win32' ? [+ process.env.LOCALAPPDATA,+ process.env.PROGRAMFILES,+ process.env['PROGRAMFILES(X86)'],+ // In some cases there is no PROGRAMFILES/(86) env var set but HOMEDRIVE is set.+ process.env.HOMEDRIVE + '\\Program Files',+ process.env.HOMEDRIVE + '\\Program Files (x86)',+ ].filter(Boolean) : ['']) as string[];++ for (const prefix of prefixes) {+ const executablePath = path.join(prefix, suffix);+ if (canAccessFile(executablePath))+ return executablePath;}if (shouldThrow)- throw new Error(`Cannot find Firefox installation for channel '${name}' under ${folder}`);+ throw new Error(`Cannot find Firefox installation for channel '${name}' at the standard system paths.`);return undefined;};return {@@ -937,7 +935,7 @@ export class Registry {};}- private _createBidiChannel(name: BidiChannel, lookAt: Record<'linux' | 'darwin' | 'win32', string>, install?: () => Promise<void>): ExecutableImpl {+ private _createBidiChromiumChannel(name: BidiChannel, lookAt: Record<'linux' | 'darwin' | 'win32', string>, install?: () => Promise<void>): ExecutableImpl {const executablePath = (sdkLanguage: string, shouldThrow: boolean) => {const suffix = lookAt[process.platform as 'linux' | 'darwin' | 'win32'];if (!suffix) {@@ -964,7 +962,7 @@ export class Registry {const location = prefixes.length ? ` at ${path.join(prefixes[0], suffix)}` : ``;const installation = install ? `\nRun "${buildPlaywrightCLICommand(sdkLanguage, 'install ' + name)}"` : '';- throw new Error(`Firefox distribution '${name}' is not found${location}${installation}`);+ throw new Error(`Chromium distribution '${name}' is not found${location}${installation}`);};return {type: 'channel',diff --git a/tests/bidi/playwright.config.ts b/tests/bidi/playwright.config.tsindex c8add44d0f..f9e79ae902 100644--- a/tests/bidi/playwright.config.ts+++ b/tests/bidi/playwright.config.ts@@ -65,15 +65,25 @@ const config: Config<PlaywrightWorkerOptions & PlaywrightTestOptions & TestModeWprojects: [],};-const executablePath = process.env.BIDIPATH;-if (executablePath && !process.env.TEST_WORKER_INDEX)- console.error(`Using executable at ${executablePath}`);+type BrowserName = '_bidiChromium' | '_bidiFirefox';++const getExecutablePath = (browserName: BrowserName) => {+ if (browserName === '_bidiChromium')+ return process.env.BIDI_CRPATH;+ if (browserName === '_bidiFirefox')+ return process.env.BIDI_FFPATH;+};+const browserToChannels = {'_bidiChromium': ['bidi-chromium', 'bidi-chrome-canary', 'bidi-chrome-stable'],'_bidiFirefox': ['bidi-firefox-nightly', 'bidi-firefox-beta', 'bidi-firefox-stable'],};+for (const [key, channels] of Object.entries(browserToChannels)) {const browserName: any = key;+ const executablePath = getExecutablePath(browserName);+ if (executablePath && !process.env.TEST_WORKER_INDEX)+ console.error(`Using executable at ${executablePath}`);for (const channel of channels) {const testIgnore: RegExp[] = [/library\/debug-controller/,