Skip to content

Commit

Permalink
chore: run bidi firefox tests on ci (#32527)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Sep 10, 2024
1 parent 6d5889a commit c8a72d6
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 9 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/tests_bidi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# TODO: add Firefox
channel: [bidi-chrome-stable]
channel: [bidi-chromium, bidi-firefox-beta]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -38,5 +37,8 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
- run: npm run build
- run: npx playwright install --with-deps chromium
if: matrix.channel == 'bidi-chromium'
- run: npx -y @puppeteer/browsers install firefox@beta
if: matrix.channel == 'bidi-firefox-beta'
- name: Run tests
run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run biditest -- --project=${{ matrix.channel }}*
78 changes: 73 additions & 5 deletions packages/playwright-core/src/server/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ function readDescriptors(browsersJSON: BrowsersJSON) {

export type BrowserName = 'chromium' | 'firefox' | 'webkit' | 'bidi';
type InternalTool = 'ffmpeg' | 'firefox-beta' | 'chromium-tip-of-tree' | 'android';
type BidiChannel = 'bidi-firefox-stable' | 'bidi-chrome-canary' | 'bidi-chrome-stable';
type BidiChannel = 'bidi-firefox-stable' | 'bidi-firefox-beta' | 'bidi-firefox-nightly' | 'bidi-chrome-canary' | 'bidi-chrome-stable' | 'bidi-chromium';
type ChromiumChannel = 'chrome' | 'chrome-beta' | 'chrome-dev' | 'chrome-canary' | 'msedge' | 'msedge-beta' | 'msedge-dev' | 'msedge-canary';
const allDownloadable = ['chromium', 'firefox', 'webkit', 'ffmpeg', 'firefox-beta', 'chromium-tip-of-tree'];

Expand Down Expand Up @@ -525,11 +525,22 @@ export class Registry {
'win32': `\\Microsoft\\Edge SxS\\Application\\msedge.exe`,
}));

this._executables.push(this._createBidiChannel('bidi-firefox-stable', {
'linux': '/usr/bin/firefox',
'darwin': '/Applications/Firefox.app/Contents/MacOS/firefox',
'win32': '\\Mozilla Firefox\\firefox.exe',
this._executables.push(this._createBidiFirefoxChannel('bidi-firefox-stable', {
'linux': '/firefox/firefox',
'darwin': '/Firefox.app/Contents/MacOS/firefox',
'win32': '\\core\\firefox.exe',
}));
this._executables.push(this._createBidiFirefoxChannel('bidi-firefox-beta', {
'linux': '/firefox/firefox',
'darwin': '/Firefox.app/Contents/MacOS/firefox',
'win32': '\\core\\firefox.exe',
}));
this._executables.push(this._createBidiFirefoxChannel('bidi-firefox-nightly', {
'linux': '/firefox/firefox',
'darwin': '/Firefox Nightly.app/Contents/MacOS/firefox',
'win32': '\\firefox\\firefox.exe',
}));

this._executables.push(this._createBidiChannel('bidi-chrome-stable', {
'linux': '/opt/google/chrome/chrome',
'darwin': '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
Expand All @@ -540,6 +551,21 @@ export class Registry {
'darwin': '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
'win32': `\\Google\\Chrome SxS\\Application\\chrome.exe`,
}));
this._executables.push({
type: 'browser',
name: 'bidi-chromium',
browserName: 'bidi',
directory: chromium.dir,
executablePath: () => chromiumExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('chromium', chromiumExecutable, chromium.installByDefault, sdkLanguage),
installType: 'download-on-demand',
_validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'chromium', chromium.dir, ['chrome-linux'], [], ['chrome-win']),
downloadURLs: this._downloadURLs(chromium),
browserVersion: chromium.browserVersion,
_install: () => this._downloadExecutable(chromium, chromiumExecutable),
_dependencyGroup: 'chromium',
_isHermeticInstallation: true,
});

const firefox = descriptors.find(d => d.name === 'firefox')!;
const firefoxExecutable = findExecutablePath(firefox.dir, 'firefox');
Expand Down Expand Up @@ -691,6 +717,48 @@ export class Registry {
};
}

private _createBidiFirefoxChannel(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) {
if (shouldThrow)
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;
}
if (shouldThrow)
throw new Error(`Cannot find Firefox installation for channel '${name}' under ${folder}`);
return undefined;
};
return {
type: 'channel',
name,
browserName: 'bidi',
directory: undefined,
executablePath: (sdkLanguage: string) => executablePath(sdkLanguage, false),
executablePathOrDie: (sdkLanguage: string) => executablePath(sdkLanguage, true)!,
installType: 'none',
_validateHostRequirements: () => Promise.resolve(),
_isHermeticInstallation: true,
_install: install,
};
}

private _createBidiChannel(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'];
Expand Down
23 changes: 23 additions & 0 deletions tests/bidi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Running Bidi tests

To run Playwright tests with Bidi:

```sh
git clone https://github.com/microsoft/playwright.git
cd playwright
npm run build # call `npm run watch` for watch mode
npx playwright install chromium
npm run biditest -- --project='bidi-firefox-beta-*'
```

To install beta channel of Firefox, run the following command in the project root:
```sh
npx -y @puppeteer/browsers install firefox@beta
```

You can also pass custom binary path via `BIDIPATH`:
```sh
BIDIPATH='/Users/myself/Downloads/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing'
```


4 changes: 2 additions & 2 deletions tests/bidi/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ if (executablePath && !process.env.TEST_WORKER_INDEX)
console.error(`Using executable at ${executablePath}`);
const testIgnore: RegExp[] = [];
const browserToChannels = {
'_bidiChromium': ['bidi-chrome-stable'],
'_bidiFirefox': ['bidi-firefox-stable'],
'_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;
Expand Down

0 comments on commit c8a72d6

Please sign in to comment.