Class: Playwright::Playwright
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::Playwright
- 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
-
#chromium ⇒ BrowserType
readonly
This object can be used to launch or connect to Chromium, returning instances of
Browser. -
#devices ⇒ Hash[untyped, untyped]
readonly
Returns a dictionary of devices to be used with [
method: Browser.newContext] or [method: Browser.newPage]. -
#firefox ⇒ BrowserType
readonly
This object can be used to launch or connect to Firefox, returning instances of
Browser. -
#request ⇒ APIRequest
readonly
Exposes API that can be used for the Web API testing.
-
#selectors ⇒ Selectors
readonly
Selectors can be used to install custom selector engines.
-
#webkit ⇒ BrowserType
readonly
This object can be used to launch or connect to WebKit, returning instances of
Browser.
Instance Method Summary collapse
- #android ⇒ Object
- #electron ⇒ Object
-
#off(event, callback) ⇒ Object
-- inherited from EventEmitter --.
-
#on(event, callback) ⇒ Object
-- inherited from EventEmitter --.
-
#once(event, callback) ⇒ Object
-- inherited from EventEmitter --.
-
#stop ⇒ Object
Terminates this instance of Playwright in case it was created bypassing the Python context manager.
Methods inherited from PlaywrightApi
Constructor Details
This class inherits a constructor from Playwright::PlaywrightApi
Instance Attribute Details
#chromium ⇒ BrowserType (readonly)
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 ⇒ Hash[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)
47 48 49 |
# File 'lib/playwright_api/playwright.rb', line 47 def devices # property wrap_impl(@impl.devices) end |
#firefox ⇒ BrowserType (readonly)
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 |
#request ⇒ APIRequest (readonly)
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 wrap_impl(@impl.request) end |
#selectors ⇒ Selectors (readonly)
Selectors can be used to install custom selector engines. See extensibility for more information.
66 67 68 |
# File 'lib/playwright_api/playwright.rb', line 66 def selectors # property wrap_impl(@impl.selectors) end |
#webkit ⇒ BrowserType (readonly)
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 |
Instance Method Details
#android ⇒ Object
97 98 99 |
# File 'lib/playwright_api/playwright.rb', line 97 def android wrap_impl(@impl.android) end |
#electron ⇒ Object
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 |
#stop ⇒ Object
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()
92 93 94 |
# File 'lib/playwright_api/playwright.rb', line 92 def stop raise NotImplementedError.new('stop is not implemented yet.') end |