Class: Playwright::Playwright

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/playwright.rb,
sig/playwright.rbs

Overview

Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright to drive automation:

from playwright.sync_api import sync_playwright, Playwright

def run(playwright: Playwright):
    chromium = playwright.chromium # or "firefox" or "webkit".
    browser = chromium.launch()
    page = browser.new_page()
    page.goto("http://example.com")
    # other actions...
    browser.close()

with sync_playwright() as playwright:
    run(playwright)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Attribute Details

#chromiumBrowserType (readonly)

This object can be used to launch or connect to Chromium, returning instances of Browser.

Returns:



24
25
26
# File 'lib/playwright_api/playwright.rb', line 24

def chromium # property
  wrap_impl(@impl.chromium)
end

#devicesHash[untyped, untyped] (readonly)

Returns a dictionary of devices to be used with [method: Browser.newContext] or [method: Browser.newPage].

from playwright.sync_api import sync_playwright, Playwright

def run(playwright: Playwright):
    webkit = playwright.webkit
    iphone = playwright.devices["iPhone 6"]
    browser = webkit.launch()
    context = browser.new_context(**iphone)
    page = context.new_page()
    page.goto("http://example.com")
    # other actions...
    browser.close()

with sync_playwright() as playwright:
    run(playwright)

Returns:

  • (Hash[untyped, untyped])


47
48
49
# File 'lib/playwright_api/playwright.rb', line 47

def devices # property
  wrap_impl(@impl.devices)
end

#firefoxBrowserType (readonly)

This object can be used to launch or connect to Firefox, returning instances of Browser.

Returns:



53
54
55
# File 'lib/playwright_api/playwright.rb', line 53

def firefox # property
  wrap_impl(@impl.firefox)
end

#requestAPIRequest (readonly)

Exposes API that can be used for the Web API testing.

Returns:



59
60
61
# File 'lib/playwright_api/playwright.rb', line 59

def request # property
  wrap_impl(@impl.request)
end

#selectorsSelectors (readonly)

Selectors can be used to install custom selector engines. See extensibility for more information.

Returns:



66
67
68
# File 'lib/playwright_api/playwright.rb', line 66

def selectors # property
  wrap_impl(@impl.selectors)
end

#webkitBrowserType (readonly)

This object can be used to launch or connect to WebKit, returning instances of Browser.

Returns:



72
73
74
# File 'lib/playwright_api/playwright.rb', line 72

def webkit # property
  wrap_impl(@impl.webkit)
end

Instance Method Details

#androidObject



97
98
99
# File 'lib/playwright_api/playwright.rb', line 97

def android
  wrap_impl(@impl.android)
end

#electronObject



102
103
104
# File 'lib/playwright_api/playwright.rb', line 102

def electron
  wrap_impl(@impl.electron)
end

#off(event, callback) ⇒ Object

-- inherited from EventEmitter --



108
109
110
# File 'lib/playwright_api/playwright.rb', line 108

def off(event, callback)
  event_emitter_proxy.off(event, callback)
end

#on(event, callback) ⇒ Object

-- inherited from EventEmitter --



120
121
122
# File 'lib/playwright_api/playwright.rb', line 120

def on(event, callback)
  event_emitter_proxy.on(event, callback)
end

#once(event, callback) ⇒ Object

-- inherited from EventEmitter --



114
115
116
# File 'lib/playwright_api/playwright.rb', line 114

def once(event, callback)
  event_emitter_proxy.once(event, callback)
end

#stopObject

Terminates this instance of Playwright in case it was created bypassing the Python context manager. This is useful in REPL applications.

from playwright.sync_api import sync_playwright

playwright = sync_playwright().start()

browser = playwright.chromium.launch()
page = browser.new_page()
page.goto("https://playwright.dev/")
page.screenshot(path="example.png")
browser.close()

playwright.stop()

Raises:

  • (NotImplementedError)


92
93
94
# File 'lib/playwright_api/playwright.rb', line 92

def stop
  raise NotImplementedError.new('stop is not implemented yet.')
end