Playwrightライブラリ
Playwrightモジュールは、ブラウザインスタンスを起動するメソッドを提供します。Playwrightを使用して自動化を駆動する典型的な例を以下に示します。
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();
})();
プロパティ
chromium
v1.9より前に追加このオブジェクトは Chromium を起動または接続するために使用でき、Browser のインスタンスを返します。
使用法
playwright.chromium
タイプ
devices
v1.9より前に追加browser.newContext() または 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
タイプ
errors
v1.9より前に追加Playwright のメソッドは、リクエストを満たせない場合、エラーをスローすることがあります。例えば、locator.waitFor() は、指定された時間内にセレクターがどのノードにも一致しない場合、失敗することがあります。
特定のエラータイプに対して、Playwright は特定のエラークラスを使用します。これらのクラスは playwright.errors を介して利用できます。
タイムアウトエラーの処理例
try {
await page.locator('.foo').waitFor();
} catch (e) {
if (e instanceof playwright.errors.TimeoutError) {
// Do something if this is a timeout.
}
}
使用法
playwright.errors
タイプ
- Object
-
TimeoutError関数TimeoutError のクラス。
-
firefox
v1.9より前に追加このオブジェクトは Firefox を起動または接続するために使用でき、Browser のインスタンスを返します。
使用法
playwright.firefox
タイプ
request
追加バージョン: v1.16Web APIテストに使用できるAPIを公開します。
使用法
playwright.request
タイプ
selectors
v1.9より前に追加セレクターはカスタムセレクターエンジンをインストールするために使用できます。詳細については、拡張性を参照してください。
使用法
playwright.selectors
タイプ
webkit
v1.9より前に追加このオブジェクトは WebKit を起動または接続するために使用でき、Browser のインスタンスを返します。
使用法
playwright.webkit
タイプ