playwright-ruby-client 0.0.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/docs/api_coverage.md +159 -101
- data/lib/playwright.rb +5 -2
- data/lib/playwright/{input_types/android_input.rb → android_input_impl.rb} +5 -1
- data/lib/playwright/api_implementation.rb +18 -0
- data/lib/playwright/channel.rb +13 -6
- data/lib/playwright/channel_owner.rb +3 -5
- data/lib/playwright/channel_owners/android.rb +1 -1
- data/lib/playwright/channel_owners/android_device.rb +12 -12
- data/lib/playwright/channel_owners/binding_call.rb +3 -0
- data/lib/playwright/channel_owners/browser.rb +1 -1
- data/lib/playwright/channel_owners/browser_context.rb +157 -3
- data/lib/playwright/channel_owners/dialog.rb +28 -0
- data/lib/playwright/channel_owners/download.rb +27 -0
- data/lib/playwright/channel_owners/element_handle.rb +15 -4
- data/lib/playwright/channel_owners/frame.rb +24 -5
- data/lib/playwright/channel_owners/js_handle.rb +1 -1
- data/lib/playwright/channel_owners/page.rb +367 -29
- data/lib/playwright/channel_owners/playwright.rb +4 -0
- data/lib/playwright/channel_owners/request.rb +35 -3
- data/lib/playwright/channel_owners/response.rb +60 -0
- data/lib/playwright/channel_owners/route.rb +78 -0
- data/lib/playwright/channel_owners/selectors.rb +19 -1
- data/lib/playwright/errors.rb +1 -1
- data/lib/playwright/event_emitter.rb +8 -1
- data/lib/playwright/event_emitter_proxy.rb +49 -0
- data/lib/playwright/file_chooser_impl.rb +23 -0
- data/lib/playwright/http_headers.rb +20 -0
- data/lib/playwright/input_files.rb +1 -1
- data/lib/playwright/{input_types/keyboard.rb → keyboard_impl.rb} +5 -1
- data/lib/playwright/mouse_impl.rb +7 -0
- data/lib/playwright/playwright_api.rb +59 -20
- data/lib/playwright/route_handler_entry.rb +36 -0
- data/lib/playwright/select_option_values.rb +14 -4
- data/lib/playwright/touchscreen_impl.rb +7 -0
- data/lib/playwright/utils.rb +4 -3
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright/wait_helper.rb +1 -1
- data/lib/playwright_api/android.rb +82 -11
- data/lib/playwright_api/android_device.rb +148 -32
- data/lib/playwright_api/android_input.rb +17 -13
- data/lib/playwright_api/android_socket.rb +16 -0
- data/lib/playwright_api/android_web_view.rb +21 -0
- data/lib/playwright_api/binding_call.rb +14 -5
- data/lib/playwright_api/browser.rb +22 -23
- data/lib/playwright_api/browser_context.rb +49 -35
- data/lib/playwright_api/browser_type.rb +24 -64
- data/lib/playwright_api/chromium_browser_context.rb +10 -8
- data/lib/playwright_api/console_message.rb +10 -6
- data/lib/playwright_api/dialog.rb +37 -6
- data/lib/playwright_api/download.rb +28 -11
- data/lib/playwright_api/element_handle.rb +107 -96
- data/lib/playwright_api/file_chooser.rb +18 -10
- data/lib/playwright_api/frame.rb +124 -117
- data/lib/playwright_api/js_handle.rb +20 -22
- data/lib/playwright_api/keyboard.rb +5 -5
- data/lib/playwright_api/page.rb +206 -148
- data/lib/playwright_api/playwright.rb +33 -45
- data/lib/playwright_api/request.rb +11 -12
- data/lib/playwright_api/response.rb +30 -16
- data/lib/playwright_api/route.rb +27 -5
- data/lib/playwright_api/selectors.rb +14 -10
- data/lib/playwright_api/web_socket.rb +10 -1
- data/lib/playwright_api/worker.rb +13 -13
- metadata +16 -7
- data/lib/playwright/input_type.rb +0 -19
- data/lib/playwright/input_types/mouse.rb +0 -4
- data/lib/playwright/input_types/touchscreen.rb +0 -4
@@ -1,41 +1,49 @@
|
|
1
1
|
module Playwright
|
2
|
-
# `FileChooser` objects are dispatched by the page in the [`event: Page.
|
2
|
+
# `FileChooser` objects are dispatched by the page in the [`event: Page.fileChooser`] event.
|
3
3
|
#
|
4
4
|
#
|
5
5
|
# ```js
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# const [fileChooser] = await Promise.all([
|
7
|
+
# page.waitForEvent('filechooser'),
|
8
|
+
# page.click('upload')
|
9
|
+
# ]);
|
10
|
+
# await fileChooser.setFiles('myfile.pdf');
|
9
11
|
# ```
|
10
12
|
#
|
11
13
|
# ```python async
|
12
|
-
# page.
|
14
|
+
# async with page.expect_file_chooser() as fc_info:
|
15
|
+
# await page.click("upload")
|
16
|
+
# file_chooser = await fc_info.value
|
17
|
+
# await file_chooser.set_files("myfile.pdf")
|
13
18
|
# ```
|
14
19
|
#
|
15
20
|
# ```python sync
|
16
|
-
# page.
|
21
|
+
# with page.expect_file_chooser() as fc_info:
|
22
|
+
# page.click("upload")
|
23
|
+
# file_chooser = fc_info.value
|
24
|
+
# file_chooser.set_files("myfile.pdf")
|
17
25
|
# ```
|
18
26
|
class FileChooser < PlaywrightApi
|
19
27
|
|
20
28
|
# Returns input element associated with this file chooser.
|
21
29
|
def element
|
22
|
-
|
30
|
+
wrap_impl(@impl.element)
|
23
31
|
end
|
24
32
|
|
25
33
|
# Returns whether this file chooser accepts multiple files.
|
26
34
|
def multiple?
|
27
|
-
|
35
|
+
wrap_impl(@impl.multiple?)
|
28
36
|
end
|
29
37
|
|
30
38
|
# Returns page this file chooser belongs to.
|
31
39
|
def page
|
32
|
-
|
40
|
+
wrap_impl(@impl.page)
|
33
41
|
end
|
34
42
|
|
35
43
|
# Sets the value of the file input this chooser is associated with. If some of the `filePaths` are relative paths, then
|
36
44
|
# they are resolved relative to the the current working directory. For empty array, clears the selected files.
|
37
45
|
def set_files(files, noWaitAfter: nil, timeout: nil)
|
38
|
-
|
46
|
+
wrap_impl(@impl.set_files(unwrap_impl(files), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
39
47
|
end
|
40
48
|
alias_method :files=, :set_files
|
41
49
|
end
|
data/lib/playwright_api/frame.rb
CHANGED
@@ -3,10 +3,10 @@ module Playwright
|
|
3
3
|
# [`method: Frame.childFrames`] methods.
|
4
4
|
#
|
5
5
|
# `Frame` object's lifecycle is controlled by three events, dispatched on the page object:
|
6
|
-
# - [`event: Page.
|
6
|
+
# - [`event: Page.frameAttached`] - fired when the frame gets attached to the page. A Frame can be attached to the page
|
7
7
|
# only once.
|
8
|
-
# - [`event: Page.
|
9
|
-
# - [`event: Page.
|
8
|
+
# - [`event: Page.frameNavigated`] - fired when the frame commits navigation to a different URL.
|
9
|
+
# - [`event: Page.frameDetached`] - fired when the frame gets detached from the page. A Frame can be detached from the
|
10
10
|
# page only once.
|
11
11
|
#
|
12
12
|
# An example of dumping frame tree:
|
@@ -75,82 +75,6 @@ module Playwright
|
|
75
75
|
# ```
|
76
76
|
class Frame < PlaywrightApi
|
77
77
|
|
78
|
-
# Returns the ElementHandle pointing to the frame element.
|
79
|
-
#
|
80
|
-
# The method finds an element matching the specified selector within the frame. See
|
81
|
-
# [Working with selectors](./selectors.md#working-with-selectors) for more details. If no elements match the selector,
|
82
|
-
# returns `null`.
|
83
|
-
def query_selector(selector)
|
84
|
-
wrap_impl(@impl.query_selector(unwrap_impl(selector)))
|
85
|
-
end
|
86
|
-
|
87
|
-
# Returns the ElementHandles pointing to the frame elements.
|
88
|
-
#
|
89
|
-
# The method finds all elements matching the specified selector within the frame. See
|
90
|
-
# [Working with selectors](./selectors.md#working-with-selectors) for more details. If no elements match the selector,
|
91
|
-
# returns empty array.
|
92
|
-
def query_selector_all(selector)
|
93
|
-
wrap_impl(@impl.query_selector_all(unwrap_impl(selector)))
|
94
|
-
end
|
95
|
-
|
96
|
-
# Returns the return value of `pageFunction`
|
97
|
-
#
|
98
|
-
# The method finds an element matching the specified selector within the frame and passes it as a first argument to
|
99
|
-
# `pageFunction`. See [Working with selectors](./selectors.md#working-with-selectors) for more details. If no elements
|
100
|
-
# match the selector, the method throws an error.
|
101
|
-
#
|
102
|
-
# If `pageFunction` returns a [Promise], then `frame.$eval` would wait for the promise to resolve and return its value.
|
103
|
-
#
|
104
|
-
# Examples:
|
105
|
-
#
|
106
|
-
#
|
107
|
-
# ```js
|
108
|
-
# const searchValue = await frame.$eval('#search', el => el.value);
|
109
|
-
# const preloadHref = await frame.$eval('link[rel=preload]', el => el.href);
|
110
|
-
# const html = await frame.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
|
111
|
-
# ```
|
112
|
-
#
|
113
|
-
# ```python async
|
114
|
-
# search_value = await frame.eval_on_selector("#search", "el => el.value")
|
115
|
-
# preload_href = await frame.eval_on_selector("link[rel=preload]", "el => el.href")
|
116
|
-
# html = await frame.eval_on_selector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello")
|
117
|
-
# ```
|
118
|
-
#
|
119
|
-
# ```python sync
|
120
|
-
# search_value = frame.eval_on_selector("#search", "el => el.value")
|
121
|
-
# preload_href = frame.eval_on_selector("link[rel=preload]", "el => el.href")
|
122
|
-
# html = frame.eval_on_selector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello")
|
123
|
-
# ```
|
124
|
-
def eval_on_selector(selector, pageFunction, arg: nil)
|
125
|
-
wrap_impl(@impl.eval_on_selector(unwrap_impl(selector), unwrap_impl(pageFunction), arg: unwrap_impl(arg)))
|
126
|
-
end
|
127
|
-
|
128
|
-
# Returns the return value of `pageFunction`
|
129
|
-
#
|
130
|
-
# The method finds all elements matching the specified selector within the frame and passes an array of matched elements
|
131
|
-
# as a first argument to `pageFunction`. See [Working with selectors](./selectors.md#working-with-selectors) for more
|
132
|
-
# details.
|
133
|
-
#
|
134
|
-
# If `pageFunction` returns a [Promise], then `frame.$$eval` would wait for the promise to resolve and return its value.
|
135
|
-
#
|
136
|
-
# Examples:
|
137
|
-
#
|
138
|
-
#
|
139
|
-
# ```js
|
140
|
-
# const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);
|
141
|
-
# ```
|
142
|
-
#
|
143
|
-
# ```python async
|
144
|
-
# divs_counts = await frame.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
|
145
|
-
# ```
|
146
|
-
#
|
147
|
-
# ```python sync
|
148
|
-
# divs_counts = frame.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
|
149
|
-
# ```
|
150
|
-
def eval_on_selector_all(selector, pageFunction, arg: nil)
|
151
|
-
wrap_impl(@impl.eval_on_selector_all(unwrap_impl(selector), unwrap_impl(pageFunction), arg: unwrap_impl(arg)))
|
152
|
-
end
|
153
|
-
|
154
78
|
# Returns the added tag when the script's onload fires or when the script content was injected into frame.
|
155
79
|
#
|
156
80
|
# Adds a `<script>` tag into the page with the desired url or content.
|
@@ -293,14 +217,73 @@ module Playwright
|
|
293
217
|
wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
|
294
218
|
end
|
295
219
|
|
296
|
-
# Returns the return value of `
|
220
|
+
# Returns the return value of `expression`.
|
221
|
+
#
|
222
|
+
# The method finds an element matching the specified selector within the frame and passes it as a first argument to
|
223
|
+
# `expression`. See [Working with selectors](./selectors.md) for more details. If no elements match the selector, the
|
224
|
+
# method throws an error.
|
225
|
+
#
|
226
|
+
# If `expression` returns a [Promise], then [`method: Frame.evalOnSelector`] would wait for the promise to resolve and
|
227
|
+
# return its value.
|
228
|
+
#
|
229
|
+
# Examples:
|
230
|
+
#
|
231
|
+
#
|
232
|
+
# ```js
|
233
|
+
# const searchValue = await frame.$eval('#search', el => el.value);
|
234
|
+
# const preloadHref = await frame.$eval('link[rel=preload]', el => el.href);
|
235
|
+
# const html = await frame.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
|
236
|
+
# ```
|
237
|
+
#
|
238
|
+
# ```python async
|
239
|
+
# search_value = await frame.eval_on_selector("#search", "el => el.value")
|
240
|
+
# preload_href = await frame.eval_on_selector("link[rel=preload]", "el => el.href")
|
241
|
+
# html = await frame.eval_on_selector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello")
|
242
|
+
# ```
|
243
|
+
#
|
244
|
+
# ```python sync
|
245
|
+
# search_value = frame.eval_on_selector("#search", "el => el.value")
|
246
|
+
# preload_href = frame.eval_on_selector("link[rel=preload]", "el => el.href")
|
247
|
+
# html = frame.eval_on_selector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello")
|
248
|
+
# ```
|
249
|
+
def eval_on_selector(selector, expression, arg: nil)
|
250
|
+
wrap_impl(@impl.eval_on_selector(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
|
251
|
+
end
|
252
|
+
|
253
|
+
# Returns the return value of `expression`.
|
254
|
+
#
|
255
|
+
# The method finds all elements matching the specified selector within the frame and passes an array of matched elements
|
256
|
+
# as a first argument to `expression`. See [Working with selectors](./selectors.md) for more details.
|
257
|
+
#
|
258
|
+
# If `expression` returns a [Promise], then [`method: Frame.evalOnSelectorAll`] would wait for the promise to resolve and
|
259
|
+
# return its value.
|
260
|
+
#
|
261
|
+
# Examples:
|
262
|
+
#
|
263
|
+
#
|
264
|
+
# ```js
|
265
|
+
# const divsCounts = await frame.$$eval('div', (divs, min) => divs.length >= min, 10);
|
266
|
+
# ```
|
267
|
+
#
|
268
|
+
# ```python async
|
269
|
+
# divs_counts = await frame.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
|
270
|
+
# ```
|
271
|
+
#
|
272
|
+
# ```python sync
|
273
|
+
# divs_counts = frame.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
|
274
|
+
# ```
|
275
|
+
def eval_on_selector_all(selector, expression, arg: nil)
|
276
|
+
wrap_impl(@impl.eval_on_selector_all(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
|
277
|
+
end
|
278
|
+
|
279
|
+
# Returns the return value of `expression`.
|
297
280
|
#
|
298
281
|
# If the function passed to the [`method: Frame.evaluate`] returns a [Promise], then [`method: Frame.evaluate`] would wait
|
299
282
|
# for the promise to resolve and return its value.
|
300
283
|
#
|
301
|
-
# If the function passed to the [`method: Frame.evaluate`] returns a non-[Serializable] value,
|
302
|
-
#
|
303
|
-
#
|
284
|
+
# If the function passed to the [`method: Frame.evaluate`] returns a non-[Serializable] value, then
|
285
|
+
# [`method: Frame.evaluate`] returns `undefined`. Playwright also supports transferring some additional values that are
|
286
|
+
# not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
|
304
287
|
#
|
305
288
|
#
|
306
289
|
# ```js
|
@@ -359,17 +342,17 @@ module Playwright
|
|
359
342
|
# html = frame.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
|
360
343
|
# body_handle.dispose()
|
361
344
|
# ```
|
362
|
-
def evaluate(
|
363
|
-
wrap_impl(@impl.evaluate(unwrap_impl(
|
345
|
+
def evaluate(expression, arg: nil)
|
346
|
+
wrap_impl(@impl.evaluate(unwrap_impl(expression), arg: unwrap_impl(arg)))
|
364
347
|
end
|
365
348
|
|
366
|
-
# Returns the return value of `
|
349
|
+
# Returns the return value of `expression` as a `JSHandle`.
|
367
350
|
#
|
368
|
-
# The only difference between [`method: Frame.evaluate`] and [`method: Frame.evaluateHandle`] is
|
369
|
-
#
|
351
|
+
# The only difference between [`method: Frame.evaluate`] and [`method: Frame.evaluateHandle`] is that
|
352
|
+
# [method: Frame.evaluateHandle`] returns `JSHandle`.
|
370
353
|
#
|
371
|
-
# If the function, passed to the [`method: Frame.evaluateHandle`], returns a [Promise],
|
372
|
-
#
|
354
|
+
# If the function, passed to the [`method: Frame.evaluateHandle`], returns a [Promise], then
|
355
|
+
# [`method: Frame.evaluateHandle`] would wait for the promise to resolve and return its value.
|
373
356
|
#
|
374
357
|
#
|
375
358
|
# ```js
|
@@ -378,7 +361,6 @@ module Playwright
|
|
378
361
|
# ```
|
379
362
|
#
|
380
363
|
# ```python async
|
381
|
-
# # FIXME
|
382
364
|
# a_window_handle = await frame.evaluate_handle("Promise.resolve(window)")
|
383
365
|
# a_window_handle # handle for the window object.
|
384
366
|
# ```
|
@@ -426,14 +408,15 @@ module Playwright
|
|
426
408
|
# print(result_handle.json_value())
|
427
409
|
# result_handle.dispose()
|
428
410
|
# ```
|
429
|
-
def evaluate_handle(
|
430
|
-
wrap_impl(@impl.evaluate_handle(unwrap_impl(
|
411
|
+
def evaluate_handle(expression, arg: nil)
|
412
|
+
wrap_impl(@impl.evaluate_handle(unwrap_impl(expression), arg: unwrap_impl(arg)))
|
431
413
|
end
|
432
414
|
|
433
415
|
# This method waits for an element matching `selector`, waits for [actionability](./actionability.md) checks, focuses the
|
434
|
-
# element, fills it and triggers an `input` event after filling. If the element
|
435
|
-
#
|
436
|
-
#
|
416
|
+
# element, fills it and triggers an `input` event after filling. If the element is inside the `<label>` element that has
|
417
|
+
# associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), that control will be
|
418
|
+
# filled instead. If the element to be filled is not an `<input>`, `<textarea>` or `[contenteditable]` element, this
|
419
|
+
# method throws an error. Note that you can pass an empty string to clear the input field.
|
437
420
|
#
|
438
421
|
# To send fine-grained keyboard events, use [`method: Frame.type`].
|
439
422
|
def fill(selector, value, noWaitAfter: nil, timeout: nil)
|
@@ -556,12 +539,14 @@ module Playwright
|
|
556
539
|
wrap_impl(@impl.enabled?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
|
557
540
|
end
|
558
541
|
|
559
|
-
# Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible).
|
542
|
+
# Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). `selector` that does not
|
543
|
+
# match any elements is considered hidden.
|
560
544
|
def hidden?(selector, timeout: nil)
|
561
545
|
wrap_impl(@impl.hidden?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
|
562
546
|
end
|
563
547
|
|
564
|
-
# Returns whether the element is [visible](./actionability.md#visible).
|
548
|
+
# Returns whether the element is [visible](./actionability.md#visible). `selector` that does not match any elements is
|
549
|
+
# considered not visible.
|
565
550
|
def visible?(selector, timeout: nil)
|
566
551
|
wrap_impl(@impl.visible?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
|
567
552
|
end
|
@@ -610,6 +595,22 @@ module Playwright
|
|
610
595
|
wrap_impl(@impl.press(unwrap_impl(selector), unwrap_impl(key), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
611
596
|
end
|
612
597
|
|
598
|
+
# Returns the ElementHandle pointing to the frame element.
|
599
|
+
#
|
600
|
+
# The method finds an element matching the specified selector within the frame. See
|
601
|
+
# [Working with selectors](./selectors.md) for more details. If no elements match the selector, returns `null`.
|
602
|
+
def query_selector(selector)
|
603
|
+
wrap_impl(@impl.query_selector(unwrap_impl(selector)))
|
604
|
+
end
|
605
|
+
|
606
|
+
# Returns the ElementHandles pointing to the frame elements.
|
607
|
+
#
|
608
|
+
# The method finds all elements matching the specified selector within the frame. See
|
609
|
+
# [Working with selectors](./selectors.md) for more details. If no elements match the selector, returns empty array.
|
610
|
+
def query_selector_all(selector)
|
611
|
+
wrap_impl(@impl.query_selector_all(unwrap_impl(selector)))
|
612
|
+
end
|
613
|
+
|
613
614
|
# Returns the array of option values that have been successfully selected.
|
614
615
|
#
|
615
616
|
# Triggers a `change` and `input` event once all the provided options have been selected. If there's no `<select>` element
|
@@ -646,8 +647,15 @@ module Playwright
|
|
646
647
|
# # multiple selection
|
647
648
|
# frame.select_option("select#colors", value=["red", "green", "blue"])
|
648
649
|
# ```
|
649
|
-
def select_option(
|
650
|
-
|
650
|
+
def select_option(
|
651
|
+
selector,
|
652
|
+
element: nil,
|
653
|
+
index: nil,
|
654
|
+
value: nil,
|
655
|
+
label: nil,
|
656
|
+
noWaitAfter: nil,
|
657
|
+
timeout: nil)
|
658
|
+
wrap_impl(@impl.select_option(unwrap_impl(selector), element: unwrap_impl(element), index: unwrap_impl(index), value: unwrap_impl(value), label: unwrap_impl(label), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
|
651
659
|
end
|
652
660
|
|
653
661
|
def set_content(html, timeout: nil, waitUntil: nil)
|
@@ -747,9 +755,9 @@ module Playwright
|
|
747
755
|
wrap_impl(@impl.url)
|
748
756
|
end
|
749
757
|
|
750
|
-
# Returns when the `
|
758
|
+
# Returns when the `expression` returns a truthy value, returns that value.
|
751
759
|
#
|
752
|
-
# The `waitForFunction` can be used to observe viewport size change:
|
760
|
+
# The [`method: Frame.waitForFunction`] can be used to observe viewport size change:
|
753
761
|
#
|
754
762
|
#
|
755
763
|
# ```js
|
@@ -773,7 +781,7 @@ module Playwright
|
|
773
781
|
# webkit = playwright.webkit
|
774
782
|
# browser = await webkit.launch()
|
775
783
|
# page = await browser.new_page()
|
776
|
-
# await page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);"
|
784
|
+
# await page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
|
777
785
|
# await page.main_frame.wait_for_function("() => window.x > 0")
|
778
786
|
# await browser.close()
|
779
787
|
#
|
@@ -790,7 +798,7 @@ module Playwright
|
|
790
798
|
# webkit = playwright.webkit
|
791
799
|
# browser = webkit.launch()
|
792
800
|
# page = browser.new_page()
|
793
|
-
# page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);"
|
801
|
+
# page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
|
794
802
|
# page.main_frame.wait_for_function("() => window.x > 0")
|
795
803
|
# browser.close()
|
796
804
|
#
|
@@ -815,8 +823,8 @@ module Playwright
|
|
815
823
|
# selector = ".foo"
|
816
824
|
# frame.wait_for_function("selector => !!document.querySelector(selector)", selector)
|
817
825
|
# ```
|
818
|
-
def wait_for_function(
|
819
|
-
wrap_impl(@impl.wait_for_function(unwrap_impl(
|
826
|
+
def wait_for_function(expression, arg: nil, polling: nil, timeout: nil)
|
827
|
+
wrap_impl(@impl.wait_for_function(unwrap_impl(expression), arg: unwrap_impl(arg), polling: unwrap_impl(polling), timeout: unwrap_impl(timeout)))
|
820
828
|
end
|
821
829
|
|
822
830
|
# Waits for the required load state to be reached.
|
@@ -938,7 +946,7 @@ module Playwright
|
|
938
946
|
# run(playwright)
|
939
947
|
# ```
|
940
948
|
def wait_for_selector(selector, state: nil, timeout: nil)
|
941
|
-
|
949
|
+
wrap_impl(@impl.wait_for_selector(unwrap_impl(selector), state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
|
942
950
|
end
|
943
951
|
|
944
952
|
# Waits for the given `timeout` in milliseconds.
|
@@ -954,27 +962,26 @@ module Playwright
|
|
954
962
|
wrap_impl(@impl.detached=(unwrap_impl(req)))
|
955
963
|
end
|
956
964
|
|
965
|
+
# -- inherited from EventEmitter --
|
957
966
|
# @nodoc
|
958
|
-
def
|
959
|
-
|
967
|
+
def off(event, callback)
|
968
|
+
event_emitter_proxy.off(event, callback)
|
960
969
|
end
|
961
970
|
|
962
971
|
# -- inherited from EventEmitter --
|
963
972
|
# @nodoc
|
964
|
-
def
|
965
|
-
|
973
|
+
def once(event, callback)
|
974
|
+
event_emitter_proxy.once(event, callback)
|
966
975
|
end
|
967
976
|
|
968
977
|
# -- inherited from EventEmitter --
|
969
978
|
# @nodoc
|
970
|
-
def
|
971
|
-
|
979
|
+
def on(event, callback)
|
980
|
+
event_emitter_proxy.on(event, callback)
|
972
981
|
end
|
973
982
|
|
974
|
-
|
975
|
-
|
976
|
-
def once(event, callback)
|
977
|
-
wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
|
983
|
+
private def event_emitter_proxy
|
984
|
+
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
978
985
|
end
|
979
986
|
end
|
980
987
|
end
|
@@ -22,7 +22,7 @@ module Playwright
|
|
22
22
|
# [`method: JSHandle.dispose`]. JSHandles are auto-disposed when their origin frame gets navigated or the parent context
|
23
23
|
# gets destroyed.
|
24
24
|
#
|
25
|
-
# JSHandle instances can be used as an argument in [`method: Page
|
25
|
+
# JSHandle instances can be used as an argument in [`method: Page.evalOnSelector`], [`method: Page.evaluate`] and
|
26
26
|
# [`method: Page.evaluateHandle`] methods.
|
27
27
|
class JSHandle < PlaywrightApi
|
28
28
|
|
@@ -36,12 +36,11 @@ module Playwright
|
|
36
36
|
wrap_impl(@impl.dispose)
|
37
37
|
end
|
38
38
|
|
39
|
-
# Returns the return value of `
|
39
|
+
# Returns the return value of `expression`.
|
40
40
|
#
|
41
|
-
# This method passes this handle as the first argument to `
|
41
|
+
# This method passes this handle as the first argument to `expression`.
|
42
42
|
#
|
43
|
-
# If `
|
44
|
-
# value.
|
43
|
+
# If `expression` returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return its value.
|
45
44
|
#
|
46
45
|
# Examples:
|
47
46
|
#
|
@@ -60,23 +59,23 @@ module Playwright
|
|
60
59
|
# tweet_handle = page.query_selector(".tweet .retweets")
|
61
60
|
# assert tweet_handle.evaluate("node => node.innerText") == "10 retweets"
|
62
61
|
# ```
|
63
|
-
def evaluate(
|
64
|
-
wrap_impl(@impl.evaluate(unwrap_impl(
|
62
|
+
def evaluate(expression, arg: nil)
|
63
|
+
wrap_impl(@impl.evaluate(unwrap_impl(expression), arg: unwrap_impl(arg)))
|
65
64
|
end
|
66
65
|
|
67
|
-
# Returns the return value of `
|
66
|
+
# Returns the return value of `expression` as a `JSHandle`.
|
68
67
|
#
|
69
|
-
# This method passes this handle as the first argument to `
|
68
|
+
# This method passes this handle as the first argument to `expression`.
|
70
69
|
#
|
71
70
|
# The only difference between `jsHandle.evaluate` and `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` returns
|
72
|
-
#
|
71
|
+
# `JSHandle`.
|
73
72
|
#
|
74
73
|
# If the function passed to the `jsHandle.evaluateHandle` returns a [Promise], then `jsHandle.evaluateHandle` would wait
|
75
74
|
# for the promise to resolve and return its value.
|
76
75
|
#
|
77
76
|
# See [`method: Page.evaluateHandle`] for more details.
|
78
|
-
def evaluate_handle(
|
79
|
-
wrap_impl(@impl.evaluate_handle(unwrap_impl(
|
77
|
+
def evaluate_handle(expression, arg: nil)
|
78
|
+
wrap_impl(@impl.evaluate_handle(unwrap_impl(expression), arg: unwrap_impl(arg)))
|
80
79
|
end
|
81
80
|
|
82
81
|
# The method returns a map with **own property names** as keys and JSHandle instances for the property values.
|
@@ -123,27 +122,26 @@ module Playwright
|
|
123
122
|
wrap_impl(@impl.json_value)
|
124
123
|
end
|
125
124
|
|
125
|
+
# -- inherited from EventEmitter --
|
126
126
|
# @nodoc
|
127
|
-
def
|
128
|
-
|
127
|
+
def off(event, callback)
|
128
|
+
event_emitter_proxy.off(event, callback)
|
129
129
|
end
|
130
130
|
|
131
131
|
# -- inherited from EventEmitter --
|
132
132
|
# @nodoc
|
133
|
-
def
|
134
|
-
|
133
|
+
def once(event, callback)
|
134
|
+
event_emitter_proxy.once(event, callback)
|
135
135
|
end
|
136
136
|
|
137
137
|
# -- inherited from EventEmitter --
|
138
138
|
# @nodoc
|
139
|
-
def
|
140
|
-
|
139
|
+
def on(event, callback)
|
140
|
+
event_emitter_proxy.on(event, callback)
|
141
141
|
end
|
142
142
|
|
143
|
-
|
144
|
-
|
145
|
-
def once(event, callback)
|
146
|
-
wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
|
143
|
+
private def event_emitter_proxy
|
144
|
+
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
147
145
|
end
|
148
146
|
end
|
149
147
|
end
|