Học Playwright tiếng Việt, Cộng đồng Playwright cho người Việt

Khóa học

[Vọc Playwright] – Playwright library

https://playwright.dev/docs/api/class-playwright

Playwright Library

  • Playwright cung cấp một method để khởi động một browser. Đây là một ví dụ điển hình về cách sử dụng Playwright để 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

  • chromium là một object cho phép bạn khởi động hoặc kết nối với trình duyệt Chromium (Chrome), trả về các instance của Browser.

Usage

playwright.chromium

Type

  • BrowserType: https://playwright.dev/docs/api/class-browsertype

devices

  • Trả về dictionary của các devices sẽ được sử dụng với browser.newContext() hoặc 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();
})();

Usage

playwright.devices

Type

  • Object

errors

  • errors là một object chứa các lớp lỗi (error classes) được sử dụng bởi Playwright. Khi Playwright không thể thực hiện một request, nó sẽ ném ra một lỗi.
try {
  await page.locator('.foo').waitFor();
} catch (e) {
  if (e instanceof playwright.errors.TimeoutError) {
    // Do something if this is a timeout.
  }
}

Usage

playwright.errors

Type

  • Object
    • TimeoutError function
    • A class of TimeoutError.

firefox

  • firefox là một object cho phép bạn khởi động hoặc connect với trình duyệt Firefox, trả về các instance của Browser.

Usage

playwright.firefox

Type

  • BrowserType

request

  • request là một object cung cấp API sử dụng để Web API testing.
playwright.request

Type

  • APIRequest

selectors

  • selectors là một object cho phép bạn cài đặt các công cụ custom selector. Bạn có thể sử dụng nó để mở rộng khả năng của Playwright.
playwright.selectors

Type

  • Selectors

webkit

  • webkit là một object cho phép bạn khởi động hoặc connect với trình duyệt WebKit (Safari), trả về các instance của Browser.
playwright.webkit

Type

  • BrowserType

Trả lời