playwright-ruby-client 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/playwright.rb +2 -0
- data/lib/playwright/channel_owners/element_handle.rb +75 -0
- data/lib/playwright/channel_owners/frame.rb +117 -0
- data/lib/playwright/channel_owners/page.rb +68 -11
- data/lib/playwright/channel_owners/request.rb +90 -0
- data/lib/playwright/input_type.rb +19 -0
- data/lib/playwright/input_types/keyboard.rb +32 -0
- data/lib/playwright/input_types/mouse.rb +4 -0
- data/lib/playwright/input_types/touchscreen.rb +4 -0
- data/lib/playwright/javascript/expression.rb +22 -0
- data/lib/playwright/javascript/function.rb +22 -0
- data/lib/playwright/playwright_api.rb +31 -23
- data/lib/playwright/timeout_settings.rb +1 -1
- data/lib/playwright/url_matcher.rb +19 -0
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright_api/accessibility.rb +46 -6
- data/lib/playwright_api/binding_call.rb +6 -6
- data/lib/playwright_api/browser.rb +76 -16
- data/lib/playwright_api/browser_context.rb +284 -30
- data/lib/playwright_api/browser_type.rb +54 -9
- data/lib/playwright_api/cdp_session.rb +23 -1
- data/lib/playwright_api/chromium_browser_context.rb +16 -6
- data/lib/playwright_api/console_message.rb +10 -10
- data/lib/playwright_api/dialog.rb +42 -0
- data/lib/playwright_api/download.rb +19 -4
- data/lib/playwright_api/element_handle.rb +174 -21
- data/lib/playwright_api/file_chooser.rb +8 -0
- data/lib/playwright_api/frame.rb +355 -68
- data/lib/playwright_api/js_handle.rb +45 -9
- data/lib/playwright_api/keyboard.rb +98 -8
- data/lib/playwright_api/mouse.rb +22 -0
- data/lib/playwright_api/page.rb +779 -127
- data/lib/playwright_api/playwright.rb +98 -19
- data/lib/playwright_api/request.rb +70 -23
- data/lib/playwright_api/response.rb +6 -6
- data/lib/playwright_api/route.rb +48 -0
- data/lib/playwright_api/selectors.rb +14 -6
- data/lib/playwright_api/video.rb +8 -0
- data/lib/playwright_api/web_socket.rb +3 -5
- data/lib/playwright_api/worker.rb +12 -0
- metadata +7 -2
@@ -1,5 +1,5 @@
|
|
1
1
|
module Playwright
|
2
|
-
# - extends: [EventEmitter]
|
2
|
+
# - extends: [EventEmitter]
|
3
3
|
#
|
4
4
|
# BrowserContexts provide a way to operate multiple independent browser sessions.
|
5
5
|
#
|
@@ -19,6 +19,26 @@ module Playwright
|
|
19
19
|
# // Dispose context once it's no longer needed.
|
20
20
|
# await context.close();
|
21
21
|
# ```
|
22
|
+
#
|
23
|
+
# ```python async
|
24
|
+
# # create a new incognito browser context
|
25
|
+
# context = await browser.new_context()
|
26
|
+
# # create a new page inside context.
|
27
|
+
# page = await context.new_page()
|
28
|
+
# await page.goto("https://example.com")
|
29
|
+
# # dispose context once it"s no longer needed.
|
30
|
+
# await context.close()
|
31
|
+
# ```
|
32
|
+
#
|
33
|
+
# ```python sync
|
34
|
+
# # create a new incognito browser context
|
35
|
+
# context = browser.new_context()
|
36
|
+
# # create a new page inside context.
|
37
|
+
# page = context.new_page()
|
38
|
+
# page.goto("https://example.com")
|
39
|
+
# # dispose context once it"s no longer needed.
|
40
|
+
# context.close()
|
41
|
+
# ```
|
22
42
|
class BrowserContext < PlaywrightApi
|
23
43
|
|
24
44
|
# Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
|
@@ -28,6 +48,14 @@ module Playwright
|
|
28
48
|
# ```js
|
29
49
|
# await browserContext.addCookies([cookieObject1, cookieObject2]);
|
30
50
|
# ```
|
51
|
+
#
|
52
|
+
# ```python async
|
53
|
+
# await browser_context.add_cookies([cookie_object1, cookie_object2])
|
54
|
+
# ```
|
55
|
+
#
|
56
|
+
# ```python sync
|
57
|
+
# browser_context.add_cookies([cookie_object1, cookie_object2])
|
58
|
+
# ```
|
31
59
|
def add_cookies(cookies)
|
32
60
|
raise NotImplementedError.new('add_cookies is not implemented yet.')
|
33
61
|
end
|
@@ -43,7 +71,7 @@ module Playwright
|
|
43
71
|
# An example of overriding `Math.random` before the page loads:
|
44
72
|
#
|
45
73
|
#
|
46
|
-
# ```js
|
74
|
+
# ```js browser
|
47
75
|
# // preload.js
|
48
76
|
# Math.random = () => 42;
|
49
77
|
# ```
|
@@ -56,7 +84,17 @@ module Playwright
|
|
56
84
|
# });
|
57
85
|
# ```
|
58
86
|
#
|
59
|
-
#
|
87
|
+
# ```python async
|
88
|
+
# # in your playwright script, assuming the preload.js file is in same directory.
|
89
|
+
# await browser_context.add_init_script(path="preload.js")
|
90
|
+
# ```
|
91
|
+
#
|
92
|
+
# ```python sync
|
93
|
+
# # in your playwright script, assuming the preload.js file is in same directory.
|
94
|
+
# browser_context.add_init_script(path="preload.js")
|
95
|
+
# ```
|
96
|
+
#
|
97
|
+
# > NOTE: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
|
60
98
|
# [`method: Page.addInitScript`] is not defined.
|
61
99
|
def add_init_script(script, arg: nil)
|
62
100
|
raise NotImplementedError.new('add_init_script is not implemented yet.')
|
@@ -81,15 +119,29 @@ module Playwright
|
|
81
119
|
# // do stuff ..
|
82
120
|
# context.clearPermissions();
|
83
121
|
# ```
|
122
|
+
#
|
123
|
+
# ```python async
|
124
|
+
# context = await browser.new_context()
|
125
|
+
# await context.grant_permissions(["clipboard-read"])
|
126
|
+
# # do stuff ..
|
127
|
+
# context.clear_permissions()
|
128
|
+
# ```
|
129
|
+
#
|
130
|
+
# ```python sync
|
131
|
+
# context = browser.new_context()
|
132
|
+
# context.grant_permissions(["clipboard-read"])
|
133
|
+
# # do stuff ..
|
134
|
+
# context.clear_permissions()
|
135
|
+
# ```
|
84
136
|
def clear_permissions
|
85
137
|
raise NotImplementedError.new('clear_permissions is not implemented yet.')
|
86
138
|
end
|
87
139
|
|
88
140
|
# Closes the browser context. All the pages that belong to the browser context will be closed.
|
89
141
|
#
|
90
|
-
# >
|
142
|
+
# > NOTE: The default browser context cannot be closed.
|
91
143
|
def close
|
92
|
-
|
144
|
+
wrap_impl(@impl.close)
|
93
145
|
end
|
94
146
|
|
95
147
|
# If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
@@ -131,6 +183,57 @@ module Playwright
|
|
131
183
|
# })();
|
132
184
|
# ```
|
133
185
|
#
|
186
|
+
# ```python async
|
187
|
+
# import asyncio
|
188
|
+
# from playwright.async_api import async_playwright
|
189
|
+
#
|
190
|
+
# async def run(playwright):
|
191
|
+
# webkit = playwright.webkit
|
192
|
+
# browser = await webkit.launch(headless=false)
|
193
|
+
# context = await browser.new_context()
|
194
|
+
# await context.expose_binding("pageURL", lambda source: source["page"].url)
|
195
|
+
# page = await context.new_page()
|
196
|
+
# await page.set_content("""
|
197
|
+
# <script>
|
198
|
+
# async function onClick() {
|
199
|
+
# document.querySelector('div').textContent = await window.pageURL();
|
200
|
+
# }
|
201
|
+
# </script>
|
202
|
+
# <button onclick="onClick()">Click me</button>
|
203
|
+
# <div></div>
|
204
|
+
# """)
|
205
|
+
# await page.click("button")
|
206
|
+
#
|
207
|
+
# async def main():
|
208
|
+
# async with async_playwright() as playwright:
|
209
|
+
# await run(playwright)
|
210
|
+
# asyncio.run(main())
|
211
|
+
# ```
|
212
|
+
#
|
213
|
+
# ```python sync
|
214
|
+
# from playwright.sync_api import sync_playwright
|
215
|
+
#
|
216
|
+
# def run(playwright):
|
217
|
+
# webkit = playwright.webkit
|
218
|
+
# browser = webkit.launch(headless=false)
|
219
|
+
# context = browser.new_context()
|
220
|
+
# context.expose_binding("pageURL", lambda source: source["page"].url)
|
221
|
+
# page = context.new_page()
|
222
|
+
# page.set_content("""
|
223
|
+
# <script>
|
224
|
+
# async function onClick() {
|
225
|
+
# document.querySelector('div').textContent = await window.pageURL();
|
226
|
+
# }
|
227
|
+
# </script>
|
228
|
+
# <button onclick="onClick()">Click me</button>
|
229
|
+
# <div></div>
|
230
|
+
# """)
|
231
|
+
# page.click("button")
|
232
|
+
#
|
233
|
+
# with sync_playwright() as playwright:
|
234
|
+
# run(playwright)
|
235
|
+
# ```
|
236
|
+
#
|
134
237
|
# An example of passing an element handle:
|
135
238
|
#
|
136
239
|
#
|
@@ -146,6 +249,34 @@ module Playwright
|
|
146
249
|
# <div>Or click me</div>
|
147
250
|
# `);
|
148
251
|
# ```
|
252
|
+
#
|
253
|
+
# ```python async
|
254
|
+
# async def print(source, element):
|
255
|
+
# print(await element.text_content())
|
256
|
+
#
|
257
|
+
# await context.expose_binding("clicked", print, handle=true)
|
258
|
+
# await page.set_content("""
|
259
|
+
# <script>
|
260
|
+
# document.addEventListener('click', event => window.clicked(event.target));
|
261
|
+
# </script>
|
262
|
+
# <div>Click me</div>
|
263
|
+
# <div>Or click me</div>
|
264
|
+
# """)
|
265
|
+
# ```
|
266
|
+
#
|
267
|
+
# ```python sync
|
268
|
+
# def print(source, element):
|
269
|
+
# print(element.text_content())
|
270
|
+
#
|
271
|
+
# context.expose_binding("clicked", print, handle=true)
|
272
|
+
# page.set_content("""
|
273
|
+
# <script>
|
274
|
+
# document.addEventListener('click', event => window.clicked(event.target));
|
275
|
+
# </script>
|
276
|
+
# <div>Click me</div>
|
277
|
+
# <div>Or click me</div>
|
278
|
+
# """)
|
279
|
+
# ```
|
149
280
|
def expose_binding(name, callback, handle: nil)
|
150
281
|
raise NotImplementedError.new('expose_binding is not implemented yet.')
|
151
282
|
end
|
@@ -181,6 +312,72 @@ module Playwright
|
|
181
312
|
# await page.click('button');
|
182
313
|
# })();
|
183
314
|
# ```
|
315
|
+
#
|
316
|
+
# ```python async
|
317
|
+
# import asyncio
|
318
|
+
# import hashlib
|
319
|
+
# from playwright.async_api import async_playwright
|
320
|
+
#
|
321
|
+
# async def sha1(text):
|
322
|
+
# m = hashlib.sha1()
|
323
|
+
# m.update(bytes(text, "utf8"))
|
324
|
+
# return m.hexdigest()
|
325
|
+
#
|
326
|
+
#
|
327
|
+
# async def run(playwright):
|
328
|
+
# webkit = playwright.webkit
|
329
|
+
# browser = await webkit.launch(headless=False)
|
330
|
+
# context = await browser.new_context()
|
331
|
+
# await context.expose_function("sha1", sha1)
|
332
|
+
# page = await context.new_page()
|
333
|
+
# await page.set_content("""
|
334
|
+
# <script>
|
335
|
+
# async function onClick() {
|
336
|
+
# document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');
|
337
|
+
# }
|
338
|
+
# </script>
|
339
|
+
# <button onclick="onClick()">Click me</button>
|
340
|
+
# <div></div>
|
341
|
+
# """)
|
342
|
+
# await page.click("button")
|
343
|
+
#
|
344
|
+
# async def main():
|
345
|
+
# async with async_playwright() as playwright:
|
346
|
+
# await run(playwright)
|
347
|
+
# asyncio.run(main())
|
348
|
+
# ```
|
349
|
+
#
|
350
|
+
# ```python sync
|
351
|
+
# import hashlib
|
352
|
+
# from playwright.sync_api import sync_playwright
|
353
|
+
#
|
354
|
+
# def sha1(text):
|
355
|
+
# m = hashlib.sha1()
|
356
|
+
# m.update(bytes(text, "utf8"))
|
357
|
+
# return m.hexdigest()
|
358
|
+
#
|
359
|
+
#
|
360
|
+
# def run(playwright):
|
361
|
+
# webkit = playwright.webkit
|
362
|
+
# browser = webkit.launch(headless=False)
|
363
|
+
# context = browser.new_context()
|
364
|
+
# context.expose_function("sha1", sha1)
|
365
|
+
# page = context.new_page()
|
366
|
+
# page.expose_function("sha1", sha1)
|
367
|
+
# page.set_content("""
|
368
|
+
# <script>
|
369
|
+
# async function onClick() {
|
370
|
+
# document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');
|
371
|
+
# }
|
372
|
+
# </script>
|
373
|
+
# <button onclick="onClick()">Click me</button>
|
374
|
+
# <div></div>
|
375
|
+
# """)
|
376
|
+
# page.click("button")
|
377
|
+
#
|
378
|
+
# with sync_playwright() as playwright:
|
379
|
+
# run(playwright)
|
380
|
+
# ```
|
184
381
|
def expose_function(name, callback)
|
185
382
|
raise NotImplementedError.new('expose_function is not implemented yet.')
|
186
383
|
end
|
@@ -193,13 +390,13 @@ module Playwright
|
|
193
390
|
|
194
391
|
# Creates a new page in the browser context.
|
195
392
|
def new_page
|
196
|
-
|
393
|
+
wrap_impl(@impl.new_page)
|
197
394
|
end
|
198
395
|
|
199
396
|
# Returns all open pages in the context. Non visible pages, such as `"background_page"`, will not be listed here. You can
|
200
397
|
# find them using [`method: ChromiumBrowserContext.backgroundPages`].
|
201
398
|
def pages
|
202
|
-
|
399
|
+
wrap_impl(@impl.pages)
|
203
400
|
end
|
204
401
|
|
205
402
|
# Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
@@ -216,6 +413,22 @@ module Playwright
|
|
216
413
|
# await browser.close();
|
217
414
|
# ```
|
218
415
|
#
|
416
|
+
# ```python async
|
417
|
+
# context = await browser.new_context()
|
418
|
+
# page = await context.new_page()
|
419
|
+
# await context.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())
|
420
|
+
# await page.goto("https://example.com")
|
421
|
+
# await browser.close()
|
422
|
+
# ```
|
423
|
+
#
|
424
|
+
# ```python sync
|
425
|
+
# context = browser.new_context()
|
426
|
+
# page = context.new_page()
|
427
|
+
# context.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())
|
428
|
+
# page.goto("https://example.com")
|
429
|
+
# browser.close()
|
430
|
+
# ```
|
431
|
+
#
|
219
432
|
# or the same snippet using a regex pattern instead:
|
220
433
|
#
|
221
434
|
#
|
@@ -227,10 +440,29 @@ module Playwright
|
|
227
440
|
# await browser.close();
|
228
441
|
# ```
|
229
442
|
#
|
443
|
+
# ```python async
|
444
|
+
# context = await browser.new_context()
|
445
|
+
# page = await context.new_page()
|
446
|
+
# await context.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())
|
447
|
+
# page = await context.new_page()
|
448
|
+
# await page.goto("https://example.com")
|
449
|
+
# await browser.close()
|
450
|
+
# ```
|
451
|
+
#
|
452
|
+
# ```python sync
|
453
|
+
# context = browser.new_context()
|
454
|
+
# page = context.new_page()
|
455
|
+
# context.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())
|
456
|
+
# page = await context.new_page()
|
457
|
+
# page = context.new_page()
|
458
|
+
# page.goto("https://example.com")
|
459
|
+
# browser.close()
|
460
|
+
# ```
|
461
|
+
#
|
230
462
|
# Page routes (set up with [`method: Page.route`]) take precedence over browser context routes when request matches both
|
231
463
|
# handlers.
|
232
464
|
#
|
233
|
-
# >
|
465
|
+
# > NOTE: Enabling routing disables http cache.
|
234
466
|
def route(url, handler)
|
235
467
|
raise NotImplementedError.new('route is not implemented yet.')
|
236
468
|
end
|
@@ -243,7 +475,7 @@ module Playwright
|
|
243
475
|
# - [`method: Page.setContent`]
|
244
476
|
# - [`method: Page.waitForNavigation`]
|
245
477
|
#
|
246
|
-
# >
|
478
|
+
# > NOTE: [`method: Page.setDefaultNavigationTimeout`] and [`method: Page.setDefaultTimeout`] take priority over
|
247
479
|
# [`method: BrowserContext.setDefaultNavigationTimeout`].
|
248
480
|
def set_default_navigation_timeout(timeout)
|
249
481
|
raise NotImplementedError.new('set_default_navigation_timeout is not implemented yet.')
|
@@ -252,7 +484,7 @@ module Playwright
|
|
252
484
|
|
253
485
|
# This setting will change the default maximum time for all the methods accepting `timeout` option.
|
254
486
|
#
|
255
|
-
# >
|
487
|
+
# > NOTE: [`method: Page.setDefaultNavigationTimeout`], [`method: Page.setDefaultTimeout`] and
|
256
488
|
# [`method: BrowserContext.setDefaultNavigationTimeout`] take priority over [`method: BrowserContext.setDefaultTimeout`].
|
257
489
|
def set_default_timeout(timeout)
|
258
490
|
raise NotImplementedError.new('set_default_timeout is not implemented yet.')
|
@@ -263,7 +495,7 @@ module Playwright
|
|
263
495
|
# with page-specific extra HTTP headers set with [`method: Page.setExtraHTTPHeaders`]. If page overrides a particular
|
264
496
|
# header, page-specific header value will be used instead of the browser context header value.
|
265
497
|
#
|
266
|
-
# >
|
498
|
+
# > NOTE: [`method: BrowserContext.setExtraHTTPHeaders`] does not guarantee the order of headers in the outgoing requests.
|
267
499
|
def set_extra_http_headers(headers)
|
268
500
|
raise NotImplementedError.new('set_extra_http_headers is not implemented yet.')
|
269
501
|
end
|
@@ -276,8 +508,16 @@ module Playwright
|
|
276
508
|
# await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667});
|
277
509
|
# ```
|
278
510
|
#
|
279
|
-
#
|
280
|
-
#
|
511
|
+
# ```python async
|
512
|
+
# await browser_context.set_geolocation({"latitude": 59.95, "longitude": 30.31667})
|
513
|
+
# ```
|
514
|
+
#
|
515
|
+
# ```python sync
|
516
|
+
# browser_context.set_geolocation({"latitude": 59.95, "longitude": 30.31667})
|
517
|
+
# ```
|
518
|
+
#
|
519
|
+
# > NOTE: Consider using [`method: BrowserContext.grantPermissions`] to grant permissions for the browser context pages to
|
520
|
+
# read its geolocation.
|
281
521
|
def set_geolocation(geolocation)
|
282
522
|
raise NotImplementedError.new('set_geolocation is not implemented yet.')
|
283
523
|
end
|
@@ -310,49 +550,63 @@ module Playwright
|
|
310
550
|
#
|
311
551
|
#
|
312
552
|
# ```js
|
313
|
-
# const
|
314
|
-
#
|
553
|
+
# const [page, _] = await Promise.all([
|
554
|
+
# context.waitForEvent('page'),
|
555
|
+
# page.click('button')
|
556
|
+
# ]);
|
315
557
|
# ```
|
316
|
-
|
317
|
-
|
558
|
+
#
|
559
|
+
# ```python async
|
560
|
+
# async with context.expect_event("page") as event_info:
|
561
|
+
# await page.click("button")
|
562
|
+
# page = await event_info.value
|
563
|
+
# ```
|
564
|
+
#
|
565
|
+
# ```python sync
|
566
|
+
# with context.expect_event("page") as event_info:
|
567
|
+
# page.click("button")
|
568
|
+
# page = event_info.value
|
569
|
+
# ```
|
570
|
+
def expect_event(event, optionsOrPredicate: nil)
|
571
|
+
raise NotImplementedError.new('expect_event is not implemented yet.')
|
318
572
|
end
|
319
573
|
|
320
574
|
# @nodoc
|
321
|
-
def
|
322
|
-
|
575
|
+
def owner_page=(req)
|
576
|
+
wrap_impl(@impl.owner_page=(req))
|
323
577
|
end
|
324
578
|
|
325
579
|
# @nodoc
|
326
|
-
def
|
327
|
-
|
580
|
+
def after_initialize
|
581
|
+
wrap_impl(@impl.after_initialize)
|
328
582
|
end
|
329
583
|
|
330
584
|
# @nodoc
|
331
|
-
def
|
332
|
-
|
585
|
+
def browser=(req)
|
586
|
+
wrap_impl(@impl.browser=(req))
|
333
587
|
end
|
334
588
|
|
335
589
|
# @nodoc
|
336
590
|
def options=(req)
|
337
|
-
|
591
|
+
wrap_impl(@impl.options=(req))
|
338
592
|
end
|
339
593
|
|
340
594
|
# -- inherited from EventEmitter --
|
341
595
|
# @nodoc
|
342
|
-
def
|
343
|
-
|
596
|
+
def on(event, callback)
|
597
|
+
wrap_impl(@impl.on(event, callback))
|
344
598
|
end
|
345
599
|
|
346
600
|
# -- inherited from EventEmitter --
|
347
601
|
# @nodoc
|
348
|
-
def
|
349
|
-
|
602
|
+
def off(event, callback)
|
603
|
+
wrap_impl(@impl.off(event, callback))
|
350
604
|
end
|
351
605
|
|
352
606
|
# -- inherited from EventEmitter --
|
353
607
|
# @nodoc
|
354
|
-
def
|
355
|
-
|
608
|
+
def once(event, callback)
|
609
|
+
wrap_impl(@impl.once(event, callback))
|
356
610
|
end
|
357
611
|
end
|
358
612
|
end
|