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

def run(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



90
91
92
# File 'lib/playwright_api/playwright.rb', line 90

def android
  wrap_impl(@impl.android)
end

#chromiumObject

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



22
23
24
# File 'lib/playwright_api/playwright.rb', line 22

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

def run(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)

“‘



44
45
46
# File 'lib/playwright_api/playwright.rb', line 44

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

#electronObject



95
96
97
# File 'lib/playwright_api/playwright.rb', line 95

def electron
  wrap_impl(@impl.electron)
end

#firefoxObject

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



49
50
51
# File 'lib/playwright_api/playwright.rb', line 49

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

#off(event, callback) ⇒ Object

– inherited from EventEmitter –



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

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

#on(event, callback) ⇒ Object

– inherited from EventEmitter –



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

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

#once(event, callback) ⇒ Object

– inherited from EventEmitter –



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

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)


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

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

#selectorsObject

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



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

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(“whatsmyuseragent.org/”) >>> page.screenshot(path=“example.png”) >>> browser.close()

>>> playwright.stop() “‘

Raises:

  • (NotImplementedError)


85
86
87
# File 'lib/playwright_api/playwright.rb', line 85

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`.



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

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