Class: Playwright::Playwright
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::Playwright
- 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
- #android ⇒ Object
-
#chromium ⇒ Object
This object can be used to launch or connect to Chromium, returning instances of ‘Browser`.
-
#devices ⇒ Object
Returns a dictionary of devices to be used with [‘method: Browser.newContext`] or [`method: Browser.newPage`].
- #electron ⇒ Object
-
#firefox ⇒ Object
This object can be used to launch or connect to Firefox, returning instances of ‘Browser`.
-
#off(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#on(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#once(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#request ⇒ Object
Exposes API that can be used for the Web API testing.
-
#selectors ⇒ Object
Selectors can be used to install custom selector engines.
-
#stop ⇒ Object
Terminates this instance of Playwright in case it was created bypassing the Python context manager.
-
#webkit ⇒ Object
This object can be used to launch or connect to WebKit, returning instances of ‘Browser`.
Methods inherited from PlaywrightApi
Constructor Details
This class inherits a constructor from Playwright::PlaywrightApi
Instance Method Details
#android ⇒ Object
97 98 99 |
# File 'lib/playwright_api/playwright.rb', line 97 def android wrap_impl(@impl.android) end |
#chromium ⇒ Object
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 |
#devices ⇒ Object
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 |
#electron ⇒ Object
102 103 104 |
# File 'lib/playwright_api/playwright.rb', line 102 def electron wrap_impl(@impl.electron) end |
#firefox ⇒ Object
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 –
114 115 116 |
# File 'lib/playwright_api/playwright.rb', line 114 def off(event, callback) event_emitter_proxy.off(event, callback) end |
#on(event, callback) ⇒ Object
– inherited from EventEmitter –
108 109 110 |
# File 'lib/playwright_api/playwright.rb', line 108 def on(event, callback) event_emitter_proxy.on(event, callback) end |
#once(event, callback) ⇒ Object
– inherited from EventEmitter –
120 121 122 |
# File 'lib/playwright_api/playwright.rb', line 120 def once(event, callback) event_emitter_proxy.once(event, callback) end |
#request ⇒ Object
Exposes API that can be used for the Web API testing.
59 60 61 |
# File 'lib/playwright_api/playwright.rb', line 59 def request # property raise NotImplementedError.new('request is not implemented yet.') end |
#selectors ⇒ Object
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 |
#stop ⇒ Object
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() “‘
92 93 94 |
# File 'lib/playwright_api/playwright.rb', line 92 def stop raise NotImplementedError.new('stop is not implemented yet.') end |
#webkit ⇒ Object
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 |