Playwright Library
Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright to drive automation:
const { chromium, firefox, webkit } = require('playwright');
(async () => {
const browser = await chromium.launch(); // Or 'firefox' or 'webkit'.
const page = await browser.newPage();
await page.goto('http://example.com');
// other actions...
await browser.close();
})();
屬性 (Properties)
chromium
Added before v1.9This object can be used to launch or connect to Chromium, returning instances of Browser.
使用方式
playwright.chromium
型別 (Type)
devices
Added before v1.9Returns a dictionary of devices to be used with browser.newContext() or browser.newPage().
const { webkit, devices } = require('playwright');
const iPhone = devices['iPhone 6'];
(async () => {
const browser = await webkit.launch();
const context = await browser.newContext({
...iPhone
});
const page = await context.newPage();
await page.goto('http://example.com');
// other actions...
await browser.close();
})();
使用方式
playwright.devices
型別 (Type)
errors
Added before v1.9Playwright methods might throw errors if they are unable to fulfill a request. For example, locator.waitFor() might fail if the selector doesn't match any nodes during the given timeframe.
For certain types of errors Playwright uses specific error classes. These classes are available via playwright.errors
.
An example of handling a timeout error:
try {
await page.locator('.foo').waitFor();
} catch (e) {
if (e instanceof playwright.errors.TimeoutError) {
// Do something if this is a timeout.
}
}
使用方式
playwright.errors
型別 (Type)
- Object
-
TimeoutError
functionA class of TimeoutError.
-
firefox
Added before v1.9This object can be used to launch or connect to Firefox, returning instances of Browser.
使用方式
playwright.firefox
型別 (Type)
request
Added in: v1.16Exposes API that can be used for the Web API testing.
使用方式
playwright.request
型別 (Type)
selectors
Added before v1.9Selectors can be used to install custom selector engines. See extensibility for more information.
使用方式
playwright.selectors
型別 (Type)
webkit
Added before v1.9This object can be used to launch or connect to WebKit, returning instances of Browser.
使用方式
playwright.webkit
型別 (Type)