feat: make `playwright` package not install browsers automatically (#26672)

Additionally introduce `@playwright/browser-<browser>` packages that
just download the respective browser, but do not export anything.

References #26614.
This commit is contained in:
Dmitry Gozman 2023-08-27 07:24:35 -07:00 коммит произвёл GitHub
Родитель 72aef6bc1d
Коммит 36347e7fea
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
51 изменённых файлов: 589 добавлений и 115 удалений

Просмотреть файл

@ -468,31 +468,17 @@ Sometimes companies maintain an internal proxy that blocks direct access to the
resources. In this case, Playwright can be configured to download browsers via a proxy server.
```bash tab=bash-bash lang=js
# For Playwright Test
HTTPS_PROXY=https://192.0.2.1 npx playwright install
# For Playwright Library
HTTPS_PROXY=https://192.0.2.1 npm install playwright
```
```batch tab=bash-batch lang=js
# For Playwright Test
set HTTPS_PROXY=https://192.0.2.1
npx playwright install
# For Playwright Library
set HTTPS_PROXY=https://192.0.2.1
npm install playwright
```
```powershell tab=bash-powershell lang=js
# For Playwright Test
$Env:HTTPS_PROXY="https://192.0.2.1"
npx playwright install
# For Playwright Library
$Env:HTTPS_PROXY="https://192.0.2.1"
npm install playwright
```
```bash tab=bash-bash lang=python
@ -614,6 +600,7 @@ pwsh bin/Debug/netX/playwright.ps1 install
$Env:PLAYWRIGHT_DOWNLOAD_CONNECTION_TIMEOUT="120000"
pwsh bin/Debug/netX/playwright.ps1 install
```
## Download from artifact repository
By default, Playwright downloads browsers from Microsoft's CDN.
@ -623,31 +610,17 @@ binaries. In this case, Playwright can be configured to download from a custom
location using the `PLAYWRIGHT_DOWNLOAD_HOST` env variable.
```bash tab=bash-bash lang=js
# For Playwright Test
PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 npx playwright install
# For Playwright Library
PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 npm install playwright
```
```batch tab=bash-batch lang=js
# For Playwright Test
set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
npx playwright install
# For Playwright Library
set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
npm install playwright
```
```powershell tab=bash-powershell lang=js
# For Playwright Test
$Env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1"
npx playwright install
# For Playwright Library
$Env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1"
npm install playwright
```
```bash tab=bash-bash lang=python
@ -699,35 +672,19 @@ It is also possible to use a per-browser download hosts using `PLAYWRIGHT_CHROMI
take precedence over `PLAYWRIGHT_DOWNLOAD_HOST`.
```bash tab=bash-bash lang=js
# For Playwright Test
PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3 PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 npx playwright install
# For Playwright Library
PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3 PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 npm install playwright
```
```batch tab=bash-batch lang=js
# For Playwright Test
set PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3
set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
npx playwright install
# For Playwright Library
set PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST=203.0.113.3
set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
npm install playwright
```
```powershell tab=bash-powershell lang=js
# For Playwright Test
$Env:PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST="203.0.113.3"
$Env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1"
npx playwright install
# For Playwright Library
$Env:PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST="203.0.113.3"
$Env:PLAYWRIGHT_DOWNLOAD_HOST="192.0.2.1"
npm install playwright
```
```bash tab=bash-bash lang=python

Просмотреть файл

@ -99,8 +99,8 @@ The key differences to note are as follows:
| | Library | Test |
| - | - | - |
| Installation | `npm install playwright` | `npm init playwright@latest` - note `install` vs. `init` |
| Install browsers | Chromium, Firefox, WebKit are installed by default | `npx playwright install` or `npx playwright install chromium` for a single one |
| `import`/`require` name | `playwright` | `@playwright/test` |
| Install browsers | Install `@playwright/browser-chromium`, `@playwright/browser-firefox` and/or `@playwright/browser-webkit` | `npx playwright install` or `npx playwright install chromium` for a single one |
| `import` from | `playwright` | `@playwright/test` |
| Initialization | Explicitly need to: <ol><li>Pick a browser to use, e.g. `chromium`</li><li>Launch browser with [`method: BrowserType.launch`]</li><li>Create a context with [`method: Browser.newContext`], <em>and</em> pass any context options explicitly, e.g. `devices['iPhone 11']`</li><li>Create a page with [`method: BrowserContext.newPage`]</li></ol> | An isolated `page` and `context` are provided to each test out-of the box, along with other [built-in fixtures](./test-fixtures.md#built-in-fixtures). No explicit creation. If referenced by the test in it's arguments, the Test Runner will create them for the test. (i.e. lazy-initialization) |
| Assertions | No built-in Web-First Assertions | [Web-First assertions](./test-assertions.md) like: <ul><li>[`method: PageAssertions.toHaveTitle`]</li><li>[`method: PageAssertions.toHaveScreenshot#1`]</li></ul> which auto-wait and retry for the condition to be met.|
| Cleanup | Explicitly need to: <ol><li>Close context with [`method: BrowserContext.close`]</li><li>Close browser with [`method: Browser.close`]</li></ol> | No explicit close of [built-in fixtures](./test-fixtures.md#built-in-fixtures); the Test Runner will take care of it.
@ -124,9 +124,19 @@ Use npm or Yarn to install Playwright library in your Node.js project. See [syst
npm i -D playwright
```
This single command downloads the Playwright NPM package and browser binaries for Chromium, Firefox and WebKit. To modify this behavior see [managing browsers](./browsers.md#managing-browser-binaries).
You will also need to install browsers - either manually or by adding a package that will do it for you automatically.
Once installed, you can `require` Playwright in a Node.js script, and launch any of the 3 browsers (`chromium`, `firefox` and `webkit`).
```bash
# Download the Chromium, Firefox and WebKit browser
npx playwright install chromium firefox webkit
# Alternatively, add packages that will download a browser upon npm install
npm i -D @playwright/browser-chromium @playwright/browser-firefox @playwright/browser-webkit
```
See [managing browsers](./browsers.md#managing-browser-binaries) for more options.
Once installed, you can import Playwright in a Node.js script, and launch any of the 3 browsers (`chromium`, `firefox` and `webkit`).
```js
const { chromium } = require('playwright');
@ -179,25 +189,114 @@ npx playwright codegen wikipedia.org
## Browser downloads
By default, `playwright` automatically downloads Chromium, Firefox and WebKit during package installation.
To download Playwright browsers run:
```bash
# Explicitly download browsers
npx playwright install
```
Alternatively, you can add `@playwright/browser-chromium`, `@playwright/browser-firefox` and `@playwright/browser-webkit` packages to automatically download the respective browser during the package installation.
```bash
# Use a helper package that downloads a browser on npm install
npm install @playwright/browser-chromium
```
**Download behind a firewall or a proxy**
Pass `HTTPS_PROXY` environment variable to download through a proxy.
```bash tab=bash-bash lang=js
# Manual
HTTPS_PROXY=https://192.0.2.1 npx playwright install
# Through @playwright/browser-chromium, @playwright/browser-firefox
# and @playwright/browser-webkit helper packages
HTTPS_PROXY=https://192.0.2.1 npm install
```
```batch tab=bash-batch lang=js
# Manual
set HTTPS_PROXY=https://192.0.2.1
npx playwright install
# Through @playwright/browser-chromium, @playwright/browser-firefox
# and @playwright/browser-webkit helper packages
set HTTPS_PROXY=https://192.0.2.1
npm install
```
```powershell tab=bash-powershell lang=js
# Manual
$Env:HTTPS_PROXY=https://192.0.2.1
npx playwright install
# Through @playwright/browser-chromium, @playwright/browser-firefox
# and @playwright/browser-webkit helper packages
$Env:HTTPS_PROXY=https://192.0.2.1
npm install
```
**Download from artifact repository**
By default, Playwright downloads browsers from Microsoft's CDN. Pass `PLAYWRIGHT_DOWNLOAD_HOST` environment variable to download from an internal artifacts repository instead.
```bash tab=bash-bash lang=js
# Manual
PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 npx playwright install
# Through @playwright/browser-chromium, @playwright/browser-firefox
# and @playwright/browser-webkit helper packages
PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1 npm install
```
```batch tab=bash-batch lang=js
# Manual
set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
npx playwright install
# Through @playwright/browser-chromium, @playwright/browser-firefox
# and @playwright/browser-webkit helper packages
set PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
npm install
```
```powershell tab=bash-powershell lang=js
# Manual
$Env:PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
npx playwright install
# Through @playwright/browser-chromium, @playwright/browser-firefox
# and @playwright/browser-webkit helper packages
$Env:PLAYWRIGHT_DOWNLOAD_HOST=192.0.2.1
npm install
```
**Skip browser download**
In certain cases, it is desired to avoid browser downloads altogether because browser binaries are managed separately. This can be done by setting `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` variable before installing packages.
```bash tab=bash-bash lang=js
# When using @playwright/browser-chromium, @playwright/browser-firefox
# and @playwright/browser-webkit helper packages
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install
```
```batch tab=bash-batch lang=js
# When using @playwright/browser-chromium, @playwright/browser-firefox
# and @playwright/browser-webkit helper packages
set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
npm install
```
```powershell tab=bash-powershell lang=js
# When using @playwright/browser-chromium, @playwright/browser-firefox
# and @playwright/browser-webkit helper packages
$Env:PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
npm install
```
## TypeScript support
Playwright includes built-in support for TypeScript. Type definitions will be imported automatically. It is recommended to use type-checking to improve the IDE experience.

67
package-lock.json сгенерированный
Просмотреть файл

@ -1396,6 +1396,18 @@
"node": ">= 8"
}
},
"node_modules/@playwright/browser-chromium": {
"resolved": "packages/playwright-browser-chromium",
"link": true
},
"node_modules/@playwright/browser-firefox": {
"resolved": "packages/playwright-browser-firefox",
"link": true
},
"node_modules/@playwright/browser-webkit": {
"resolved": "packages/playwright-browser-webkit",
"link": true
},
"node_modules/@playwright/experimental-ct-core": {
"resolved": "packages/playwright-ct-core",
"link": true
@ -6278,7 +6290,6 @@
},
"packages/playwright": {
"version": "1.38.0-next",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.38.0-next"
@ -6290,6 +6301,42 @@
"node": ">=16"
}
},
"packages/playwright-browser-chromium": {
"name": "@playwright/browser-chromium",
"version": "1.38.0-next",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.38.0-next"
},
"engines": {
"node": ">=16"
}
},
"packages/playwright-browser-firefox": {
"name": "@playwright/browser-firefox",
"version": "1.38.0-next",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.38.0-next"
},
"engines": {
"node": ">=16"
}
},
"packages/playwright-browser-webkit": {
"name": "@playwright/browser-webkit",
"version": "1.38.0-next",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.38.0-next"
},
"engines": {
"node": ">=16"
}
},
"packages/playwright-chromium": {
"version": "1.38.0-next",
"hasInstallScript": true,
@ -7402,6 +7449,24 @@
"fastq": "^1.6.0"
}
},
"@playwright/browser-chromium": {
"version": "file:packages/playwright-browser-chromium",
"requires": {
"playwright-core": "1.38.0-next"
}
},
"@playwright/browser-firefox": {
"version": "file:packages/playwright-browser-firefox",
"requires": {
"playwright-core": "1.38.0-next"
}
},
"@playwright/browser-webkit": {
"version": "file:packages/playwright-browser-webkit",
"requires": {
"playwright-core": "1.38.0-next"
}
},
"@playwright/experimental-ct-core": {
"version": "file:packages/playwright-ct-core",
"requires": {

Просмотреть файл

@ -0,0 +1,3 @@
# @playwright/browser-chromium
This package automatically installs [Chromium](https://www.chromium.org/) browser for [Playwright](http://github.com/microsoft/playwright) library. If you want to write end-to-end tests, we recommend [@playwright/test](https://playwright.dev/docs/intro).

17
packages/playwright-browser-chromium/index.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,17 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export {};

Просмотреть файл

@ -0,0 +1,15 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Просмотреть файл

@ -0,0 +1,15 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Просмотреть файл

@ -0,0 +1,27 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
let install;
try {
if (!require('playwright-core/lib/utils').isLikelyNpxGlobal())
install = require('playwright-core/lib/server').installBrowsersForNpmInstall;
} catch (e) {
// Dev build, don't install browsers by default.
}
if (install)
install(['chromium', 'ffmpeg']);

Просмотреть файл

@ -0,0 +1,29 @@
{
"name": "@playwright/browser-chromium",
"version": "1.38.0-next",
"description": "Playwright package that automatically installs Chromium",
"repository": "github:Microsoft/playwright",
"homepage": "https://playwright.dev",
"engines": {
"node": ">=16"
},
"author": {
"name": "Microsoft Corporation"
},
"license": "Apache-2.0",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.mjs",
"require": "./index.js",
"default": "./index.js"
},
"./package.json": "./package.json"
},
"scripts": {
"install": "node install.js"
},
"dependencies": {
"playwright-core": "1.38.0-next"
}
}

Просмотреть файл

@ -0,0 +1,3 @@
# @playwright/browser-firefox
This package automatically installs [Firefox](https://www.mozilla.org/firefox/) browser for [Playwright](http://github.com/microsoft/playwright) library. If you want to write end-to-end tests, we recommend [@playwright/test](https://playwright.dev/docs/intro).

17
packages/playwright-browser-firefox/index.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,17 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export {};

Просмотреть файл

@ -0,0 +1,15 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Просмотреть файл

@ -0,0 +1,15 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Просмотреть файл

@ -0,0 +1,27 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
let install;
try {
if (!require('playwright-core/lib/utils').isLikelyNpxGlobal())
install = require('playwright-core/lib/server').installBrowsersForNpmInstall;
} catch (e) {
// Dev build, don't install browsers by default.
}
if (install)
install(['firefox']);

Просмотреть файл

@ -0,0 +1,29 @@
{
"name": "@playwright/browser-firefox",
"version": "1.38.0-next",
"description": "Playwright package that automatically installs Firefox",
"repository": "github:Microsoft/playwright",
"homepage": "https://playwright.dev",
"engines": {
"node": ">=16"
},
"author": {
"name": "Microsoft Corporation"
},
"license": "Apache-2.0",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.mjs",
"require": "./index.js",
"default": "./index.js"
},
"./package.json": "./package.json"
},
"scripts": {
"install": "node install.js"
},
"dependencies": {
"playwright-core": "1.38.0-next"
}
}

Просмотреть файл

@ -0,0 +1,3 @@
# @playwright/browser-webkit
This package automatically installs [WebKit](https://www.webkit.org/) browser for [Playwright](http://github.com/microsoft/playwright) library. If you want to write end-to-end tests, we recommend [@playwright/test](https://playwright.dev/docs/intro).

17
packages/playwright-browser-webkit/index.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,17 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export {};

Просмотреть файл

@ -0,0 +1,15 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Просмотреть файл

@ -0,0 +1,15 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

Просмотреть файл

@ -18,10 +18,10 @@ let install;
try {
if (!require('playwright-core/lib/utils').isLikelyNpxGlobal())
install = require('playwright-core/lib/server').installDefaultBrowsersForNpmInstall;
install = require('playwright-core/lib/server').installBrowsersForNpmInstall;
} catch (e) {
// Dev build, don't install browsers by default.
}
if (install)
install();
install(['webkit']);

Просмотреть файл

@ -0,0 +1,29 @@
{
"name": "@playwright/browser-webkit",
"version": "1.38.0-next",
"description": "Playwright package that automatically installs WebKit",
"repository": "github:Microsoft/playwright",
"homepage": "https://playwright.dev",
"engines": {
"node": ">=16"
},
"author": {
"name": "Microsoft Corporation"
},
"license": "Apache-2.0",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.mjs",
"require": "./index.js",
"default": "./index.js"
},
"./package.json": "./package.json"
},
"scripts": {
"install": "node install.js"
},
"dependencies": {
"playwright-core": "1.38.0-next"
}
}

Просмотреть файл

@ -25,7 +25,6 @@
"playwright": "./cli.js"
},
"scripts": {
"install": "node install.js"
},
"dependencies": {
"playwright-core": "1.38.0-next"

Просмотреть файл

@ -16,7 +16,7 @@
import { test } from './npmTest';
test('android types', async ({ exec, tsc, writeFiles }) => {
await exec('npm i --foreground-scripts playwright', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
await exec('npm i --foreground-scripts playwright');
await writeFiles({
'test.ts':
`import { AndroidDevice, _android, AndroidWebView, Page } from 'playwright';`,

Просмотреть файл

@ -16,7 +16,7 @@
import { test, expect } from './npmTest';
test('driver should work', async ({ exec }) => {
await exec('npm i --foreground-scripts playwright', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
await exec('npm i --foreground-scripts playwright');
await exec('npx playwright install');
await exec('node driver-client.js');
});
@ -24,7 +24,7 @@ test('driver should work', async ({ exec }) => {
test('driver should ignore SIGINT', async ({ exec }) => {
test.skip(process.platform === 'win32', 'Only relevant for POSIX');
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright-python/issues/1843' });
await exec('npm i --foreground-scripts playwright', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
await exec('npm i --foreground-scripts playwright');
await exec('npx playwright install chromium');
const output = await exec('node driver-client-sigint.js');
const lines = output.split('\n').filter(l => l.trim());

Просмотреть файл

@ -16,7 +16,7 @@
import { test } from './npmTest';
test('electron types', async ({ exec, tsc, writeFiles }) => {
await exec('npm i --foreground-scripts playwright electron@12', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
await exec('npm i --foreground-scripts playwright electron@12');
await writeFiles({
'test.ts':
`import { Page, _electron, ElectronApplication, Electron } from 'playwright';`

Просмотреть файл

@ -0,0 +1,27 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const requireName = process.argv[2];
const pkg = require(requireName);
for (const key of ['chromium', 'firefox', 'webkit', 'test', 'devices']) {
if (pkg[key] !== undefined) {
console.error(`Package ${requireName} should not export ${key}`);
process.exit(1);
}
}
console.log(`${requireName} SUCCESS`);

Просмотреть файл

@ -15,20 +15,7 @@
*/
const requireName = process.argv[2];
let success = {
'playwright': ['chromium', 'firefox', 'webkit'],
'playwright-chromium': ['chromium'],
'playwright-firefox': ['firefox'],
'playwright-webkit': ['webkit'],
'@playwright/test': ['chromium', 'firefox', 'webkit'],
}[requireName];
if (process.argv[3] === 'none')
success = [];
else if (process.argv[3] === 'all')
success = ['chromium', 'firefox', 'webkit'];
else if (process.argv[3])
success = process.argv.slice(3)
const success = process.argv.slice(3);
const playwright = require(requireName);
const packageJSON = require(requireName + '/package.json');

Просмотреть файл

@ -15,16 +15,7 @@
*/
const requireName = process.argv[2];
let success = {
'playwright': ['chromium', 'firefox', 'webkit'],
'playwright-chromium': ['chromium'],
'playwright-firefox': ['firefox'],
'playwright-webkit': ['webkit'],
}[requireName];
if (process.argv[3] === 'none')
success = [];
if (process.argv[3] === 'all')
success = ['chromium', 'firefox', 'webkit'];
const success = process.argv.slice(3);
const playwright = require(requireName);
const fs = require('fs');

Просмотреть файл

@ -50,6 +50,9 @@ async function globalSetup() {
build('playwright-chromium'),
build('playwright-firefox'),
build('playwright-webkit'),
build('playwright-browser-chromium', '@playwright/browser-chromium'),
build('playwright-browser-firefox', '@playwright/browser-firefox'),
build('playwright-browser-webkit', '@playwright/browser-webkit'),
]);
await fs.promises.writeFile(path.join(__dirname, '.registry.json'), JSON.stringify(Object.fromEntries(builds)));

Просмотреть файл

@ -18,7 +18,7 @@ import { test, expect } from './npmTest';
import fs from 'fs';
test('installs local packages', async ({ registry, exec, tmpWorkspace }) => {
const packages = ['playwright', 'playwright-core', 'playwright-chromium', 'playwright-firefox', 'playwright-webkit', '@playwright/test'];
const packages = ['playwright', 'playwright-core', 'playwright-chromium', 'playwright-firefox', 'playwright-webkit', '@playwright/test', '@playwright/browser-chromium', '@playwright/browser-firefox', '@playwright/browser-webkit'];
await exec('npm i --foreground-scripts', ...packages, { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
const output = await exec('node', path.join(__dirname, '..', '..', 'utils', 'workspace.js'), '--get-version');

Просмотреть файл

@ -17,6 +17,7 @@ import { test, expect } from './npmTest';
test('npx playwright install global', async ({ exec, installedSoftwareOnDisk }) => {
test.skip(process.platform === 'win32', 'isLikelyNpxGlobal() does not work in this setup on our bots');
const result = await exec('npx playwright install', { env: { npm_config_prefix: '' } }); // global npx and npm_config_prefix do not work together nicely (https://github.com/npm/cli/issues/5268)
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);

Просмотреть файл

@ -35,13 +35,14 @@ const parsedDownloads = (rawLogs: string) => {
for (const cdn of CDNS) {
test(`playwright cdn failover should work (${cdn})`, async ({ exec, nodeMajorVersion, installedSoftwareOnDisk }) => {
const result = await exec('npm i --foreground-scripts playwright', { env: { PW_TEST_CDN_THAT_SHOULD_WORK: cdn, DEBUG: 'pw:install' } });
await exec('npm i --foreground-scripts playwright');
const result = await exec('npx playwright install', { env: { PW_TEST_CDN_THAT_SHOULD_WORK: cdn, DEBUG: 'pw:install' } });
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
const dls = parsedDownloads(result);
for (const software of ['chromium', 'ffmpeg', 'firefox', 'webkit'])
expect(dls).toContainEqual({ status: 200, name: software, url: expect.stringContaining(cdn) });
await exec('node sanity.js playwright');
await exec('node sanity.js playwright chromium firefox webkit');
if (nodeMajorVersion >= 14)
await exec('node esm-playwright.mjs');
const stdio = await exec('npx playwright', 'test', '-c', '.', { expectToExitWithError: true });

Просмотреть файл

@ -21,7 +21,8 @@ test(`playwright cdn should race with a timeout`, async ({ exec }) => {
const server = http.createServer(() => {});
await new Promise<void>(resolve => server.listen(0, resolve));
try {
const result = await exec('npm i --foreground-scripts playwright', {
await exec('npm i --foreground-scripts playwright');
const result = await exec('npx playwright install', {
env: {
PLAYWRIGHT_DOWNLOAD_HOST: `http://127.0.0.1:${(server.address() as AddressInfo).port}`,
DEBUG: 'pw:install',

Просмотреть файл

@ -17,6 +17,7 @@ import { test, expect } from './npmTest';
test('codegen should work', async ({ exec }) => {
await exec('npm i --foreground-scripts playwright');
await exec('npx playwright install chromium');
await test.step('codegen without arguments', async () => {
const result = await exec('npx playwright codegen', {

Просмотреть файл

@ -16,7 +16,7 @@
import { test, expect } from './npmTest';
test('codegen should print the right install command without browsers', async ({ exec }) => {
await exec('npm i --foreground-scripts playwright', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
await exec('npm i --foreground-scripts playwright');
const pwLangName2InstallCommand = {
'java': 'mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="install"',

Просмотреть файл

@ -15,7 +15,7 @@
*/
import { test, expect } from './npmTest';
test('codegen should work', async ({ exec, installedSoftwareOnDisk }) => {
test('install command should work', async ({ exec, installedSoftwareOnDisk }) => {
await exec('npm i --foreground-scripts playwright', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
await test.step('playwright install chromium', async () => {
@ -30,12 +30,12 @@ test('codegen should work', async ({ exec, installedSoftwareOnDisk }) => {
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
});
await exec('node sanity.js playwright none', { env: { PLAYWRIGHT_BROWSERS_PATH: undefined } });
await exec('node sanity.js playwright');
await exec('node sanity.js playwright', { env: { PLAYWRIGHT_BROWSERS_PATH: undefined } });
await exec('node sanity.js playwright chromium firefox webkit');
});
test('should be able to remove browsers', async ({ exec, installedSoftwareOnDisk }) => {
await exec('npm i --foreground-scripts playwright', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
await exec('npm i --foreground-scripts playwright');
await exec('npx playwright install chromium');
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg']);
await exec('npx playwright uninstall');

Просмотреть файл

@ -19,6 +19,7 @@ import path from 'path';
test('playwright cli screenshot should work', async ({ exec, tmpWorkspace }) => {
await exec('npm i --foreground-scripts playwright');
await exec('npx playwright install chromium');
await exec(path.join('node_modules', '.bin', 'playwright'), 'screenshot about:blank one.png');
await fs.promises.stat(path.join(tmpWorkspace, 'one.png'));

Просмотреть файл

@ -16,6 +16,6 @@
import { test } from './npmTest';
test('electron should work', async ({ exec }) => {
await exec('npm i --foreground-scripts playwright electron@9.0', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
await exec('npm i --foreground-scripts playwright electron@19.0.11');
await exec('node sanity-electron.js');
});

Просмотреть файл

@ -19,10 +19,10 @@ test('global installation cross package', async ({ exec, installedSoftwareOnDisk
const packages = ['playwright-chromium', 'playwright-firefox', 'playwright-webkit'];
for (const pkg of packages)
await exec('npm i --foreground-scripts', pkg, { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
const result = await exec('npm i --foreground-scripts playwright');
const result = await exec('npx playwright install');
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
for (const pkg of packages)
await test.step(pkg, () => exec('node sanity.js', pkg, 'all'));
await test.step(pkg, () => exec('node sanity.js', pkg, 'chromium firefox webkit'));
});

Просмотреть файл

@ -16,9 +16,14 @@
import { test, expect } from './npmTest';
test('global installation', async ({ exec, installedSoftwareOnDisk }) => {
const result = await exec('npm i --foreground-scripts playwright');
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
const result1 = await exec('npm i --foreground-scripts playwright');
expect(result1).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
const result2 = await exec('npx playwright install');
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
await exec('node sanity.js playwright none', { env: { PLAYWRIGHT_BROWSERS_PATH: undefined } });
await exec('node sanity.js playwright');
await exec('node sanity.js playwright', { env: { PLAYWRIGHT_BROWSERS_PATH: undefined } });
await exec('node sanity.js playwright chromium firefox webkit');
});

Просмотреть файл

@ -18,11 +18,11 @@ import path from 'path';
test('subsequent installs works', async ({ exec }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/1651' });
await exec('npm i --foreground-scripts playwright');
await exec('npm i --foreground-scripts @playwright/browser-chromium');
// Note: the `npm install` would not actually crash, the error
// is merely logged to the console. To reproduce the error, we should make
// sure that script's install.js can be run subsequently without unhandled promise rejections.
// Note: the flag `--unhandled-rejections=strict` will force node to terminate in case
// of UnhandledPromiseRejection.
await exec('node --unhandled-rejections=strict', path.join('node_modules', 'playwright', 'install.js'));
await exec('node --unhandled-rejections=strict', path.join('node_modules', '@playwright', 'browser-chromium', 'install.js'));
});

Просмотреть файл

@ -21,5 +21,6 @@ test('playwright should work with relative home path', async ({ exec, tmpWorkspa
await fs.promises.mkdir(path.join(tmpWorkspace, 'foo'));
// Make sure that browsers path is resolved relative to the `npm install` call location.
await exec('npm i --foreground-scripts playwright', { cwd: path.join(tmpWorkspace, 'foo'), env: { PLAYWRIGHT_BROWSERS_PATH: path.join('..', 'relative') } });
await exec('node sanity.js playwright', { env: { PLAYWRIGHT_BROWSERS_PATH: path.join('.', 'relative') } });
await exec('npx playwright install', { cwd: path.join(tmpWorkspace, 'foo'), env: { PLAYWRIGHT_BROWSERS_PATH: path.join('..', 'relative') } });
await exec('node sanity.js playwright chromium firefox webkit', { env: { PLAYWRIGHT_BROWSERS_PATH: path.join('.', 'relative') } });
});

Просмотреть файл

@ -20,7 +20,7 @@ test('playwright should work with relative home path', async ({ exec }) => {
test.skip(os.platform().startsWith('win'));
const env = { PLAYWRIGHT_BROWSERS_PATH: '0', HOME: '.' };
await exec('npm i --foreground-scripts playwright', { env });
await exec('npm i --foreground-scripts playwright @playwright/browser-chromium @playwright/browser-webkit', { env });
// Firefox does not work with relative HOME.
await exec('node sanity.js playwright chromium webkit', { env });
});

Просмотреть файл

@ -16,10 +16,15 @@
import { test, expect } from './npmTest';
test(`playwright should work`, async ({ exec, nodeMajorVersion, installedSoftwareOnDisk }) => {
const result = await exec('npm i --foreground-scripts playwright');
expect(result).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
const result1 = await exec('npm i --foreground-scripts playwright');
expect(result1).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
const result2 = await exec('npm i --foreground-scripts @playwright/browser-chromium @playwright/browser-firefox @playwright/browser-webkit');
expect(result2).toHaveLoggedSoftwareDownload(['chromium', 'ffmpeg', 'firefox', 'webkit']);
expect(await installedSoftwareOnDisk()).toEqual(['chromium', 'ffmpeg', 'firefox', 'webkit']);
await exec('node sanity.js playwright');
await exec('node sanity.js playwright chromium firefox webkit');
if (nodeMajorVersion >= 14)
await exec('node esm-playwright.mjs');
const stdio = await exec('npx playwright', 'test', '-c', '.', { expectToExitWithError: true });

Просмотреть файл

@ -23,7 +23,7 @@ test('@playwright/test should work', async ({ exec, nodeMajorVersion, tmpWorkspa
await exec('npx playwright install');
await exec('npx playwright test -c . --browser=all --reporter=list,json sample.spec.js', { env: { PLAYWRIGHT_JSON_OUTPUT_NAME: 'report.json' } });
await exec('node read-json-report.js', path.join(tmpWorkspace, 'report.json'));
await exec('node sanity.js @playwright/test');
await exec('node sanity.js @playwright/test chromium firefox webkit');
if (nodeMajorVersion >= 14)
await exec('node', 'esm-playwright-test.mjs');
});

Просмотреть файл

@ -16,8 +16,9 @@
*/
import { test, expect } from './npmTest';
for (const pkg of ['playwright-chromium', 'playwright-firefox', 'playwright-webkit']) {
test(`${pkg} should work`, async ({ exec, nodeMajorVersion, installedSoftwareOnDisk }) => {
for (const browser of ['chromium', 'firefox', 'webkit']) {
test(`playwright-${browser} should work`, async ({ exec, nodeMajorVersion, installedSoftwareOnDisk }) => {
const pkg = `playwright-${browser}`;
const result = await exec('npm i --foreground-scripts', pkg);
const browserName = pkg.split('-')[1];
const expectedSoftware = [browserName];
@ -26,8 +27,29 @@ for (const pkg of ['playwright-chromium', 'playwright-firefox', 'playwright-webk
expect(result).toHaveLoggedSoftwareDownload(expectedSoftware as any);
expect(await installedSoftwareOnDisk()).toEqual(expectedSoftware);
expect(result).not.toContain(`To avoid unexpected behavior, please install your dependencies first`);
await exec('node sanity.js', pkg);
await exec('node sanity.js', pkg, browser);
if (nodeMajorVersion >= 14)
await exec('node', `esm-${pkg}.mjs`);
});
}
for (const browser of ['chromium', 'firefox', 'webkit']) {
test(`@playwright/browser-${browser} should work`, async ({ exec, installedSoftwareOnDisk }) => {
const pkg = `@playwright/browser-${browser}`;
const expectedSoftware = [browser];
if (browser === 'chromium')
expectedSoftware.push('ffmpeg');
const result1 = await exec('npm i --foreground-scripts', pkg);
expect(result1).toHaveLoggedSoftwareDownload(expectedSoftware as any);
expect(await installedSoftwareOnDisk()).toEqual(expectedSoftware);
expect(result1).not.toContain(`To avoid unexpected behavior, please install your dependencies first`);
const result2 = await exec('npm i --foreground-scripts playwright');
expect(result2).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual(expectedSoftware);
await exec('node sanity.js playwright', browser);
await exec('node browser-only.js', pkg);
});
}

Просмотреть файл

@ -16,8 +16,8 @@
import { test } from './npmTest';
test('screencast works', async ({ exec }) => {
const packages = ['playwright', 'playwright-chromium', 'playwright-firefox', 'playwright-webkit'];
await exec('npm i --foreground-scripts', ...packages);
for (const pkg of packages)
await test.step(pkg, () => exec('node screencast.js', pkg));
await exec('npm i --foreground-scripts', 'playwright', 'playwright-chromium', 'playwright-firefox', 'playwright-webkit');
await test.step('playwright', () => exec('node screencast.js playwright chromium firefox webkit'));
for (const browser of ['chromium', 'firefox', 'webkit'])
await test.step(browser, () => exec(`node screencast.js playwright-${browser} ${browser}`));
});

Просмотреть файл

@ -16,7 +16,7 @@
import { test, expect } from './npmTest';
test('should skip download', async ({ exec }) => {
const installOutput = await exec('npm i --foreground-scripts playwright', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
const installOutput = await exec('npm i --foreground-scripts playwright @playwright/browser-chromium', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
expect(installOutput).toContain('Skipping browsers download because');
if (process.platform === 'linux') {
const output = await exec('node inspector-custom-executable.js', { env: { PWDEBUG: '1' } });

Просмотреть файл

@ -16,7 +16,7 @@
import { test, expect } from './npmTest';
test('PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD should skip browser installs', async ({ exec, installedSoftwareOnDisk }) => {
const result = await exec('npm i --foreground-scripts playwright', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
const result = await exec('npm i --foreground-scripts @playwright/browser-firefox', { env: { PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' } });
expect(result).toHaveLoggedSoftwareDownload([]);
expect(await installedSoftwareOnDisk()).toEqual([]);
expect(result).toContain(`Skipping browsers download because`);

Просмотреть файл

@ -18,12 +18,14 @@ import { test, expect } from './npmTest';
test.describe('validate dependencies', () => {
test('default (on)', async ({ exec }) => {
await exec('npm i --foreground-scripts playwright');
await exec('npx playwright install chromium');
const result = await exec('node validate-dependencies.js');
expect(result).toContain(`PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS`);
});
test('disabled (off)', async ({ exec }) => {
await exec('npm i --foreground-scripts playwright');
await exec('npx playwright install chromium');
const result = await exec('node validate-dependencies-skip-executable-path.js');
expect(result).not.toContain(`PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS`);
});

Просмотреть файл

@ -178,6 +178,21 @@ const workspace = new Workspace(ROOT_PATH, [
path: path.join(ROOT_PATH, 'packages', 'playwright-chromium'),
files: LICENCE_FILES,
}),
new PWPackage({
name: '@playwright/browser-webkit',
path: path.join(ROOT_PATH, 'packages', 'playwright-browser-webkit'),
files: LICENCE_FILES,
}),
new PWPackage({
name: '@playwright/browser-firefox',
path: path.join(ROOT_PATH, 'packages', 'playwright-browser-firefox'),
files: LICENCE_FILES,
}),
new PWPackage({
name: '@playwright/browser-chromium',
path: path.join(ROOT_PATH, 'packages', 'playwright-browser-chromium'),
files: LICENCE_FILES,
}),
new PWPackage({
name: '@playwright/experimental-ct-core',
path: path.join(ROOT_PATH, 'packages', 'playwright-ct-core'),