Class: Playwright::Playwright

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

Overview

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

“‘python sync 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 Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#androidObject



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

def android
  wrap_impl(@impl.android)
end

#chromiumObject

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



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

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

#devicesObject

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

“‘python sync 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)

“‘



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

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

#electronObject



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

def electron
  wrap_impl(@impl.electron)
end

#firefoxObject

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



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

def firefox # property
  wrap_impl(@impl.firefox)
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

#requestObject

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

Raises:

  • (NotImplementedError)


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

def request # property
  raise NotImplementedError.new('request is not implemented yet.')
end

#selectorsObject

Selectors can be used to install custom selector engines. See [extensibility](../extensibility.md) for more information.



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

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

#stopObject

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

“‘py from playwright.sync_api import sync_playwright

playwright = sync_playwright().start()

browser = playwright.chromium.launch() page = browser.new_page() page.goto(“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

#webkitObject

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



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

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