Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

api: export all browsers from every package (#3128)

Dmitry Gozmanfd2e65b73cf9
diff --git a/browsers.json b/browsers.json
index 46b0ad902b..8db931095c 100644
--- a/browsers.json
+++ b/browsers.json
@@ -3,15 +3,18 @@
"browsers": [
{
"name": "chromium",
- "revision": "791201"
+ "revision": "791201",
+ "download": true
},
{
"name": "firefox",
- "revision": "1140"
+ "revision": "1140",
+ "download": true
},
{
"name": "webkit",
- "revision": "1317"
+ "revision": "1317",
+ "download": true
}
]
}
diff --git a/packages/.gitignore b/packages/.gitignore
new file mode 100644
index 0000000000..53752db253
--- /dev/null
+++ b/packages/.gitignore
@@ -0,0 +1 @@
+output
diff --git a/packages/build_package.js b/packages/build_package.js
index 9c9359fcdb..f5f4df6e38 100755
--- a/packages/build_package.js
+++ b/packages/build_package.js
@@ -64,8 +64,6 @@ const PACKAGES = {
},
};
-const cleanupPaths = [];
-
// 1. Parse CLI arguments
const args = process.argv.slice(2);
if (args.some(arg => arg === '--help')) {
@@ -81,10 +79,19 @@ if (args.some(arg => arg === '--help')) {
process.exit(1);
}
+const packageName = args[0];
+const outputPath = path.resolve(args[1]);
+const packagePath = path.join(__dirname, 'output', packageName);
+const package = PACKAGES[packageName];
+if (!package) {
+ console.log(`ERROR: unknown package ${packageName}`);
+ process.exit(1);
+}
+
// 2. Setup cleanup if needed
if (!args.some(arg => arg === '--no-cleanup')) {
process.on('exit', () => {
- cleanupPaths.forEach(cleanupPath => rmSync(cleanupPath, {}));
+ rmSync(packagePath, {});
});
process.on('SIGINT', () => process.exit(2));
process.on('SIGHUP', () => process.exit(3));
@@ -99,19 +106,17 @@ if (!args.some(arg => arg === '--no-cleanup')) {
});
}
-const packageName = args[0];
-const outputPath = path.resolve(args[1]);
-const packagePath = path.join(__dirname, packageName);
-const package = PACKAGES[packageName];
-if (!package) {
- console.log(`ERROR: unknown package ${packageName}`);
- process.exit(1);
-}
-
(async () => {
// 3. Copy package files.
+ rmSync(packagePath, {});
+ fs.mkdirSync(packagePath, { recursive: true });
+ await copyToPackage(path.join(__dirname, 'common') + path.sep, packagePath + path.sep);
+ if (fs.existsSync(path.join(__dirname, packageName))) {
+ // Copy package-specific files, these can overwrite common ones.
+ await copyToPackage(path.join(__dirname, packageName) + path.sep, packagePath + path.sep);
+ }
for (const file of package.files)
- await copyToPackage(file);
+ await copyToPackage(path.join(ROOT_PATH, file), path.join(packagePath, file));
// 4. Generate package.json
const pwInternalJSON = require(path.join(ROOT_PATH, 'package.json'));
@@ -144,7 +149,8 @@ if (!package) {
// 5. Generate browsers.json
const browsersJSON = require(path.join(ROOT_PATH, 'browsers.json'));
- browsersJSON.browsers = browsersJSON.browsers.filter(browser => package.browsers.includes(browser.name));
+ for (const browser of browsersJSON.browsers)
+ browser.download = package.browsers.includes(browser.name);
await writeToPackage('browsers.json', JSON.stringify(browsersJSON, null, 2));
// 6. Run npm pack
@@ -163,15 +169,11 @@ if (!package) {
async function writeToPackage(fileName, content) {
const toPath = path.join(packagePath, fileName);
- cleanupPaths.push(toPath);
console.error(`- generating: //${path.relative(ROOT_PATH, toPath)}`);
await writeFileAsync(toPath, content);
}
-async function copyToPackage(fileOrDirectoryName) {
- const fromPath = path.join(ROOT_PATH, fileOrDirectoryName);
- const toPath = path.join(packagePath, fileOrDirectoryName);
- cleanupPaths.push(toPath);
+async function copyToPackage(fromPath, toPath) {
console.error(`- copying: //${path.relative(ROOT_PATH, fromPath)} -> //${path.relative(ROOT_PATH, toPath)}`);
await cpAsync(fromPath, toPath);
}
diff --git a/packages/playwright-core/index.d.ts b/packages/common/index.d.ts
similarity index 100%
rename from packages/playwright-core/index.d.ts
rename to packages/common/index.d.ts
index 4e7b270a07..c90fa88e79 100644
--- a/packages/playwright-core/index.d.ts
+++ b/packages/common/index.d.ts
@@ -17,6 +17,6 @@
import * as types from './types/types';
export * from './types/types';
-export const webkit: types.BrowserType<types.WebKitBrowser>;
export const chromium: types.BrowserType<types.ChromiumBrowser>;
export const firefox: types.BrowserType<types.FirefoxBrowser>;
+export const webkit: types.BrowserType<types.WebKitBrowser>;
diff --git a/packages/playwright-chromium/index.js b/packages/common/index.js
similarity index 100%
rename from packages/playwright-chromium/index.js
rename to packages/common/index.js
diff --git a/packages/playwright-core/index.mjs b/packages/common/index.mjs
similarity index 100%
rename from packages/playwright-core/index.mjs
rename to packages/common/index.mjs
diff --git a/packages/playwright-chromium/install.js b/packages/common/install.js
similarity index 100%
rename from packages/playwright-chromium/install.js
rename to packages/common/install.js
diff --git a/packages/installation-tests/esm-playwright-chromium.mjs b/packages/installation-tests/esm-playwright-chromium.mjs
index 0e2f6fd4e3..a68fed8b76 100644
--- a/packages/installation-tests/esm-playwright-chromium.mjs
+++ b/packages/installation-tests/esm-playwright-chromium.mjs
@@ -14,28 +14,9 @@
* limitations under the License.
*/
-import { chromium, selectors, devices, errors } from 'playwright-chromium';
+import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright-chromium';
import playwright from 'playwright-chromium';
import errorsFile from 'playwright-chromium/lib/errors.js';
-if (playwright.chromium !== chromium)
- process.exit(1);
-
-if (playwright.errors !== errors)
- process.exit(1);
-if (errors.TimeoutError !== errorsFile.TimeoutError)
- process.exit(1);
-
-(async () => {
- for (const browserType of [chromium]) {
- const browser = await browserType.launch();
- const context = await browser.newContext();
- const page = await context.newPage();
- await page.evaluate(() => navigator.userAgent);
- await browser.close();
- }
- console.log(`esm SUCCESS`);
-})().catch(err => {
- console.error(err);
- process.exit(1);
-});
+import testESM from './esm.mjs';
+testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [chromium]);
diff --git a/packages/installation-tests/esm-playwright-firefox.mjs b/packages/installation-tests/esm-playwright-firefox.mjs
index d3854688f9..74758eec9a 100644
--- a/packages/installation-tests/esm-playwright-firefox.mjs
+++ b/packages/installation-tests/esm-playwright-firefox.mjs
@@ -14,28 +14,9 @@
* limitations under the License.
*/
-import { firefox, selectors, devices, errors } from 'playwright-firefox';
+import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright-firefox';
import playwright from 'playwright-firefox';
import errorsFile from 'playwright-firefox/lib/errors.js';
-if (playwright.firefox !== firefox)
- process.exit(1);
-
-if (playwright.errors !== errors)
- process.exit(1);
-if (errors.TimeoutError !== errorsFile.TimeoutError)
- process.exit(1);
-
-(async () => {
- for (const browserType of [firefox]) {
- const browser = await browserType.launch();
- const context = await browser.newContext();
- const page = await context.newPage();
- await page.evaluate(() => navigator.userAgent);
- await browser.close();
- }
- console.log(`esm SUCCESS`);
-})().catch(err => {
- console.error(err);
- process.exit(1);
-});
+import testESM from './esm.mjs';
+testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [firefox]);
diff --git a/packages/installation-tests/esm-playwright-webkit.mjs b/packages/installation-tests/esm-playwright-webkit.mjs
index dba784d3c6..444c55c0f7 100644
--- a/packages/installation-tests/esm-playwright-webkit.mjs
+++ b/packages/installation-tests/esm-playwright-webkit.mjs
@@ -14,28 +14,9 @@
* limitations under the License.
*/
-import { webkit, selectors, devices, errors } from 'playwright-webkit';
+import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright-webkit';
import playwright from 'playwright-webkit';
import errorsFile from 'playwright-webkit/lib/errors.js';
-if (playwright.webkit !== webkit)
- process.exit(1);
-
-if (playwright.errors !== errors)
- process.exit(1);
-if (errors.TimeoutError !== errorsFile.TimeoutError)
- process.exit(1);
-
-(async () => {
- for (const browserType of [webkit]) {
- const browser = await browserType.launch();
- const context = await browser.newContext();
- const page = await context.newPage();
- await page.evaluate(() => navigator.userAgent);
- await browser.close();
- }
- console.log(`esm SUCCESS`);
-})().catch(err => {
- console.error(err);
- process.exit(1);
-});
+import testESM from './esm.mjs';
+testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [webkit]);
diff --git a/packages/installation-tests/esm-playwright.mjs b/packages/installation-tests/esm-playwright.mjs
index 18be425d2f..1e1f5516ad 100644
--- a/packages/installation-tests/esm-playwright.mjs
+++ b/packages/installation-tests/esm-playwright.mjs
@@ -18,28 +18,5 @@ import { chromium, firefox, webkit, selectors, devices, errors } from 'playwrigh
import playwright from 'playwright';
import errorsFile from 'playwright/lib/errors.js';
-if (playwright.chromium !== chromium)
- process.exit(1);
-if (playwright.firefox !== firefox)
- process.exit(1);
-if (playwright.webkit !== webkit)
- process.exit(1);
-
-if (playwright.errors !== errors)
- process.exit(1);
-if (errors.TimeoutError !== errorsFile.TimeoutError)
- process.exit(1);
-
-(async () => {
- for (const browserType of [chromium, firefox, webkit]) {
- const browser = await browserType.launch();
- const context = await browser.newContext();
- const page = await context.newPage();
- await page.evaluate(() => navigator.userAgent);
- await browser.close();
- }
- console.log(`esm SUCCESS`);
-})().catch(err => {
- console.error(err);
- process.exit(1);
-});
+import testESM from './esm.mjs';
+testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [chromium, firefox, webkit]);
diff --git a/packages/installation-tests/esm.mjs b/packages/installation-tests/esm.mjs
new file mode 100644
index 0000000000..2ae1ece1d2
--- /dev/null
+++ b/packages/installation-tests/esm.mjs
@@ -0,0 +1,42 @@
+/**
+ * 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 default async function testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, browsers) {
+ if (playwright.chromium !== chromium)
+ process.exit(1);
+ if (playwright.firefox !== firefox)
+ process.exit(1);
+ if (playwright.webkit !== webkit)
+ process.exit(1);
+ if (playwright.errors !== errors)
+ process.exit(1);
+ if (errors.TimeoutError !== errorsFile.TimeoutError)
+ process.exit(1);
+
+ try {
+ for (const browserType of browsers) {
+ const browser = await browserType.launch();
+ const context = await browser.newContext();
+ const page = await context.newPage();
+ await page.evaluate(() => navigator.userAgent);
+ await browser.close();
+ }
+ console.log(`esm SUCCESS`);
+ } catch (err) {
+ console.error(err);
+ process.exit(1);
+ }
+}
diff --git a/packages/installation-tests/installation-tests.sh b/packages/installation-tests/installation-tests.sh
index fe13886bd6..570748470f 100755
--- a/packages/installation-tests/installation-tests.sh
+++ b/packages/installation-tests/installation-tests.sh
@@ -28,6 +28,7 @@ NODE_VERSION="$(node --version)"
function copy_test_scripts {
cp "${SCRIPTS_PATH}/sanity.js" .
+ cp "${SCRIPTS_PATH}/esm.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright-chromium.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright-firefox.mjs" .
@@ -43,6 +44,7 @@ function run_tests {
test_playwright_webkit_should_work
test_playwright_firefox_should_work
test_playwright_global_installation
+ test_playwright_global_installation_cross_package
}
function test_typescript_types {
@@ -77,13 +79,31 @@ function test_playwright_global_installation {
exit 1
fi
copy_test_scripts
- if node sanity.js playwright chromium 2>/dev/null; then
- echo "Should not be able to launch chromium without PLAYWRIGHT_BROWSERS_PATH variable!"
+ node sanity.js playwright none
+ PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright
+}
+
+function test_playwright_global_installation_cross_package {
+ initialize_test "${FUNCNAME[0]}"
+
+ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_FIREFOX_TGZ}
+ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_WEBKIT_TGZ}
+ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_CHROMIUM_TGZ}
+
+ local BROWSERS="$(pwd -P)/browsers"
+ PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_TGZ}
+ if [[ ! -d "${BROWSERS}" ]]; then
+ echo "Directory for shared browsers was not created!"
exit 1
fi
- PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright chromium
-}
+ copy_test_scripts
+
+ # Every package should be able to launch.
+ PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright-chromium all
+ PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright-firefox all
+ PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright-webkit all
+}
# @see https://github.com/microsoft/playwright/issues/1651
function test_playwright_global_installation_subsequent_installs {
@@ -119,9 +139,21 @@ function test_skip_browser_download {
function test_playwright_should_work {
initialize_test "${FUNCNAME[0]}"
- npm install ${PLAYWRIGHT_TGZ}
+ OUTPUT=$(npm install ${PLAYWRIGHT_TGZ})
+ if [[ "${OUTPUT}" != *"chromium"* ]]; then
+ echo "ERROR: should download chromium"
+ exit 1
+ fi
+ if [[ "${OUTPUT}" != *"firefox"* ]]; then
+ echo "ERROR: should download firefox"
+ exit 1
+ fi
+ if [[ "${OUTPUT}" != *"webkit"* ]]; then
+ echo "ERROR: should download webkit"
+ exit 1
+ fi
copy_test_scripts
- node sanity.js playwright chromium firefox webkit
+ node sanity.js playwright
if [[ "${NODE_VERSION}" == *"v14."* ]]; then
node esm-playwright.mjs
fi
@@ -130,9 +162,21 @@ function test_playwright_should_work {
function test_playwright_chromium_should_work {
initialize_test "${FUNCNAME[0]}"
- npm install ${PLAYWRIGHT_CHROMIUM_TGZ}
+ OUTPUT=$(npm install ${PLAYWRIGHT_CHROMIUM_TGZ})
+ if [[ "${OUTPUT}" != *"chromium"* ]]; then
+ echo "ERROR: should download chromium"
+ exit 1
+ fi
+ if [[ "${OUTPUT}" == *"firefox"* ]]; then
+ echo "ERROR: should not download firefox"
+ exit 1
+ fi
+ if [[ "${OUTPUT}" == *"webkit"* ]]; then
+ echo "ERROR: should not download webkit"
+ exit 1
+ fi
copy_test_scripts
- node sanity.js playwright-chromium chromium
+ node sanity.js playwright-chromium
if [[ "${NODE_VERSION}" == *"v14."* ]]; then
node esm-playwright-chromium.mjs
fi
@@ -141,9 +185,21 @@ function test_playwright_chromium_should_work {
function test_playwright_webkit_should_work {
initialize_test "${FUNCNAME[0]}"
- npm install ${PLAYWRIGHT_WEBKIT_TGZ}
+ OUTPUT=$(npm install ${PLAYWRIGHT_WEBKIT_TGZ})
+ if [[ "${OUTPUT}" == *"chromium"* ]]; then
+ echo "ERROR: should not download chromium"
+ exit 1
+ fi
+ if [[ "${OUTPUT}" == *"firefox"* ]]; then
+ echo "ERROR: should not download firefox"
+ exit 1
+ fi
+ if [[ "${OUTPUT}" != *"webkit"* ]]; then
+ echo "ERROR: should download webkit"
+ exit 1
+ fi
copy_test_scripts
- node sanity.js playwright-webkit webkit
+ node sanity.js playwright-webkit
if [[ "${NODE_VERSION}" == *"v14."* ]]; then
node esm-playwright-webkit.mjs
fi
@@ -152,9 +208,21 @@ function test_playwright_webkit_should_work {
function test_playwright_firefox_should_work {
initialize_test "${FUNCNAME[0]}"
- npm install ${PLAYWRIGHT_FIREFOX_TGZ}
+ OUTPUT=$(npm install ${PLAYWRIGHT_FIREFOX_TGZ})
+ if [[ "${OUTPUT}" == *"chromium"* ]]; then
+ echo "ERROR: should not download chromium"
+ exit 1
+ fi
+ if [[ "${OUTPUT}" != *"firefox"* ]]; then
+ echo "ERROR: should download firefox"
+ exit 1
+ fi
+ if [[ "${OUTPUT}" == *"webkit"* ]]; then
+ echo "ERROR: should not download webkit"
+ exit 1
+ fi
copy_test_scripts
- node sanity.js playwright-firefox firefox
+ node sanity.js playwright-firefox
if [[ "${NODE_VERSION}" == *"v14."* ]]; then
node esm-playwright-firefox.mjs
fi
diff --git a/packages/installation-tests/sanity.js b/packages/installation-tests/sanity.js
index 4ff42fbadc..3b414dfadc 100644
--- a/packages/installation-tests/sanity.js
+++ b/packages/installation-tests/sanity.js
@@ -15,7 +15,16 @@
*/
const requireName = process.argv[2];
-const browsers = process.argv.slice(3);
+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 playwright = require(requireName);
@@ -24,12 +33,28 @@ const errors = require(requireName + '/lib/errors');
const installer = require(requireName + '/lib/install/installer');
(async () => {
- for (const browserType of browsers) {
- const browser = await playwright[browserType].launch();
- const context = await browser.newContext();
- const page = await context.newPage();
- await page.evaluate(() => navigator.userAgent);
- await browser.close();
+ for (const browserType of success) {
+ try {
+ const browser = await playwright[browserType].launch();
+ const context = await browser.newContext();
+ const page = await context.newPage();
+ await page.evaluate(() => navigator.userAgent);
+ await browser.close();
+ } catch (e) {
+ console.error(`Should be able to launch ${browserType} from ${requireName}`);
+ console.error(err);
+ process.exit(1);
+ }
+ }
+ const fail = ['chromium', 'webkit', 'firefox'].filter(x => !success.includes(x));
+ for (const browserType of fail) {
+ try {
+ await playwright[browserType].launch();
+ console.error(`Should not be able to launch ${browserType} from ${requireName}`);
+ process.exit(1);
+ } catch (e) {
+ // All good.
+ }
}
console.log(`require SUCCESS`);
})().catch(err => {
diff --git a/packages/playwright-chromium/index.d.ts b/packages/playwright-chromium/index.d.ts
deleted file mode 100644
index a5d8a610be..0000000000
--- a/packages/playwright-chromium/index.d.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * 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.
- */
-
-import * as types from './types/types';
-
-export * from './types/types';
-export const chromium: types.BrowserType<types.ChromiumBrowser>;
diff --git a/packages/playwright-chromium/index.mjs b/packages/playwright-chromium/index.mjs
deleted file mode 100644
index 8365d8453b..0000000000
--- a/packages/playwright-chromium/index.mjs
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-
-import playwright from './index.js';
-
-export const chromium = playwright.chromium;
-export const selectors = playwright.selectors;
-export const devices = playwright.devices;
-export const errors = playwright.errors;
-export default playwright;
diff --git a/packages/playwright-core/index.js b/packages/playwright-core/index.js
deleted file mode 100644
index bcc6ecaa3d..0000000000
--- a/packages/playwright-core/index.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * 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 { Playwright } = require('./lib/server/playwright');
-
-module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);
diff --git a/packages/playwright-core/install.js b/packages/playwright-core/install.js
deleted file mode 100644
index 955ab6083e..0000000000
--- a/packages/playwright-core/install.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * 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.
- */
-
-/* NOTE: playwright-core does not install browsers by design. */
diff --git a/packages/playwright-firefox/index.d.ts b/packages/playwright-firefox/index.d.ts
deleted file mode 100644
index dc34fe5d12..0000000000
--- a/packages/playwright-firefox/index.d.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * 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.
- */
-
-import * as types from './types/types';
-
-export * from './types/types';
-export const firefox: types.BrowserType<types.FirefoxBrowser>;
diff --git a/packages/playwright-firefox/index.js b/packages/playwright-firefox/index.js
deleted file mode 100644
index bcc6ecaa3d..0000000000
--- a/packages/playwright-firefox/index.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * 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 { Playwright } = require('./lib/server/playwright');
-
-module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);
diff --git a/packages/playwright-firefox/index.mjs b/packages/playwright-firefox/index.mjs
deleted file mode 100644
index 824f5c8af8..0000000000
--- a/packages/playwright-firefox/index.mjs
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-
-import playwright from './index.js';
-
-export const firefox = playwright.firefox;
-export const selectors = playwright.selectors;
-export const devices = playwright.devices;
-export const errors = playwright.errors;
-export default playwright;
diff --git a/packages/playwright-firefox/install.js b/packages/playwright-firefox/install.js
deleted file mode 100644
index 13c8ccee30..0000000000
--- a/packages/playwright-firefox/install.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * 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 { installBrowsersWithProgressBar } = require('./lib/install/installer');
-
-installBrowsersWithProgressBar(__dirname);
diff --git a/packages/playwright-webkit/index.d.ts b/packages/playwright-webkit/index.d.ts
deleted file mode 100644
index 6da7c60d11..0000000000
--- a/packages/playwright-webkit/index.d.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * 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.
- */
-
-import * as types from './types/types';
-
-export * from './types/types';
-export const webkit: types.BrowserType<types.WebKitBrowser>;
diff --git a/packages/playwright-webkit/index.js b/packages/playwright-webkit/index.js
deleted file mode 100644
index bcc6ecaa3d..0000000000
--- a/packages/playwright-webkit/index.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * 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 { Playwright } = require('./lib/server/playwright');
-
-module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);
diff --git a/packages/playwright-webkit/index.mjs b/packages/playwright-webkit/index.mjs
deleted file mode 100644
index 5f44947f37..0000000000
--- a/packages/playwright-webkit/index.mjs
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.
- */
-
-import playwright from './index.js';
-
-export const webkit = playwright.webkit;
-export const selectors = playwright.selectors;
-export const devices = playwright.devices;
-export const errors = playwright.errors;
-export default playwright;
diff --git a/packages/playwright-webkit/install.js b/packages/playwright-webkit/install.js
deleted file mode 100644
index 13c8ccee30..0000000000
--- a/packages/playwright-webkit/install.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * 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 { installBrowsersWithProgressBar } = require('./lib/install/installer');
-
-installBrowsersWithProgressBar(__dirname);
diff --git a/packages/playwright/index.d.ts b/packages/playwright/index.d.ts
deleted file mode 100644
index 4e7b270a07..0000000000
--- a/packages/playwright/index.d.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * 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.
- */
-
-import * as types from './types/types';
-
-export * from './types/types';
-export const webkit: types.BrowserType<types.WebKitBrowser>;
-export const chromium: types.BrowserType<types.ChromiumBrowser>;
-export const firefox: types.BrowserType<types.FirefoxBrowser>;
diff --git a/packages/playwright/index.js b/packages/playwright/index.js
deleted file mode 100644
index bcc6ecaa3d..0000000000
--- a/packages/playwright/index.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * 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 { Playwright } = require('./lib/server/playwright');
-
-module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);
diff --git a/packages/playwright/index.mjs b/packages/playwright/index.mjs
deleted file mode 100644
index 337c589660..0000000000
--- a/packages/playwright/index.mjs
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * 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.
- */
-
-import playwright from './index.js';
-
-export const chromium = playwright.chromium;
-export const firefox = playwright.firefox;
-export const webkit = playwright.webkit;
-export const selectors = playwright.selectors;
-export const devices = playwright.devices;
-export const errors = playwright.errors;
-export default playwright;
diff --git a/packages/playwright/install.js b/packages/playwright/install.js
deleted file mode 100644
index 13c8ccee30..0000000000
--- a/packages/playwright/install.js
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * 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 { installBrowsersWithProgressBar } = require('./lib/install/installer');
-
-installBrowsersWithProgressBar(__dirname);
diff --git a/src/install/browserFetcher.ts b/src/install/browserFetcher.ts
index 024ea35b5d..75ac4fae09 100644
--- a/src/install/browserFetcher.ts
+++ b/src/install/browserFetcher.ts
@@ -122,7 +122,8 @@ function revisionURL(browser: BrowserDescriptor, platform = browserPaths.hostPla
return util.format(urlTemplate, serverHost, browser.revision);
}
-export async function downloadBrowserWithProgressBar(browserPath: string, browser: BrowserDescriptor): Promise<boolean> {
+export async function downloadBrowserWithProgressBar(browsersPath: string, browser: BrowserDescriptor): Promise<boolean> {
+ const browserPath = browserPaths.browserDirectory(browsersPath, browser);
const progressBarName = `${browser.name} v${browser.revision}`;
if (await existsAsync(browserPath)) {
// Already downloaded.
@@ -168,8 +169,8 @@ function toMegabytes(bytes: number) {
return `${Math.round(mb * 10) / 10} Mb`;
}
-export async function canDownload(browserName: BrowserName, browserRevision: string, platform: BrowserPlatform): Promise<boolean> {
- const url = revisionURL({ name: browserName, revision: browserRevision }, platform);
+export async function canDownload(browser: BrowserDescriptor, platform: BrowserPlatform): Promise<boolean> {
+ const url = revisionURL(browser, platform);
let resolve: (result: boolean) => void = () => {};
const promise = new Promise<boolean>(x => resolve = x);
const request = httpRequest(url, 'HEAD', response => {
diff --git a/src/install/browserPaths.ts b/src/install/browserPaths.ts
index 27eda3f185..03e6cb4531 100644
--- a/src/install/browserPaths.ts
+++ b/src/install/browserPaths.ts
@@ -24,7 +24,8 @@ export type BrowserName = 'chromium'|'webkit'|'firefox';
export type BrowserPlatform = 'win32'|'win64'|'mac10.13'|'mac10.14'|'mac10.15'|'ubuntu18.04'|'ubuntu20.04';
export type BrowserDescriptor = {
name: BrowserName,
- revision: string
+ revision: string,
+ download: boolean,
};
export const hostPlatform = ((): BrowserPlatform => {
diff --git a/src/install/installer.ts b/src/install/installer.ts
index 561e3cde23..df5d43cb6a 100644
--- a/src/install/installer.ts
+++ b/src/install/installer.ts
@@ -52,8 +52,8 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
let linkTarget = '';
try {
linkTarget = (await fsReadFileAsync(linkPath)).toString();
- const browsers = JSON.parse((await fsReadFileAsync(path.join(linkTarget, 'browsers.json'))).toString())['browsers'];
- for (const browser of browsers) {
+ const browsersToDownload = await readBrowsersToDownload(linkTarget);
+ for (const browser of browsersToDownload) {
const usedBrowserPath = browserPaths.browserDirectory(browsersPath, browser);
const browserRevision = parseInt(browser.revision, 10);
// Old browser installations don't have marker file.
@@ -82,14 +82,20 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
}
// 3. Install missing browsers for this package.
- const myBrowsers = JSON.parse((await fsReadFileAsync(path.join(packagePath, 'browsers.json'))).toString())['browsers'] as browserPaths.BrowserDescriptor[];
- for (const browser of myBrowsers) {
- const browserPath = browserPaths.browserDirectory(browsersPath, browser);
- await browserFetcher.downloadBrowserWithProgressBar(browserPath, browser);
+ const myBrowsersToDownload = await readBrowsersToDownload(packagePath);
+ for (const browser of myBrowsersToDownload) {
+ await browserFetcher.downloadBrowserWithProgressBar(browsersPath, browser);
await fsWriteFileAsync(browserPaths.markerFilePath(browsersPath, browser), '');
}
}
+async function readBrowsersToDownload(packagePath: string) {
+ const browsers = JSON.parse((await fsReadFileAsync(path.join(packagePath, 'browsers.json'))).toString())['browsers'] as browserPaths.BrowserDescriptor[];
+ // Older versions do not have "download" field. We assume they need all browsers
+ // from the list. So we want to skip all browsers that are explicitly marked as "download: false".
+ return browsers.filter(browser => browser.download !== false);
+}
+
function sha1(data: string): string {
const sum = crypto.createHash('sha1');
sum.update(data);
diff --git a/src/rpc/server/playwrightDispatcher.ts b/src/rpc/server/playwrightDispatcher.ts
index 2c0ebff6c3..1c7efdfacd 100644
--- a/src/rpc/server/playwrightDispatcher.ts
+++ b/src/rpc/server/playwrightDispatcher.ts
@@ -28,9 +28,9 @@ export class PlaywrightDispatcher extends Dispatcher<Playwright, PlaywrightIniti
const deviceDescriptors = Object.entries(playwright.devices)
.map(([name, descriptor]) => ({ name, descriptor }));
super(scope, playwright, 'Playwright', {
- chromium: new BrowserTypeDispatcher(scope, playwright.chromium!),
- firefox: new BrowserTypeDispatcher(scope, playwright.firefox!),
- webkit: new BrowserTypeDispatcher(scope, playwright.webkit!),
+ chromium: new BrowserTypeDispatcher(scope, playwright.chromium),
+ firefox: new BrowserTypeDispatcher(scope, playwright.firefox),
+ webkit: new BrowserTypeDispatcher(scope, playwright.webkit),
electron: electron ? new ElectronDispatcher(scope, electron) : undefined,
deviceDescriptors,
selectors: new SelectorsDispatcher(scope, playwright.selectors),
diff --git a/src/server/playwright.ts b/src/server/playwright.ts
index 9f506bf395..8050d226ce 100644
--- a/src/server/playwright.ts
+++ b/src/server/playwright.ts
@@ -34,24 +34,21 @@ export class Playwright {
readonly selectors = selectors;
readonly devices: types.Devices;
readonly errors: { TimeoutError: typeof TimeoutError };
- readonly chromium: (Chromium|undefined);
- readonly firefox: (Firefox|undefined);
- readonly webkit: (WebKit|undefined);
+ readonly chromium: Chromium;
+ readonly firefox: Firefox;
+ readonly webkit: WebKit;
constructor(packagePath: string, browsers: browserPaths.BrowserDescriptor[]) {
this.devices = DeviceDescriptors;
this.errors = { TimeoutError };
const chromium = browsers.find(browser => browser.name === 'chromium');
- if (chromium)
- this.chromium = new Chromium(packagePath, chromium);
+ this.chromium = new Chromium(packagePath, chromium!);
const firefox = browsers.find(browser => browser.name === 'firefox');
- if (firefox)
- this.firefox = new Firefox(packagePath, firefox);
+ this.firefox = new Firefox(packagePath, firefox!);
const webkit = browsers.find(browser => browser.name === 'webkit');
- if (webkit)
- this.webkit = new WebKit(packagePath, webkit);
+ this.webkit = new WebKit(packagePath, webkit!);
}
}
diff --git a/utils/check_availability.js b/utils/check_availability.js
index 02ff589acd..e82464649e 100755
--- a/utils/check_availability.js
+++ b/utils/check_availability.js
@@ -106,7 +106,7 @@ async function checkRangeAvailability(fromRevision, toRevision, stopWhenAllAvail
* @return {boolean}
*/
async function checkAndDrawRevisionAvailability(table, name, revision) {
- const promises = fetcherOptions.map(platform => browserFetcher.canDownload(name, revision, platform));
+ const promises = fetcherOptions.map(platform => browserFetcher.canDownload({ name, revision, download: true }, platform));
const availability = await Promise.all(promises);
const allAvailable = availability.every(e => !!e);
const values = [name + ' ' + (allAvailable ? colors.green + revision + colors.reset : revision)];