playwright

Playwright-compatible API built on WebDriver BiDi

playwright
bidi
webdriver
moon add mizchi/playwright@0.3.7
Download zip
Author
Version
0.3.7
License
Apache-2.0
Last updated
4 months ago
Downloads
244
README

#mizchi/playwright.mbt

Playwright 互換 API を WebDriver BiDi 上に実装した MoonBit ライブラリです。 関数名は MoonBit 流儀の snake_case で提供します。

#インストール

moon add mizchi/playwright

#パッケージ

  • mizchi/playwright: ブラウザ操作 API(chromium, firefox, webkit など)
  • mizchi/playwright/test: expect とテスト DSL(retry, timeout, to_pass, expect_poll, step, skip, fail, fixme, shard など)

#使い方

import "mizchi/playwright" as @pw
import "mizchi/playwright/test" as @pwt

let chromium = @pw.chromium()
let _ = @pwt.expect(chromium.name()).to_equal("chromium")

async test "dsl helpers" {
@pwt.configure_test(
retry_times=3,
timeout_ms=3_000,
expect_timeout_ms=800,
expect_interval_ms=10,
shard_index=1,
shard_total=2,
)

let _ = @pwt.step("open", fn() -> Int { 1 })

// shard は設定値を省略可能
@pwt.shard(item_index=0, item_total=2, fn() {})

// retry / timeout は設定値をデフォルトとして使える
let _ = @pwt.retry(async fn() -> Int { 1 })

let _ = @pwt.timeout(async fn() -> Int { 1 })

// 一定時間リトライしながら assertion
@pwt.to_pass(async fn() {
@pwt.expect("ok").to_equal("ok")
})

// expect.poll 相当
@pwt.expect_poll(async fn() -> String { "done-1" }).to_match("done-\\d+")
}

#Playwright 連携(1プロセス共有)

@playwright/test 側で globalSetup を使うと、ブラウザサーバーを 1 回だけ起動して wsEndpoint を複数テストで共有できます。

// test/integration/global.setup.js const { chromium } = require("@playwright/test") const fs = require("node:fs/promises") const path = require("node:path") module.exports = async () => { const server = await chromium.launchServer({ headless: true }) const runtimeDir = path.join(__dirname, ".runtime") await fs.mkdir(runtimeDir, { recursive: true }) await fs.writeFile( path.join(runtimeDir, "state.json"), JSON.stringify({ ws_endpoint: server.wsEndpoint() }), "utf-8", ) return async () => { await server.close() } }

// test/integration/config_bridge.spec.js (抜粋) const state = JSON.parse(fs.readFileSync(".runtime/state.json", "utf-8")) const wsEndpoint = state.ws_endpoint spawnSync("moon", [ "run", "src/playwright/test_utils/integration_bridge", "--target", "js", /* retry/timeout/shard など */, wsEndpoint, ])

このリポジトリでは上記方式を test/integration/ で実装済みです。

#
PlaywrightError

pub suberror PlaywrightError {
StrictModeViolation(String, Int)
}

#
BoundingBox

pub struct BoundingBox {
x : Double
y : Double
width : Double
height : Double
}

impl Eq for BoundingBox
impl Show for BoundingBox

#
BoundingBox::from_json

fn BoundingBox::from_json(json : Json) -> BoundingBox?

#
BoundingBox::new

fn BoundingBox::new(x : Double, y : Double, width : Double, height : Double) -> BoundingBox

#
BoundingBox::to_json

fn BoundingBox::to_json(self : BoundingBox) -> Json

#
Browser

pub struct Browser {
// private fields
}

#
Browser::close

async fn Browser::close(self : Browser) -> Unit

#
Browser::close_with_error_callback

fn Browser::close_with_error_callback(self : Browser, on_error : (Error) -> Unit) -> Unit

Close browser with error callback (for use with defer) Note: This initiates close but doesn't wait for completion

#
Browser::contexts

fn Browser::contexts(self : Browser) -> Array[BrowserContext]

Get all contexts

#
Browser::is_connected

fn Browser::is_connected(self : Browser) -> Bool

Check if browser is connected

#
Browser::new_context

async fn Browser::new_context(self : Browser, viewport? : (Int, Int), user_agent? : String, locale? : String, timezone_id? : String, geolocation? : (Double, Double), permissions? : Array[String], color_scheme? : String, reduced_motion? : String, forced_colors? : String, accept_downloads? : Bool, ignore_https_errors? : Bool, javascript_enabled? : Bool, bypass_csp? : Bool, offline? : Bool, device_scale_factor? : Double, is_mobile? : Bool, has_touch? : Bool) -> BrowserContext

Create new browser context

#
Browser::new_page

async fn Browser::new_page(self : Browser, viewport? : (Int, Int), user_agent? : String, locale? : String, timezone_id? : String, ignore_https_errors? : Bool, javascript_enabled? : Bool, bypass_csp? : Bool, offline? : Bool, color_scheme? : String, device_scale_factor? : Double, is_mobile? : Bool, has_touch? : Bool) -> Page

Create new page (with default context)

#
Browser::version

fn Browser::version(self : Browser) -> String

Get browser version

#
BrowserContext

pub struct BrowserContext {
// private fields
}

#
BrowserContext::add_cookies

async fn BrowserContext::add_cookies(self : BrowserContext, cookies : Array[Cookie]) -> Unit

Add cookies

#
BrowserContext::clear_cookies

async fn BrowserContext::clear_cookies(self : BrowserContext) -> Unit

Clear cookies

#
BrowserContext::clear_permissions

async fn BrowserContext::clear_permissions(self : BrowserContext) -> Unit

Clear permissions

#
BrowserContext::close

async fn BrowserContext::close(self : BrowserContext) -> Unit

Close context

#
BrowserContext::close_with_error_callback

fn BrowserContext::close_with_error_callback(self : BrowserContext, on_error : (Error) -> Unit) -> Unit

Close context with error callback (for use with defer) Note: This initiates close but doesn't wait for completion

#
BrowserContext::cookies

async fn BrowserContext::cookies(self : BrowserContext, urls? : Array[String]) -> Array[Cookie]

Get cookies

#
BrowserContext::grant_permissions

async fn BrowserContext::grant_permissions(self : BrowserContext, permissions : Array[String], origin? : String) -> Unit

Grant permissions

#
BrowserContext::new_page

async fn BrowserContext::new_page(self : BrowserContext) -> Page

Create new page in context

#
BrowserContext::pages

fn BrowserContext::pages(self : BrowserContext) -> Array[Page]

Get all pages in context

#
BrowserContext::set_default_navigation_timeout

fn BrowserContext::set_default_navigation_timeout(self : BrowserContext, timeout : Int) -> Unit

Set default navigation timeout

#
BrowserContext::set_default_timeout

fn BrowserContext::set_default_timeout(self : BrowserContext, timeout : Int) -> Unit

Set default timeout

#
BrowserContext::set_geolocation

async fn BrowserContext::set_geolocation(self : BrowserContext, latitude : Double, longitude : Double, accuracy? : Double) -> Unit

Set geolocation

#
BrowserContext::set_offline

async fn BrowserContext::set_offline(self : BrowserContext, offline : Bool) -> Unit

Set offline mode

#
BrowserKind

pub enum BrowserKind {
Chromium
Firefox
WebKit
}

impl Eq for BrowserKind
impl Show for BrowserKind

#
BrowserType

pub struct BrowserType {
kind : BrowserKind
}

impl Show for BrowserType

#
BrowserType::connect

async fn BrowserType::connect(self : BrowserType, ws_endpoint : String) -> Browser

#
BrowserType::connect_over_websocket

async fn BrowserType::connect_over_websocket(self : BrowserType, ws_endpoint : String) -> Browser

#
BrowserType::connect_with_transport

async fn BrowserType::connect_with_transport(self : BrowserType, transport :
Transport
) -> Browser

#
BrowserType::launch

async fn BrowserType::launch(self : BrowserType, headless? : Bool, args? : Array[String], channel? : String, chromium_sandbox? : Bool, devtools? : Bool, downloads_path? : String, executable_path? : String, handle_sighup? : Bool, handle_sigint? : Bool, handle_sigterm? : Bool, slow_mo? : Int, timeout? : Int) -> Browser

Launch browser with options. Spawns a real browser process and connects via BiDi WebSocket. See: https://playwright.dev/docs/api/class-browsertype#browser-type-launch

#
BrowserType::launch_persistent_context

async fn BrowserType::launch_persistent_context(self : BrowserType, user_data_dir : String, headless? : Bool, args? : Array[String], channel? : String, slow_mo? : Int, timeout? : Int) -> BrowserContext

Launch persistent context (saves user data)

#
BrowserType::name

fn BrowserType::name(self : BrowserType) -> String

#
Clip

pub struct Clip {
x : Double
y : Double
width : Double
height : Double
}

impl Eq for Clip
impl Show for Clip

#
Clip::new

fn Clip::new(x : Double, y : Double, width : Double, height : Double) -> Clip

#
Clip::to_json

fn Clip::to_json(self : Clip) -> Json

#
ConsoleMessage

pub(all) struct ConsoleMessage {
level : String
text : String
source : String
}

Console message collected from log.entryAdded events
pub struct Cookie {
name : String
value : String
url : String?
domain : String?
path : String?
expires : Double?
http_only : Bool?
secure : Bool?
same_site : String?
}

impl Eq for Cookie
impl Show for Cookie

#
Cookie::from_json

fn Cookie::from_json(json : Json) -> Cookie?

#
Cookie::new

fn Cookie::new(name : String, value : String, url? : String, domain? : String, path? : String, expires? : Double, http_only? : Bool, secure? : Bool, same_site? : String) -> Cookie

#
Cookie::to_json

fn Cookie::to_json(self : Cookie) -> Json

#
ElementHandle

pub struct ElementHandle {
// private fields
}

#
ElementHandle::as_js_handle

fn ElementHandle::as_js_handle(self : ElementHandle) -> JSHandle

#
ElementHandle::dispose

async fn ElementHandle::dispose(self : ElementHandle) -> Unit

#
ElementHandle::evaluate

async fn ElementHandle::evaluate(self : ElementHandle, page_function : String, arg? : Json) -> Json

#
ElementHandle::evaluate_handle

async fn ElementHandle::evaluate_handle(self : ElementHandle, page_function : String, arg? : Json) -> JSHandle

#
ElementHandle::from_handle

fn ElementHandle::from_handle(handle : JSHandle) -> ElementHandle

#
ElementHandle::json_value

fn ElementHandle::json_value(self : ElementHandle) -> Json

#
Expect

pub struct Expect[T] {
actual : T
}

#
Expect::to_be

#callsite(autofill(loc))
fn[T : Eq + Show] Expect::to_be(self : Expect[T], expected : T, msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_be_checked

#callsite(autofill(loc))
async fn Expect::to_be_checked(self : Expect[Locator], timeout? : Int, msg? : String, loc~ : SourceLoc) -> Unit

#
Expect::to_be_close_to

#callsite(autofill(loc))
fn Expect::to_be_close_to(self : Expect[Double], expected : Double, precision? : Int, msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_be_disabled

#callsite(autofill(loc))
async fn Expect::to_be_disabled(self : Expect[Locator], timeout? : Int, msg? : String, loc~ : SourceLoc) -> Unit

#
Expect::to_be_editable

#callsite(autofill(loc))
async fn Expect::to_be_editable(self : Expect[Locator], timeout? : Int, msg? : String, loc~ : SourceLoc) -> Unit

#
Expect::to_be_enabled

#callsite(autofill(loc))
async fn Expect::to_be_enabled(self : Expect[Locator], timeout? : Int, msg? : String, loc~ : SourceLoc) -> Unit

#
Expect::to_be_falsy

#callsite(autofill(loc))
fn Expect::to_be_falsy(self : Expect[Bool], msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_be_focused

#callsite(autofill(loc))
async fn Expect::to_be_focused(self : Expect[Locator], timeout? : Int, msg? : String, loc~ : SourceLoc) -> Unit

#
Expect::to_be_greater_than

#callsite(autofill(loc))
fn Expect::to_be_greater_than(self : Expect[Int], expected : Int, msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_be_hidden

#callsite(autofill(loc))
async fn Expect::to_be_hidden(self : Expect[Locator], timeout? : Int, msg? : String, loc~ : SourceLoc) -> Unit

#
Expect::to_be_less_than

#callsite(autofill(loc))
fn Expect::to_be_less_than(self : Expect[Int], expected : Int, msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_be_truthy

#callsite(autofill(loc))
fn Expect::to_be_truthy(self : Expect[Bool], msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_be_visible

#callsite(autofill(loc))
async fn Expect::to_be_visible(self : Expect[Locator], timeout? : Int, msg? : String, loc~ : SourceLoc) -> Unit

#
Expect::to_contain

#callsite(autofill(loc))
fn Expect::to_contain(self : Expect[String], expected : String, msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_contain_item

#callsite(autofill(loc))
fn[T : Eq + Show] Expect::to_contain_item(self : Expect[Array[T]], expected : T, msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_contain_text

#callsite(autofill(loc))
async fn Expect::to_contain_text(self : Expect[Locator], expected : String, timeout? : Int, msg? : String, match_mode? : String, normalize? : Bool, loc~ : SourceLoc) -> Unit

#
Expect::to_equal

#callsite(autofill(loc))
fn[T : Eq + Show] Expect::to_equal(self : Expect[T], expected : T, msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_have_attribute

#callsite(autofill(loc))
async fn Expect::to_have_attribute(self : Expect[Locator], name : String, expected? : String, timeout? : Int, msg? : String, match_mode? : String, normalize? : Bool, loc~ : SourceLoc) -> Unit

#
Expect::to_have_class

#callsite(autofill(loc))
async fn Expect::to_have_class(self : Expect[Locator], expected : String, expected_tokens? : Array[String], expected_list? : Array[String], expected_list_tokens? : Array[Array[String]], timeout? : Int, msg? : String, match_mode? : String, normalize? : Bool, loc~ : SourceLoc) -> Unit

#
Expect::to_have_count

#callsite(autofill(loc))
async fn Expect::to_have_count(self : Expect[Locator], expected : Int, timeout? : Int, msg? : String, loc~ : SourceLoc) -> Unit

#
Expect::to_have_css

#callsite(autofill(loc))
async fn Expect::to_have_css(self : Expect[Locator], name : String, expected : String, timeout? : Int, msg? : String, match_mode? : String, normalize? : Bool, numeric? : Bool, tolerance? : Double, relative? : Bool, root_font_size? : Double, em_size? : Double, percent_base? : Double, viewport_width? : Double, viewport_height? : Double, loc~ : SourceLoc) -> Unit

#
Expect::to_have_length

#callsite(autofill(loc))
fn Expect::to_have_length(self : Expect[String], expected : Int, msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_have_length_items

#callsite(autofill(loc))
fn[T] Expect::to_have_length_items(self : Expect[Array[T]], expected : Int, msg? : String, loc~ : SourceLoc) -> Unit raise

#
Expect::to_have_text

#callsite(autofill(loc))
async fn Expect::to_have_text(self : Expect[Locator], expected : String, timeout? : Int, msg? : String, match_mode? : String, normalize? : Bool, loc~ : SourceLoc) -> Unit

#
Expect::to_have_title

#callsite(autofill(loc))
async fn Expect::to_have_title(self : Expect[Page], expected : String, timeout? : Int, msg? : String, match_mode? : String, normalize? : Bool, loc~ : SourceLoc) -> Unit

#
Expect::to_have_url

#callsite(autofill(loc))
async fn Expect::to_have_url(self : Expect[Page], expected : String, timeout? : Int, msg? : String, match_mode? : String, loc~ : SourceLoc) -> Unit

#
Expect::to_have_value

#callsite(autofill(loc))
async fn Expect::to_have_value(self : Expect[Locator], expected : String, timeout? : Int, msg? : String, match_mode? : String, normalize? : Bool, loc~ : SourceLoc) -> Unit

#
Expect::to_match

#callsite(autofill(loc))
fn Expect::to_match(self : Expect[String], pattern : String, msg? : String, loc~ : SourceLoc) -> Unit raise

#
Frame

pub struct Frame {
url_ : String
name_ : String
}

impl Show for Frame

#
Frame::child_frames

fn Frame::child_frames(self : Frame) -> Array[Frame]

Get child frames

#
Frame::content

async fn Frame::content(self : Frame) -> String

Get frame content

#
Frame::goto

async fn Frame::goto(self : Frame, url : String, timeout? : Int, wait_until? : String) -> Response?

Navigate frame to URL

#
Frame::is_detached

fn Frame::is_detached(self : Frame) -> Bool

Check if frame is detached

#
Frame::locator

fn Frame::locator(self : Frame, selector : String) -> Locator

Get locator in frame

#
Frame::name

fn Frame::name(self : Frame) -> String

Get frame name

#
Frame::parent_frame

fn Frame::parent_frame(self : Frame) -> Frame?

Get parent frame

#
Frame::title

async fn Frame::title(self : Frame) -> String

Get frame title

#
Frame::url

fn Frame::url(self : Frame) -> String

Get frame URL

#
Headers

pub struct Headers {
entries : Array[(String, String)]
}

impl Eq for Headers
impl Show for Headers

#
Headers::empty

fn Headers::empty() -> Headers

#
Headers::from_json

fn Headers::from_json(json : Json) -> Headers

#
Headers::from_pairs

fn Headers::from_pairs(entries : Array[(String, String)]) -> Headers

#
Headers::get

fn Headers::get(self : Headers, key : String) -> String?

#
Headers::to_json

fn Headers::to_json(self : Headers) -> Json

#
JSHandle

pub struct JSHandle {
// private fields
}

#
JSHandle::as_element

fn JSHandle::as_element(self : JSHandle) -> ElementHandle?

#
JSHandle::dispose

async fn JSHandle::dispose(self : JSHandle) -> Unit

#
JSHandle::evaluate

async fn JSHandle::evaluate(self : JSHandle, page_function : String, arg? : Json) -> Json

#
JSHandle::evaluate_handle

async fn JSHandle::evaluate_handle(self : JSHandle, page_function : String, arg? : Json) -> JSHandle

#
JSHandle::from_json

fn JSHandle::from_json(value : Json) -> JSHandle

#
JSHandle::from_remote_value

fn JSHandle::from_remote_value(value : Json) -> JSHandle

#
JSHandle::is_null

fn JSHandle::is_null(self : JSHandle) -> Bool

#
JSHandle::json_value

fn JSHandle::json_value(self : JSHandle) -> Json

#
JSHandle::null

fn JSHandle::null() -> JSHandle

#
JSHandle::raw

fn JSHandle::raw(self : JSHandle) -> Json

#
Length

pub enum Length {
Points(Double)
Css(String)
}

impl Eq for Length
impl Show for Length

#
Length::css

fn Length::css(value : String) -> Length

#
Length::points

fn Length::points(value : Double) -> Length

#
Length::to_json

fn Length::to_json(self : Length) -> Json

#
Locator

pub struct Locator {
// private fields
}

#
Locator::all_inner_texts

async fn Locator::all_inner_texts(self : Locator) -> Array[String]

Get all inner texts

#
Locator::all_text_contents

async fn Locator::all_text_contents(self : Locator) -> Array[String]

Get all text contents

#
Locator::blur

async fn Locator::blur(self : Locator, timeout? : Int) -> Unit

Blur element

#
Locator::bounding_box

async fn Locator::bounding_box(self : Locator, timeout? : Int) -> BoundingBox?

Get bounding box

#
Locator::check

async fn Locator::check(self : Locator, force? : Bool, no_wait_after? : Bool, timeout? : Int) -> Unit

Check checkbox

#
Locator::clear

async fn Locator::clear(self : Locator, force? : Bool, no_wait_after? : Bool, timeout? : Int) -> Unit

Clear input

#
Locator::click

async fn Locator::click(self : Locator, button? : String, click_count? : Int, delay? : Int, force? : Bool, modifiers? : Array[String], no_wait_after? : Bool, position? : (Double, Double), timeout? : Int, trial? : Bool) -> Unit

Click element

#
Locator::count

async fn Locator::count(self : Locator) -> Int

Get element count

#
Locator::dblclick

async fn Locator::dblclick(self : Locator, timeout? : Int, force? : Bool) -> Unit

Double click element

#
Locator::evaluate

async fn Locator::evaluate(self : Locator, page_function : String, arg? : Json, timeout? : Int) -> Json

Evaluate JavaScript in element context

#
Locator::evaluate_all

async fn Locator::evaluate_all(self : Locator, page_function : String, arg? : Json) -> Json

Evaluate all matching elements

#
Locator::fill

async fn Locator::fill(self : Locator, value : String, force? : Bool, no_wait_after? : Bool, timeout? : Int) -> Unit

Fill input

#
Locator::filter

fn Locator::filter(self : Locator, has? : Locator, has_not? : Locator, has_text? : String, has_not_text? : String) -> Locator

Filter locator

#
Locator::first

fn Locator::first(self : Locator) -> Locator

Get first element

#
Locator::focus

async fn Locator::focus(self : Locator, timeout? : Int) -> Unit

Focus element

#
Locator::get_attribute

async fn Locator::get_attribute(self : Locator, name : String, timeout? : Int) -> String?

Get attribute

#
Locator::get_by_label

fn Locator::get_by_label(self : Locator, text : String, exact? : Bool) -> Locator

Get by label within this locator

#
Locator::get_by_placeholder

fn Locator::get_by_placeholder(self : Locator, text : String, exact? : Bool) -> Locator

Get by placeholder within this locator

#
Locator::get_by_role

fn Locator::get_by_role(self : Locator, role : String, name? : String, exact? : Bool) -> Locator

Get by role within this locator

#
Locator::get_by_test_id

fn Locator::get_by_test_id(self : Locator, testId : String) -> Locator

Get by test ID within this locator

#
Locator::get_by_text

fn Locator::get_by_text(self : Locator, text : String, exact? : Bool) -> Locator

Get by text within this locator

#
Locator::hover

async fn Locator::hover(self : Locator, force? : Bool, modifiers? : Array[String], position? : (Double, Double), timeout? : Int, trial? : Bool) -> Unit

Hover over element

#
Locator::inner_html

async fn Locator::inner_html(self : Locator, timeout? : Int) -> String

Get inner HTML

#
Locator::inner_text

async fn Locator::inner_text(self : Locator, timeout? : Int) -> String

Get inner text

#
Locator::input_value

async fn Locator::input_value(self : Locator, timeout? : Int) -> String

Get input value

#
Locator::is_checked

async fn Locator::is_checked(self : Locator, timeout? : Int) -> Bool

Check if checkbox is checked

#
Locator::is_disabled

async fn Locator::is_disabled(self : Locator, timeout? : Int) -> Bool

Check if element is disabled

#
Locator::is_editable

async fn Locator::is_editable(self : Locator, timeout? : Int) -> Bool

Check if element is editable

#
Locator::is_enabled

async fn Locator::is_enabled(self : Locator, timeout? : Int) -> Bool

Check if element is enabled

#
Locator::is_hidden

async fn Locator::is_hidden(self : Locator, timeout? : Int) -> Bool

Check if element is hidden

#
Locator::is_visible

async fn Locator::is_visible(self : Locator, timeout? : Int) -> Bool

Check if element is visible

#
Locator::last

fn Locator::last(self : Locator) -> Locator

Get last element

#
Locator::locator

fn Locator::locator(self : Locator, selector : String) -> Locator

Get locator within this locator

#
Locator::nth

fn Locator::nth(self : Locator, index : Int) -> Locator

Get nth element (0-indexed)

#
Locator::press

async fn Locator::press(self : Locator, key : String, delay? : Int, no_wait_after? : Bool, timeout? : Int) -> Unit

Press key

#
Locator::screenshot

async fn Locator::screenshot(self : Locator, path? : String, type_? : String, quality? : Int, omit_background? : Bool, timeout? : Int, scale? : String) -> ResponseBody

Take screenshot of element

#
Locator::scroll_into_view_if_needed

async fn Locator::scroll_into_view_if_needed(self : Locator, timeout? : Int) -> Unit

Scroll element into view

#
Locator::select_option

async fn Locator::select_option(self : Locator, values : Array[SelectOption], force? : Bool, no_wait_after? : Bool, timeout? : Int) -> Array[String]

Select option(s) in dropdown

#
Locator::set_checked

async fn Locator::set_checked(self : Locator, checked : Bool, force? : Bool, no_wait_after? : Bool, timeout? : Int) -> Unit

Set checkbox state

#
Locator::text_content

async fn Locator::text_content(self : Locator, timeout? : Int) -> String?

Get text content

#
Locator::type_

async fn Locator::type_(self : Locator, text : String, delay? : Int, no_wait_after? : Bool, timeout? : Int) -> Unit

Type text (keystroke by keystroke)

#
Locator::uncheck

async fn Locator::uncheck(self : Locator, force? : Bool, no_wait_after? : Bool, timeout? : Int) -> Unit

Uncheck checkbox

#
Locator::wait_for

async fn Locator::wait_for(self : Locator, state? : String, timeout? : Int) -> Unit

Wait for element to be visible/hidden/attached/detached

#
Margin

pub struct Margin {
top : Length?
right : Length?
bottom : Length?
left : Length?
}

impl Eq for Margin
impl Show for Margin

#
Margin::new

fn Margin::new(top? : Length, right? : Length, bottom? : Length, left? : Length) -> Margin

#
Margin::to_json

fn Margin::to_json(self : Margin) -> Json

#
NetworkEvent

pub enum NetworkEvent {
Request(Request)
Response(Response)
ResponseCompleted(Response)
}

#
Page

pub struct Page {
// private fields
}

#
Page::add_script_tag

async fn Page::add_script_tag(self : Page, url? : String, path? : String, content? : String, type_? : String) -> Json

Add script tag

#
Page::add_style_tag

async fn Page::add_style_tag(self : Page, url? : String, path? : String, content? : String) -> Json

Add style tag

#
Page::bring_to_front

async fn Page::bring_to_front(self : Page) -> Unit

Bring page to front

#
Page::check

async fn Page::check(self : Page, selector : String, force? : Bool, no_wait_after? : Bool, timeout? : Int) -> Unit

Check checkbox

#
Page::clear_console

fn Page::clear_console(self : Page) -> Unit

Clear collected console messages

#
Page::click

async fn Page::click(self : Page, selector : String, button? : String, click_count? : Int, delay? : Int, force? : Bool, modifiers? : Array[String], no_wait_after? : Bool, position? : (Double, Double), timeout? : Int, trial? : Bool) -> Unit

Click on element

#
Page::close

async fn Page::close(self : Page, run_before_unload? : Bool) -> Unit

Close page

#
Page::close_with_error_callback

fn Page::close_with_error_callback(self : Page, on_error : (Error) -> Unit) -> Unit

Close page with error callback (for use with defer) Note: This initiates close but doesn't wait for completion

#
Page::console_errors

fn Page::console_errors(self : Page) -> Array[ConsoleMessage]

Get console error messages (level == "error")

#
Page::console_messages

fn Page::console_messages(self : Page) -> Array[ConsoleMessage]

Get all console messages collected since page creation

#
Page::content

async fn Page::content(self : Page) -> String

Get page content (HTML)

#
Page::dblclick

async fn Page::dblclick(self : Page, selector : String, timeout? : Int, force? : Bool) -> Unit

Double click on element

#
Page::ensure_hydration

async fn Page::ensure_hydration(self : Page, timeout? : Int) -> Unit

Ensure Luna island hydration is complete. Calls LUNA_SCAN if available, then waits for the specified timeout. Use after goto() when testing hydrated islands.

#
Page::evaluate

async fn Page::evaluate(self : Page, page_function : String, arg? : Json) -> Json

Evaluate JavaScript in page context. If page_function looks like a function (starts with "function", "async", "(" or "=>"), uses script.callFunction for proper invocation. Otherwise uses script.evaluate.

#
Page::evaluate_handle

async fn Page::evaluate_handle(self : Page, page_function : String, arg? : Json) -> JSHandle

Evaluate JavaScript and return handle

#
Page::expose_function

async fn Page::expose_function(self : Page, name : String, callback : Json) -> Unit

Expose function to page

#
Page::fetch_json

async fn Page::fetch_json(self : Page, url : String, method? : String, body? : String, headers? : Array[(String, String)]) -> (Int, Json)

Fetch a URL and parse response as JSON.

#
Page::fetch_text

async fn Page::fetch_text(self : Page, url : String, method? : String, body? : String, headers? : Array[(String, String)]) -> (Int, String)

Fetch a URL from the page context and return status + body text.

#
Page::fill

async fn Page::fill(self : Page, selector : String, value : String, force? : Bool, no_wait_after? : Bool, timeout? : Int) -> Unit

Fill input

#
Page::fill_input

async fn Page::fill_input(self : Page, selector : String, value : String) -> Unit

Fill an input element by selector. Uses script.evaluate with single-quote escaping to avoid double-quote issues in BiDi expression evaluation.

#
Page::focus

async fn Page::focus(self : Page, selector : String, timeout? : Int) -> Unit

Focus element

#
Page::get_by_alt_text

fn Page::get_by_alt_text(self : Page, text : String, exact? : Bool) -> Locator

Get locator by alt text

#
Page::get_by_label

fn Page::get_by_label(self : Page, text : String, exact? : Bool) -> Locator

Get locator by label

#
Page::get_by_placeholder

fn Page::get_by_placeholder(self : Page, text : String, exact? : Bool) -> Locator

Get locator by placeholder

#
Page::get_by_role

fn Page::get_by_role(self : Page, role : String, name? : String, exact? : Bool) -> Locator

Get locator by role

#
Page::get_by_test_id

fn Page::get_by_test_id(self : Page, testId : String) -> Locator

Get locator by test ID

#
Page::get_by_text

fn Page::get_by_text(self : Page, text : String, exact? : Bool) -> Locator

Get locator by text

#
Page::get_by_title

fn Page::get_by_title(self : Page, text : String, exact? : Bool) -> Locator

Get locator by title

#
Page::go_back

async fn Page::go_back(self : Page, timeout? : Int, wait_until? : String) -> Response?

Go back in history

#
Page::go_forward

async fn Page::go_forward(self : Page, timeout? : Int, wait_until? : String) -> Response?

Go forward in history

#
Page::goto

async fn Page::goto(self : Page, url : String, timeout? : Int, wait_until? : String, referer? : String) -> Response?

Navigate to URL See: https://playwright.dev/docs/api/class-page#page-goto

#
Page::hover

async fn Page::hover(self : Page, selector : String, force? : Bool, modifiers? : Array[String], position? : (Double, Double), timeout? : Int, trial? : Bool) -> Unit

Hover over element

#
Page::is_closed

fn Page::is_closed(self : Page) -> Bool

Check if page is closed

#
Page::locator

fn Page::locator(self : Page, selector : String) -> Locator

Get locator for CSS selector or text

#
Page::on_network_event

fn Page::on_network_event(self : Page, handler : (NetworkEvent) -> Unit) -> Unit

Subscribe network event

#
Page::on_request

fn Page::on_request(self : Page, handler : (Request) -> Unit) -> Unit

Subscribe request event

#
Page::on_response

fn Page::on_response(self : Page, handler : (Response) -> Unit) -> Unit

Subscribe response event

#
Page::on_response_completed

fn Page::on_response_completed(self : Page, handler : (Response) -> Unit) -> Unit

Subscribe response completed event

#
Page::pdf

async fn Page::pdf(self : Page, path? : String, scale? : Double, display_header_footer? : Bool, header_template? : String, footer_template? : String, print_background? : Bool, landscape? : Bool, page_ranges? : String, format? : String, width? : String, height? : String, margin? : Margin, prefer_css_page_size? : Bool) -> ResponseBody

Generate PDF (Chromium only)

#
Page::press

async fn Page::press(self : Page, selector : String, key : String, delay? : Int, no_wait_after? : Bool, timeout? : Int) -> Unit

Press key

#
Page::reload

async fn Page::reload(self : Page, timeout? : Int, wait_until? : String) -> Response?

Reload page

#
Page::screenshot

async fn Page::screenshot(self : Page, path? : String, type_? : String, quality? : Int, full_page? : Bool, clip? : Clip, omit_background? : Bool, timeout? : Int, scale? : String) -> ResponseBody

Take screenshot

#
Page::select_option

async fn Page::select_option(self : Page, selector : String, values : Array[SelectOption], force? : Bool, no_wait_after? : Bool, timeout? : Int) -> Array[String]

Select option(s) in dropdown

#
Page::set_content

async fn Page::set_content(self : Page, html : String, timeout? : Int, wait_until? : String) -> Unit

Set page content

#
Page::set_default_navigation_timeout

fn Page::set_default_navigation_timeout(self : Page, timeout : Int) -> Unit

Set default navigation timeout

#
Page::set_default_timeout

fn Page::set_default_timeout(self : Page, timeout : Int) -> Unit

Set default timeout

#
Page::set_extra_http_headers

async fn Page::set_extra_http_headers(self : Page, headers : Headers) -> Unit

Set extra HTTP headers

#
Page::set_viewport_size

async fn Page::set_viewport_size(self : Page, width : Int, height : Int) -> Unit

Set viewport size

#
Page::shadow_click

async fn Page::shadow_click(self : Page, host_selector : String, inner_selector : String) -> Unit

Click an element inside a shadow DOM host. Uses evaluate to pierce shadow roots.

#
Page::shadow_text

async fn Page::shadow_text(self : Page, host_selector : String, inner_selector : String) -> String

Get text content from an element inside a shadow DOM host.

#
Page::title

async fn Page::title(self : Page) -> String

Get page title

#
Page::type_

async fn Page::type_(self : Page, selector : String, text : String, delay? : Int, no_wait_after? : Bool, timeout? : Int) -> Unit

Type text (keystroke by keystroke)

#
Page::uncheck

async fn Page::uncheck(self : Page, selector : String, force? : Bool, no_wait_after? : Bool, timeout? : Int) -> Unit

Uncheck checkbox

#
Page::url

fn Page::url(self : Page) -> String

Get page URL

#
Page::viewport_size

fn Page::viewport_size(self : Page) -> (Int, Int)?

Get viewport size

#
Page::wait_for_content

async fn Page::wait_for_content(self : Page, text : String, timeout? : Int) -> Bool

Wait until page content contains a specific string. Polls content() until the string is found or timeout.

#
Page::wait_for_function

async fn Page::wait_for_function(self : Page, page_function : String, arg? : Json, polling? : Int, timeout? : Int) -> Json

Wait for function to return truthy value

#
Page::wait_for_load_state

async fn Page::wait_for_load_state(self : Page, state? : String, timeout? : Int) -> Unit

Wait for load state

#
Page::wait_for_navigation

async fn Page::wait_for_navigation(self : Page, timeout? : Int, url? : String, wait_until? : String) -> Response?

Wait for navigation

#
Page::wait_for_request

async fn Page::wait_for_request(self : Page, url : String, timeout? : Int, match_mode? : String, predicate? : (Request) -> Bool) -> Request?

Wait for network request

#
Page::wait_for_response

async fn Page::wait_for_response(self : Page, url : String, timeout? : Int, match_mode? : String, stage? : String, predicate? : (Response) -> Bool) -> Response?

Wait for network response

#
Page::wait_for_selector

async fn Page::wait_for_selector(self : Page, selector : String, state? : String, timeout? : Int, strict? : Bool) -> ElementHandle?

Wait for selector

#
Page::wait_for_timeout

async fn Page::wait_for_timeout(self : Page, timeout : Int) -> Unit

Wait for timeout

#
Page::wait_for_url

async fn Page::wait_for_url(self : Page, url : String, timeout? : Int, wait_until? : String) -> Unit

Wait for URL

#
Request

pub struct Request {
url_ : String
method_ : String
headers_ : Headers
}

impl Show for Request

#
Request::all_headers

async fn Request::all_headers(self : Request) -> Headers

Get all request headers

#
Request::headers

fn Request::headers(self : Request) -> Headers

Get request headers

#
Request::is_navigation_request

fn Request::is_navigation_request(self : Request) -> Bool

Check if request is navigation request

#
Request::method_

fn Request::method_(self : Request) -> String

Get request method

#
Request::post_data

fn Request::post_data(self : Request) -> String?

Get request post data

#
Request::post_data_json

fn Request::post_data_json(self : Request) -> Json

Get request post data as JSON

#
Request::resource_type

fn Request::resource_type(self : Request) -> String

Get resource type

#
Request::response

async fn Request::response(self : Request) -> Response?

Get response for this request

#
Request::url

fn Request::url(self : Request) -> String

Get request URL

#
Response

pub struct Response {
url_ : String
status_ : Int
status_text_ : String
headers_ : Headers
from_cache_ : Bool
from_service_worker_ : Bool
}

impl Show for Response

#
Response::all_headers

async fn Response::all_headers(self : Response) -> Headers

Get all response headers

#
Response::body

async fn Response::body(self : Response) -> ResponseBody

Get response body as buffer

#
Response::frame

fn Response::frame(self : Response) -> Frame

Get frame associated with response

#
Response::from_cache

fn Response::from_cache(self : Response) -> Bool

Check if response was served from cache

#
Response::from_service_worker

fn Response::from_service_worker(self : Response) -> Bool

Check if response was served from service worker

#
Response::headers

fn Response::headers(self : Response) -> Headers

Get response headers

#
Response::json

async fn Response::json(self : Response) -> Json

Get response body as JSON

#
Response::ok

fn Response::ok(self : Response) -> Bool

Check if response is OK (status 200-299)

#
Response::request

fn Response::request(self : Response) -> Request

Get request associated with response

#
Response::status

fn Response::status(self : Response) -> Int

Get response status

#
Response::status_text

fn Response::status_text(self : Response) -> String

Get response status text

#
Response::text

async fn Response::text(self : Response) -> String

Get response body as text

#
Response::url

fn Response::url(self : Response) -> String

Get response URL

#
ResponseBody

pub enum ResponseBody {
Text(String)
JsonValue(Json)
Bytes(Bytes)
}

#
ResponseBody::as_bytes

fn ResponseBody::as_bytes(self : ResponseBody) -> Bytes?

#
ResponseBody::as_json

fn ResponseBody::as_json(self : ResponseBody) -> Json?

#
ResponseBody::as_text

fn ResponseBody::as_text(self : ResponseBody) -> String?

#
ResponseBody::bytes

fn ResponseBody::bytes(value : Bytes) -> ResponseBody

#
ResponseBody::json

fn ResponseBody::json(value : Json) -> ResponseBody

#
ResponseBody::text

fn ResponseBody::text(value : String) -> ResponseBody

#
SelectOption

pub struct SelectOption {
value : String?
label : String?
index : Int?
}

impl Eq for SelectOption

#
SelectOption::from_value

fn SelectOption::from_value(value : String) -> SelectOption

#
SelectOption::new

fn SelectOption::new(value? : String, label? : String, index? : Int) -> SelectOption

#
SelectOption::to_json

fn SelectOption::to_json(self : SelectOption) -> Json

#
chromium

fn chromium() -> BrowserType

#
expect

fn[T] expect(actual : T) -> Expect[T]

#
firefox

fn firefox() -> BrowserType

#
webkit

fn webkit() -> BrowserType