chore: update top-level api (#479)
```
require('playwright').chromium.launch(...)
window.playwrightweb.chromium.connect(...)
```
This commit is contained in:
parent
64560b1bfa
commit
b388722777
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -18,7 +18,6 @@ yarn.lock
|
||||||
/src/chromium/protocol.ts
|
/src/chromium/protocol.ts
|
||||||
/src/firefox/protocol.ts
|
/src/firefox/protocol.ts
|
||||||
/src/webkit/protocol.ts
|
/src/webkit/protocol.ts
|
||||||
/utils/browser/playwright-web.js
|
|
||||||
lib/
|
lib/
|
||||||
playwright-*.tgz
|
playwright-*.tgz
|
||||||
/web.js
|
/web.js
|
||||||
|
|
|
||||||
11
.npmignore
11
.npmignore
|
|
@ -9,7 +9,7 @@ lib/injected/
|
||||||
#types
|
#types
|
||||||
!lib/**/*.d.ts
|
!lib/**/*.d.ts
|
||||||
!index.d.ts
|
!index.d.ts
|
||||||
!web.d.ts
|
|
||||||
# Install
|
# Install
|
||||||
!install.js
|
!install.js
|
||||||
|
|
||||||
|
|
@ -18,12 +18,3 @@ lib/injected/
|
||||||
|
|
||||||
# root for "playwright/web"
|
# root for "playwright/web"
|
||||||
!web.js
|
!web.js
|
||||||
|
|
||||||
# specific browsers
|
|
||||||
!chromium.js
|
|
||||||
!firefox.js
|
|
||||||
!webkit.js
|
|
||||||
|
|
||||||
# dgozman says to remove these
|
|
||||||
!DeviceDescriptors.js
|
|
||||||
!Errors.js
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright 2019 Google Inc. All rights reserved.
|
|
||||||
* Modifications 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 {DeviceDescriptors} = require('./lib/deviceDescriptors');
|
|
||||||
|
|
||||||
module.exports = DeviceDescriptors;
|
|
||||||
17
Errors.js
17
Errors.js
|
|
@ -1,17 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright 2018 Google Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = require('./lib/errors');
|
|
||||||
|
|
@ -31,7 +31,7 @@ This code snippet navigates to example.com in WebKit, and saves a screenshot.
|
||||||
const pw = require('playwright');
|
const pw = require('playwright');
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await pw.playwright('webkit').launch(); // or 'chromium', 'firefox'
|
const browser = await pw.webkit.launch(); // or 'chromium', 'firefox'
|
||||||
const context = await browser.newContext();
|
const context = await browser.newContext();
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ This code snippet navigates to example.com in Firefox, and executes a script in
|
||||||
const pw = require('playwright');
|
const pw = require('playwright');
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await pw.playwright('firefox').launch(); // or 'chromium', 'webkit'
|
const browser = await pw.firefox.launch(); // or 'chromium', 'webkit'
|
||||||
const context = await browser.newContext();
|
const context = await browser.newContext();
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
||||||
|
|
|
||||||
17
chromium.js
17
chromium.js
|
|
@ -1,17 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright 2017 Google Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = require('./index').playwright('chromium');
|
|
||||||
30
docs/api.md
30
docs/api.md
|
|
@ -300,7 +300,7 @@
|
||||||
Playwright module provides a method to launch a browser instance.
|
Playwright module provides a method to launch a browser instance.
|
||||||
The following is a typical example of using Playwright to drive automation:
|
The following is a typical example of using Playwright to drive automation:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright')('chromium'); // Or 'firefox' or 'webkit'.
|
const playwright = require('playwright').chromium; // Or 'firefox' or 'webkit'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.launch();
|
const browser = await playwright.launch();
|
||||||
|
|
@ -329,7 +329,7 @@ Returns a list of devices to be used with [`page.emulate(options)`](#pageemulate
|
||||||
devices can be found in [lib/deviceDescriptors.js](https://github.com/Microsoft/playwright/blob/master/src/deviceDescriptors.ts).
|
devices can be found in [lib/deviceDescriptors.js](https://github.com/Microsoft/playwright/blob/master/src/deviceDescriptors.ts).
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright')('firefox'); // Or 'chromium' or 'webkit'.
|
const playwright = require('playwright').firefox; // Or 'chromium' or 'webkit'.
|
||||||
const iPhone = playwright.devices['iPhone 6'];
|
const iPhone = playwright.devices['iPhone 6'];
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
@ -376,7 +376,7 @@ A Browser is created when Playwright connects to a browser instance, either thro
|
||||||
|
|
||||||
An example of using a [Browser] to create a [Page]:
|
An example of using a [Browser] to create a [Page]:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').firefox; // Or 'chromium' or 'webkit'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.launch();
|
const browser = await playwright.launch();
|
||||||
|
|
@ -388,7 +388,7 @@ const playwright = require('playwright');
|
||||||
|
|
||||||
An example of disconnecting from and reconnecting to a [Browser]:
|
An example of disconnecting from and reconnecting to a [Browser]:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').webkit; // Or 'chromium' or 'firefox'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browserServer = await playwright.launchServer();
|
const browserServer = await playwright.launchServer();
|
||||||
|
|
@ -678,7 +678,7 @@ One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'
|
||||||
|
|
||||||
An example of using `Dialog` class:
|
An example of using `Dialog` class:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').chromium; // Or 'firefox' or 'webkit'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.launch();
|
const browser = await playwright.launch();
|
||||||
|
|
@ -715,7 +715,7 @@ const playwright = require('playwright');
|
||||||
ElementHandle represents an in-page DOM element. ElementHandles can be created with the [page.$](#pageselector) method.
|
ElementHandle represents an in-page DOM element. ElementHandles can be created with the [page.$](#pageselector) method.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').chromium; // Or 'firefox' or 'webkit'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.launch();
|
const browser = await playwright.launch();
|
||||||
|
|
@ -982,7 +982,7 @@ At every point of time, page exposes its current frame tree via the [page.mainFr
|
||||||
An example of dumping frame tree:
|
An example of dumping frame tree:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').firefox; // Or 'chromium' or 'webkit'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.launch();
|
const browser = await playwright.launch();
|
||||||
|
|
@ -1413,7 +1413,7 @@ await page.waitFor(selector => !!document.querySelector(selector), {}, selector)
|
||||||
|
|
||||||
The `waitForFunction` can be used to observe viewport size change:
|
The `waitForFunction` can be used to observe viewport size change:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').firefox; // Or 'chromium' or 'webkit'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.launch();
|
const browser = await playwright.launch();
|
||||||
|
|
@ -1488,7 +1488,7 @@ immediately. If the selector doesn't appear after the `timeout` milliseconds of
|
||||||
|
|
||||||
This method works across navigations:
|
This method works across navigations:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').webkit; // Or 'chromium' or 'firefox'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.launch();
|
const browser = await playwright.launch();
|
||||||
|
|
@ -1770,7 +1770,7 @@ Page provides methods to interact with a single tab or [extension background pag
|
||||||
|
|
||||||
This example creates a page, navigates it to a URL, and then saves a screenshot:
|
This example creates a page, navigates it to a URL, and then saves a screenshot:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').webkit; // Or 'chromium' or 'firefox'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.launch();
|
const browser = await playwright.launch();
|
||||||
|
|
@ -2238,7 +2238,7 @@ If the `playwrightFunction` returns a [Promise], it will be awaited.
|
||||||
|
|
||||||
An example of adding an `md5` function into the page:
|
An example of adding an `md5` function into the page:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').firefox; // Or 'chromium' or 'webkit'.
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
@ -2262,7 +2262,7 @@ const crypto = require('crypto');
|
||||||
An example of adding a `window.readfile` function into the page:
|
An example of adding a `window.readfile` function into the page:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').chromium; // Or 'firefox' or 'webkit'.
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
@ -2758,7 +2758,7 @@ Waits for event to fire and passes its value into the predicate function. Resolv
|
||||||
|
|
||||||
The `waitForFunction` can be used to observe viewport size change:
|
The `waitForFunction` can be used to observe viewport size change:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').webkit; // Or 'chromium' or 'firefox'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.launch();
|
const browser = await playwright.launch();
|
||||||
|
|
@ -2866,7 +2866,7 @@ immediately. If the selector doesn't appear after the `timeout` milliseconds of
|
||||||
|
|
||||||
This method works across navigations:
|
This method works across navigations:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').chromium; // Or 'firefox' or 'webkit'.
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await playwright.launch();
|
const browser = await playwright.launch();
|
||||||
|
|
@ -3749,7 +3749,7 @@ Playwright can be used for testing Chrome Extensions.
|
||||||
|
|
||||||
The following is code for getting a handle to the [background page](https://developer.chrome.com/extensions/background_pages) of an extension whose source is located in `./my-extension`:
|
The following is code for getting a handle to the [background page](https://developer.chrome.com/extensions/background_pages) of an extension whose source is located in `./my-extension`:
|
||||||
```js
|
```js
|
||||||
const playwright = require('playwright');
|
const playwright = require('playwright').chromium;
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const pathToExtension = require('path').join(__dirname, 'my-extension');
|
const pathToExtension = require('path').join(__dirname, 'my-extension');
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,10 @@ API consists of a single `connect` function, similar to
|
||||||
[webkitPlaywright.connect(options)](api.md#webkitplaywrightconnectoptions).
|
[webkitPlaywright.connect(options)](api.md#webkitplaywrightconnectoptions).
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src='../playwright/web.js'></script>
|
<script src='playwright/web.js'></script>
|
||||||
<script>
|
<script>
|
||||||
async function usePlaywright() {
|
async function usePlaywright() {
|
||||||
const connect = window.playwrightweb('chromium'); // or 'firefox', 'webkit'
|
const browser = await window.playwrightweb.chromium.connect(options); // or 'firefox', 'webkit'
|
||||||
const browser = await connect(options);
|
|
||||||
// ... drive automation ...
|
// ... drive automation ...
|
||||||
await browser.disconnect();
|
await browser.disconnect();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
firefox.js
17
firefox.js
|
|
@ -1,17 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright 2017 Google Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = require('./index').playwright('firefox');
|
|
||||||
7
index.d.ts
vendored
7
index.d.ts
vendored
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './lib/api';
|
export * from './lib/api';
|
||||||
export function playwright(browser: 'chromium'): import('./lib/api').ChromiumPlaywright;
|
export const chromium: import('./lib/api').ChromiumPlaywright;
|
||||||
export function playwright(browser: 'firefox'): import('./lib/api').FirefoxPlaywright;
|
export const firefox: import('./lib/api').FirefoxPlaywright;
|
||||||
export function playwright(browser: 'webkit'): import('./lib/api').WebKitPlaywright;
|
export const webkit: import('./lib/api').WebKitPlaywright;
|
||||||
|
export type PlaywrightWeb = typeof import('./lib/web');
|
||||||
|
|
|
||||||
13
index.js
13
index.js
|
|
@ -19,17 +19,12 @@ const api = require('./lib/api');
|
||||||
const packageJson = require('./package.json');
|
const packageJson = require('./package.json');
|
||||||
|
|
||||||
for (const className in api) {
|
for (const className in api) {
|
||||||
// Playwright-web excludes certain classes from bundle, e.g. BrowserFetcher.
|
|
||||||
if (typeof api[className] === 'function')
|
if (typeof api[className] === 'function')
|
||||||
helper.installAsyncStackHooks(api[className]);
|
helper.installAsyncStackHooks(api[className]);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.playwright = browser => {
|
module.exports = {
|
||||||
if (browser === 'chromium')
|
chromium: new api.ChromiumPlaywright(__dirname, packageJson.playwright.chromium_revision),
|
||||||
return new api.ChromiumPlaywright(__dirname, packageJson.playwright.chromium_revision);
|
firefox: new api.FirefoxPlaywright(__dirname, packageJson.playwright.firefox_revision),
|
||||||
if (browser === 'firefox')
|
webkit: new api.WebKitPlaywright(__dirname, packageJson.playwright.webkit_revision),
|
||||||
return new api.FirefoxPlaywright(__dirname, packageJson.playwright.firefox_revision);
|
|
||||||
if (browser === 'webkit')
|
|
||||||
return new api.WebKitPlaywright(__dirname, packageJson.playwright.webkit_revision);
|
|
||||||
throw new Error(`Unsupported browser "${browser}"`);
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
15
src/web.ts
15
src/web.ts
|
|
@ -18,14 +18,9 @@ import { CRBrowser as ChromiumBrowser } from './chromium/crBrowser';
|
||||||
import { FFBrowser as FirefoxBrowser } from './firefox/ffBrowser';
|
import { FFBrowser as FirefoxBrowser } from './firefox/ffBrowser';
|
||||||
import { WKBrowser as WebKitBrowser } from './webkit/wkBrowser';
|
import { WKBrowser as WebKitBrowser } from './webkit/wkBrowser';
|
||||||
|
|
||||||
function connect(browser: 'chromium' | 'firefox' | 'webkit') {
|
const connect = {
|
||||||
if (browser === 'chromium')
|
chromium: { connect: ChromiumBrowser.connect },
|
||||||
return ChromiumBrowser.connect;
|
firefox: { connect: FirefoxBrowser.connect },
|
||||||
if (browser === 'firefox')
|
webkit: { connect: WebKitBrowser.connect },
|
||||||
return FirefoxBrowser.connect;
|
};
|
||||||
if (browser === 'webkit')
|
|
||||||
return WebKitBrowser.connect;
|
|
||||||
throw new Error(`Unsupported browser "${browser}"`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export = connect;
|
export = connect;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
<script src='../../web.js'></script>
|
<script src='../../web.js'></script>
|
||||||
<script>
|
<script>
|
||||||
async function setup(product, connectOptions) {
|
async function setup(product, connectOptions) {
|
||||||
window.connect = window.playwrightweb(product);
|
window.browser = await window.playwrightweb[product].connect(connectOptions);
|
||||||
window.browser = await window.connect(connectOptions);
|
|
||||||
window.context = await window.browser.newContext();
|
window.context = await window.browser.newContext();
|
||||||
window.page = await window.context.newPage();
|
window.page = await window.context.newPage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const {spawn, execSync} = require('child_process');
|
const {spawn, execSync} = require('child_process');
|
||||||
|
|
||||||
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, playwrightPath}) {
|
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, playwrightPath, product}) {
|
||||||
const {describe, xdescribe, fdescribe} = testRunner;
|
const {describe, xdescribe, fdescribe} = testRunner;
|
||||||
const {it, fit, xit, dit} = testRunner;
|
const {it, fit, xit, dit} = testRunner;
|
||||||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||||
|
|
@ -40,7 +40,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
|
||||||
// Disable DUMPIO to cleanly read stdout.
|
// Disable DUMPIO to cleanly read stdout.
|
||||||
dumpio: false,
|
dumpio: false,
|
||||||
});
|
});
|
||||||
const res = spawn('node', [path.join(__dirname, '..', 'fixtures', 'closeme.js'), playwrightPath, JSON.stringify(options)]);
|
const res = spawn('node', [path.join(__dirname, '..', 'fixtures', 'closeme.js'), playwrightPath, product, JSON.stringify(options)]);
|
||||||
let wsEndPointCallback;
|
let wsEndPointCallback;
|
||||||
const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
|
const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
|
||||||
let output = '';
|
let output = '';
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const {spawn, execSync} = require('child_process');
|
const {spawn, execSync} = require('child_process');
|
||||||
|
|
||||||
module.exports.describe = function({testRunner, defaultBrowserOptions, playwright, playwrightPath}) {
|
module.exports.describe = function({testRunner, defaultBrowserOptions, playwright, playwrightPath, product}) {
|
||||||
const {describe, xdescribe, fdescribe} = testRunner;
|
const {describe, xdescribe, fdescribe} = testRunner;
|
||||||
const {it, fit, xit, dit} = testRunner;
|
const {it, fit, xit, dit} = testRunner;
|
||||||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||||
|
|
@ -28,7 +28,7 @@ module.exports.describe = function({testRunner, defaultBrowserOptions, playwrigh
|
||||||
// Disable DUMPIO to cleanly read stdout.
|
// Disable DUMPIO to cleanly read stdout.
|
||||||
dumpio: false,
|
dumpio: false,
|
||||||
});
|
});
|
||||||
const res = spawn('node', [path.join(__dirname, '..', 'fixtures', 'closeme.js'), playwrightPath, JSON.stringify(options)]);
|
const res = spawn('node', [path.join(__dirname, '..', 'fixtures', 'closeme.js'), playwrightPath, product, JSON.stringify(options)]);
|
||||||
let wsEndPointCallback;
|
let wsEndPointCallback;
|
||||||
const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
|
const wsEndPointPromise = new Promise(x => wsEndPointCallback = x);
|
||||||
let output = '';
|
let output = '';
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const {spawn} = require('child_process');
|
const {spawn} = require('child_process');
|
||||||
|
|
||||||
module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, playwrightPath, FFOX, CHROMIUM, WEBKIT}) {
|
module.exports.describe = function({testRunner, expect, product, playwrightPath, FFOX, CHROMIUM, WEBKIT}) {
|
||||||
const {describe, xdescribe, fdescribe} = testRunner;
|
const {describe, xdescribe, fdescribe} = testRunner;
|
||||||
const {it, fit, xit, dit} = testRunner;
|
const {it, fit, xit, dit} = testRunner;
|
||||||
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
||||||
|
|
@ -26,14 +26,14 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
|
||||||
describe('Fixtures', function() {
|
describe('Fixtures', function() {
|
||||||
it('dumpio option should work with pipe option ', async({server}) => {
|
it('dumpio option should work with pipe option ', async({server}) => {
|
||||||
let dumpioData = '';
|
let dumpioData = '';
|
||||||
const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, 'use-pipe']);
|
const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, product, 'use-pipe']);
|
||||||
res.stderr.on('data', data => dumpioData += data.toString('utf8'));
|
res.stderr.on('data', data => dumpioData += data.toString('utf8'));
|
||||||
await new Promise(resolve => res.on('close', resolve));
|
await new Promise(resolve => res.on('close', resolve));
|
||||||
expect(dumpioData).toContain('message from dumpio');
|
expect(dumpioData).toContain('message from dumpio');
|
||||||
});
|
});
|
||||||
it('should dump browser process stderr', async({server}) => {
|
it('should dump browser process stderr', async({server}) => {
|
||||||
let dumpioData = '';
|
let dumpioData = '';
|
||||||
const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath]);
|
const res = spawn('node', [path.join(__dirname, 'fixtures', 'dumpio.js'), playwrightPath, product]);
|
||||||
res.stderr.on('data', data => dumpioData += data.toString('utf8'));
|
res.stderr.on('data', data => dumpioData += data.toString('utf8'));
|
||||||
await new Promise(resolve => res.on('close', resolve));
|
await new Promise(resolve => res.on('close', resolve));
|
||||||
expect(dumpioData).toContain('message from dumpio');
|
expect(dumpioData).toContain('message from dumpio');
|
||||||
|
|
|
||||||
4
test/fixtures/closeme.js
vendored
4
test/fixtures/closeme.js
vendored
|
|
@ -1,5 +1,5 @@
|
||||||
(async() => {
|
(async() => {
|
||||||
const [, , playwrightRoot, options] = process.argv;
|
const [, , playwrightRoot, product, options] = process.argv;
|
||||||
const browserServer = await require(playwrightRoot).launchServer(JSON.parse(options));
|
const browserServer = await require(playwrightRoot)[product.toLowerCase()].launchServer(JSON.parse(options));
|
||||||
console.log(browserServer.wsEndpoint());
|
console.log(browserServer.wsEndpoint());
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
6
test/fixtures/dumpio.js
vendored
6
test/fixtures/dumpio.js
vendored
|
|
@ -4,7 +4,7 @@
|
||||||
console.log('unhandledRejection', error.message);
|
console.log('unhandledRejection', error.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
const [, , playwrightRoot, usePipe] = process.argv;
|
const [, , playwrightRoot, product, usePipe] = process.argv;
|
||||||
const options = {
|
const options = {
|
||||||
pipe: usePipe === 'use-pipe',
|
pipe: usePipe === 'use-pipe',
|
||||||
ignoreDefaultArgs: true,
|
ignoreDefaultArgs: true,
|
||||||
|
|
@ -14,10 +14,10 @@
|
||||||
args: ['-e', 'console.error("message from dumpio")', '--']
|
args: ['-e', 'console.error("message from dumpio")', '--']
|
||||||
}
|
}
|
||||||
console.error('using pipe: ' + options.pipe);
|
console.error('using pipe: ' + options.pipe);
|
||||||
if (playwrightRoot.includes('firefox'))
|
if (product.toLowerCase() === 'firefox')
|
||||||
options.args.push('-juggler', '-profile');
|
options.args.push('-juggler', '-profile');
|
||||||
try {
|
try {
|
||||||
await require(playwrightRoot).launchServer(options);
|
await require(playwrightRoot)[product.toLowerCase()].launchServer(options);
|
||||||
console.error('Browser launch unexpectedly succeeded.');
|
console.error('Browser launch unexpectedly succeeded.');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,11 +72,11 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
|
||||||
|
|
||||||
describe('Top-level requires', function() {
|
describe('Top-level requires', function() {
|
||||||
it('should require top-level Errors', async() => {
|
it('should require top-level Errors', async() => {
|
||||||
const Errors = require(path.join(utils.projectRoot(), '/Errors'));
|
const Errors = require(path.join(utils.projectRoot(), '/lib/errors.js'));
|
||||||
expect(Errors.TimeoutError).toBe(playwright.errors.TimeoutError);
|
expect(Errors.TimeoutError).toBe(playwright.errors.TimeoutError);
|
||||||
});
|
});
|
||||||
it('should require top-level DeviceDescriptors', async() => {
|
it('should require top-level DeviceDescriptors', async() => {
|
||||||
const Devices = require(path.join(utils.projectRoot(), '/DeviceDescriptors'));
|
const Devices = require(path.join(utils.projectRoot(), '/lib/deviceDescriptors.js')).DeviceDescriptors;
|
||||||
expect(Devices['iPhone 6']).toBe(playwright.devices['iPhone 6']);
|
expect(Devices['iPhone 6']).toBe(playwright.devices['iPhone 6']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => {
|
||||||
const LINUX = os.platform() === 'linux';
|
const LINUX = os.platform() === 'linux';
|
||||||
const WIN = os.platform() === 'win32';
|
const WIN = os.platform() === 'win32';
|
||||||
|
|
||||||
const playwright = require(playwrightPath);
|
const playwright = require(playwrightPath)[product.toLowerCase()];
|
||||||
|
|
||||||
const headless = (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true';
|
const headless = (process.env.HEADLESS || 'true').trim().toLowerCase() === 'true';
|
||||||
const slowMo = parseInt((process.env.SLOW_MO || '0').trim(), 10);
|
const slowMo = parseInt((process.env.SLOW_MO || '0').trim(), 10);
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ if (process.env.BROWSER === 'firefox') {
|
||||||
describe('Firefox', () => {
|
describe('Firefox', () => {
|
||||||
testRunner.loadTests(require('./playwright.spec.js'), {
|
testRunner.loadTests(require('./playwright.spec.js'), {
|
||||||
product: 'Firefox',
|
product: 'Firefox',
|
||||||
playwrightPath: path.join(utils.projectRoot(), 'firefox.js'),
|
playwrightPath: utils.projectRoot(),
|
||||||
testRunner,
|
testRunner,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -89,7 +89,7 @@ if (process.env.BROWSER === 'firefox') {
|
||||||
describe('WebKit', () => {
|
describe('WebKit', () => {
|
||||||
testRunner.loadTests(require('./playwright.spec.js'), {
|
testRunner.loadTests(require('./playwright.spec.js'), {
|
||||||
product: 'WebKit',
|
product: 'WebKit',
|
||||||
playwrightPath: path.join(utils.projectRoot(), 'webkit.js'),
|
playwrightPath: utils.projectRoot(),
|
||||||
testRunner,
|
testRunner,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -97,7 +97,7 @@ if (process.env.BROWSER === 'firefox') {
|
||||||
describe('Chromium', () => {
|
describe('Chromium', () => {
|
||||||
testRunner.loadTests(require('./playwright.spec.js'), {
|
testRunner.loadTests(require('./playwright.spec.js'), {
|
||||||
product: 'Chromium',
|
product: 'Chromium',
|
||||||
playwrightPath: path.join(utils.projectRoot(), 'chromium.js'),
|
playwrightPath: utils.projectRoot(),
|
||||||
testRunner,
|
testRunner,
|
||||||
});
|
});
|
||||||
if (process.env.COVERAGE)
|
if (process.env.COVERAGE)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const playwright = require('../../chromium');
|
const playwright = require('../../index.js').chromium;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const Source = require('./Source');
|
const Source = require('./Source');
|
||||||
|
|
||||||
|
|
|
||||||
20
web.d.ts
vendored
20
web.d.ts
vendored
|
|
@ -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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function connect(browser: 'chromium'): import('./lib/api').ChromiumBrowser.connect;
|
|
||||||
function connect(browser: 'firefox'): import('./lib/api').FirefoxBrowser.connect;
|
|
||||||
function connect(browser: 'webkit'): import('./lib/api').WebKitBrowser.connect;
|
|
||||||
export = connect;
|
|
||||||
17
webkit.js
17
webkit.js
|
|
@ -1,17 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright 2017 Google Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = require('./index').playwright('webkit');
|
|
||||||
Loading…
Reference in a new issue