playwright-ruby-client 0.3.0 → 0.5.2

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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -5
  3. data/docs/api_coverage.md +14 -25
  4. data/lib/playwright/channel.rb +19 -9
  5. data/lib/playwright/channel_owners/artifact.rb +30 -0
  6. data/lib/playwright/channel_owners/browser.rb +21 -0
  7. data/lib/playwright/channel_owners/browser_context.rb +5 -0
  8. data/lib/playwright/channel_owners/browser_type.rb +28 -0
  9. data/lib/playwright/channel_owners/element_handle.rb +1 -1
  10. data/lib/playwright/channel_owners/frame.rb +25 -2
  11. data/lib/playwright/channel_owners/js_handle.rb +2 -2
  12. data/lib/playwright/channel_owners/page.rb +78 -15
  13. data/lib/playwright/channel_owners/playwright.rb +22 -29
  14. data/lib/playwright/channel_owners/stream.rb +15 -0
  15. data/lib/playwright/connection.rb +11 -32
  16. data/lib/playwright/download.rb +27 -0
  17. data/lib/playwright/errors.rb +6 -0
  18. data/lib/playwright/events.rb +2 -5
  19. data/lib/playwright/keyboard_impl.rb +1 -1
  20. data/lib/playwright/mouse_impl.rb +41 -0
  21. data/lib/playwright/route_handler_entry.rb +1 -9
  22. data/lib/playwright/transport.rb +27 -6
  23. data/lib/playwright/url_matcher.rb +1 -1
  24. data/lib/playwright/utils.rb +8 -0
  25. data/lib/playwright/version.rb +1 -1
  26. data/lib/playwright/video.rb +51 -0
  27. data/lib/playwright/wait_helper.rb +2 -2
  28. data/lib/playwright.rb +47 -9
  29. data/lib/playwright_api/accessibility.rb +39 -1
  30. data/lib/playwright_api/android.rb +10 -10
  31. data/lib/playwright_api/android_device.rb +10 -9
  32. data/lib/playwright_api/browser.rb +83 -8
  33. data/lib/playwright_api/browser_context.rb +163 -15
  34. data/lib/playwright_api/browser_type.rb +35 -4
  35. data/lib/playwright_api/console_message.rb +6 -6
  36. data/lib/playwright_api/dialog.rb +28 -8
  37. data/lib/playwright_api/element_handle.rb +111 -37
  38. data/lib/playwright_api/file_chooser.rb +5 -0
  39. data/lib/playwright_api/frame.rb +228 -37
  40. data/lib/playwright_api/js_handle.rb +26 -3
  41. data/lib/playwright_api/keyboard.rb +48 -1
  42. data/lib/playwright_api/mouse.rb +26 -5
  43. data/lib/playwright_api/page.rb +456 -48
  44. data/lib/playwright_api/playwright.rb +26 -9
  45. data/lib/playwright_api/request.rb +34 -6
  46. data/lib/playwright_api/response.rb +8 -8
  47. data/lib/playwright_api/route.rb +30 -6
  48. data/lib/playwright_api/selectors.rb +32 -6
  49. data/lib/playwright_api/touchscreen.rb +1 -1
  50. data/lib/playwright_api/worker.rb +25 -1
  51. data/playwright.gemspec +4 -2
  52. metadata +37 -14
  53. data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
  54. data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
  55. data/lib/playwright/channel_owners/download.rb +0 -27
  56. data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
  57. data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
  58. data/lib/playwright_api/binding_call.rb +0 -32
  59. data/lib/playwright_api/chromium_browser_context.rb +0 -59
  60. data/lib/playwright_api/download.rb +0 -95
  61. data/lib/playwright_api/video.rb +0 -24
@@ -20,6 +20,24 @@ module Playwright
20
20
  # })();
21
21
  # ```
22
22
  #
23
+ # ```java
24
+ # import com.microsoft.playwright.*;
25
+ #
26
+ # public class Example {
27
+ # public static void main(String[] args) {
28
+ # try (Playwright playwright = Playwright.create()) {
29
+ # BrowserType chromium = playwright.chromium();
30
+ # Browser browser = chromium.launch();
31
+ # Page page = browser.newPage();
32
+ # page.navigate("https://example.com");
33
+ # ElementHandle hrefElement = page.querySelector("a");
34
+ # hrefElement.click();
35
+ # // ...
36
+ # }
37
+ # }
38
+ # }
39
+ # ```
40
+ #
23
41
  # ```python async
24
42
  # import asyncio
25
43
  # from playwright.async_api import async_playwright
@@ -81,6 +99,11 @@ module Playwright
81
99
  # await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
82
100
  # ```
83
101
  #
102
+ # ```java
103
+ # BoundingBox box = elementHandle.boundingBox();
104
+ # page.mouse().click(box.x + box.width / 2, box.y + box.height / 2);
105
+ # ```
106
+ #
84
107
  # ```python async
85
108
  # box = await element_handle.bounding_box()
86
109
  # await page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
@@ -95,20 +118,20 @@ module Playwright
95
118
  end
96
119
 
97
120
  # This method checks the element by performing the following steps:
98
- # 1. Ensure that element is a checkbox or a radio input. If not, this method rejects. If the element is already
99
- # checked, this method returns immediately.
121
+ # 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already checked,
122
+ # this method returns immediately.
100
123
  # 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
101
124
  # 1. Scroll the element into view if needed.
102
125
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
103
126
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
104
- # 1. Ensure that the element is now checked. If not, this method rejects.
127
+ # 1. Ensure that the element is now checked. If not, this method throws.
105
128
  #
106
- # If the element is detached from the DOM at any moment during the action, this method rejects.
129
+ # If the element is detached from the DOM at any moment during the action, this method throws.
107
130
  #
108
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
109
- # Passing zero timeout disables this.
110
- def check(force: nil, noWaitAfter: nil, timeout: nil)
111
- wrap_impl(@impl.check(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
131
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
132
+ # zero timeout disables this.
133
+ def check(force: nil, noWaitAfter: nil, position: nil, timeout: nil)
134
+ wrap_impl(@impl.check(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout)))
112
135
  end
113
136
 
114
137
  # This method clicks the element by performing the following steps:
@@ -117,10 +140,10 @@ module Playwright
117
140
  # 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
118
141
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
119
142
  #
120
- # If the element is detached from the DOM at any moment during the action, this method rejects.
143
+ # If the element is detached from the DOM at any moment during the action, this method throws.
121
144
  #
122
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
123
- # Passing zero timeout disables this.
145
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
146
+ # zero timeout disables this.
124
147
  def click(
125
148
  button: nil,
126
149
  clickCount: nil,
@@ -143,12 +166,12 @@ module Playwright
143
166
  # 1. Scroll the element into view if needed.
144
167
  # 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
145
168
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
146
- # first click of the `dblclick()` triggers a navigation event, this method will reject.
169
+ # first click of the `dblclick()` triggers a navigation event, this method will throw.
147
170
  #
148
- # If the element is detached from the DOM at any moment during the action, this method rejects.
171
+ # If the element is detached from the DOM at any moment during the action, this method throws.
149
172
  #
150
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
151
- # Passing zero timeout disables this.
173
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
174
+ # zero timeout disables this.
152
175
  #
153
176
  # > NOTE: `elementHandle.dblclick()` dispatches two `click` events and a single `dblclick` event.
154
177
  def dblclick(
@@ -162,8 +185,8 @@ module Playwright
162
185
  wrap_impl(@impl.dblclick(button: unwrap_impl(button), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout)))
163
186
  end
164
187
 
165
- # The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
166
- # is dispatched. This is equivalend to calling
188
+ # The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
189
+ # `click` is dispatched. This is equivalent to calling
167
190
  # [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
168
191
  #
169
192
  #
@@ -171,6 +194,10 @@ module Playwright
171
194
  # await elementHandle.dispatchEvent('click');
172
195
  # ```
173
196
  #
197
+ # ```java
198
+ # elementHandle.dispatchEvent("click");
199
+ # ```
200
+ #
174
201
  # ```python async
175
202
  # await element_handle.dispatch_event("click")
176
203
  # ```
@@ -200,6 +227,14 @@ module Playwright
200
227
  # await elementHandle.dispatchEvent('dragstart', { dataTransfer });
201
228
  # ```
202
229
  #
230
+ # ```java
231
+ # // Note you can only create DataTransfer in Chromium and Firefox
232
+ # JSHandle dataTransfer = page.evaluateHandle("() => new DataTransfer()");
233
+ # Map<String, Object> arg = new HashMap<>();
234
+ # arg.put("dataTransfer", dataTransfer);
235
+ # elementHandle.dispatchEvent("dragstart", arg);
236
+ # ```
237
+ #
203
238
  # ```python async
204
239
  # # note you can only create data_transfer in chromium and firefox
205
240
  # data_transfer = await page.evaluate_handle("new DataTransfer()")
@@ -233,6 +268,12 @@ module Playwright
233
268
  # expect(await tweetHandle.$eval('.retweets', node => node.innerText)).toBe('10');
234
269
  # ```
235
270
  #
271
+ # ```java
272
+ # ElementHandle tweetHandle = page.querySelector(".tweet");
273
+ # assertEquals("100", tweetHandle.evalOnSelector(".like", "node => node.innerText"));
274
+ # assertEquals("10", tweetHandle.evalOnSelector(".retweets", "node => node.innerText"));
275
+ # ```
276
+ #
236
277
  # ```python async
237
278
  # tweet_handle = await page.query_selector(".tweet")
238
279
  # assert await tweet_handle.eval_on_selector(".like", "node => node.innerText") == "100"
@@ -271,6 +312,11 @@ module Playwright
271
312
  # expect(await feedHandle.$$eval('.tweet', nodes => nodes.map(n => n.innerText))).toEqual(['Hello!', 'Hi!']);
272
313
  # ```
273
314
  #
315
+ # ```java
316
+ # ElementHandle feedHandle = page.querySelector(".feed");
317
+ # assertEquals(Arrays.asList("Hello!", "Hi!"), feedHandle.evalOnSelectorAll(".tweet", "nodes => nodes.map(n => n.innerText)"));
318
+ # ```
319
+ #
274
320
  # ```python async
275
321
  # feed_handle = await page.query_selector(".feed")
276
322
  # assert await feed_handle.eval_on_selector_all(".tweet", "nodes => nodes.map(n => n.innerText)") == ["hello!", "hi!"]
@@ -310,10 +356,10 @@ module Playwright
310
356
  # 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
311
357
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
312
358
  #
313
- # If the element is detached from the DOM at any moment during the action, this method rejects.
359
+ # If the element is detached from the DOM at any moment during the action, this method throws.
314
360
  #
315
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
316
- # Passing zero timeout disables this.
361
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
362
+ # zero timeout disables this.
317
363
  def hover(force: nil, modifiers: nil, position: nil, timeout: nil)
318
364
  wrap_impl(@impl.hover(force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), position: unwrap_impl(position), timeout: unwrap_impl(timeout)))
319
365
  end
@@ -379,7 +425,7 @@ module Playwright
379
425
  # If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
380
426
  # texts.
381
427
  #
382
- # Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When speficied with the
428
+ # Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
383
429
  # modifier, modifier is pressed and being held while the subsequent key is being pressed.
384
430
  def press(key, delay: nil, noWaitAfter: nil, timeout: nil)
385
431
  wrap_impl(@impl.press(unwrap_impl(key), delay: unwrap_impl(delay), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
@@ -439,6 +485,15 @@ module Playwright
439
485
  # handle.selectOption(['red', 'green', 'blue']);
440
486
  # ```
441
487
  #
488
+ # ```java
489
+ # // single selection matching the value
490
+ # handle.selectOption("blue");
491
+ # // single selection matching the label
492
+ # handle.selectOption(new SelectOption().setLabel("Blue"));
493
+ # // multiple selection
494
+ # handle.selectOption(new String[] {"red", "green", "blue"});
495
+ # ```
496
+ #
442
497
  # ```python async
443
498
  # # single selection matching the value
444
499
  # await handle.select_option("blue")
@@ -499,10 +554,10 @@ module Playwright
499
554
  # 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
500
555
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
501
556
  #
502
- # If the element is detached from the DOM at any moment during the action, this method rejects.
557
+ # If the element is detached from the DOM at any moment during the action, this method throws.
503
558
  #
504
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
505
- # Passing zero timeout disables this.
559
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
560
+ # zero timeout disables this.
506
561
  #
507
562
  # > NOTE: `elementHandle.tap()` requires that the `hasTouch` option of the browser context be set to true.
508
563
  def tap_point(
@@ -529,6 +584,11 @@ module Playwright
529
584
  # await elementHandle.type('World', {delay: 100}); // Types slower, like a user
530
585
  # ```
531
586
  #
587
+ # ```java
588
+ # elementHandle.type("Hello"); // Types instantly
589
+ # elementHandle.type("World", new ElementHandle.TypeOptions().setDelay(100)); // Types slower, like a user
590
+ # ```
591
+ #
532
592
  # ```python async
533
593
  # await element_handle.type("hello") # types instantly
534
594
  # await element_handle.type("world", delay=100) # types slower, like a user
@@ -548,6 +608,12 @@ module Playwright
548
608
  # await elementHandle.press('Enter');
549
609
  # ```
550
610
  #
611
+ # ```java
612
+ # ElementHandle elementHandle = page.querySelector("input");
613
+ # elementHandle.type("some text");
614
+ # elementHandle.press("Enter");
615
+ # ```
616
+ #
551
617
  # ```python async
552
618
  # element_handle = await page.query_selector("input")
553
619
  # await element_handle.type("some text")
@@ -564,20 +630,20 @@ module Playwright
564
630
  end
565
631
 
566
632
  # This method checks the element by performing the following steps:
567
- # 1. Ensure that element is a checkbox or a radio input. If not, this method rejects. If the element is already
633
+ # 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already
568
634
  # unchecked, this method returns immediately.
569
635
  # 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
570
636
  # 1. Scroll the element into view if needed.
571
637
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
572
638
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
573
- # 1. Ensure that the element is now unchecked. If not, this method rejects.
639
+ # 1. Ensure that the element is now unchecked. If not, this method throws.
574
640
  #
575
- # If the element is detached from the DOM at any moment during the action, this method rejects.
641
+ # If the element is detached from the DOM at any moment during the action, this method throws.
576
642
  #
577
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
578
- # Passing zero timeout disables this.
579
- def uncheck(force: nil, noWaitAfter: nil, timeout: nil)
580
- wrap_impl(@impl.uncheck(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
643
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
644
+ # zero timeout disables this.
645
+ def uncheck(force: nil, noWaitAfter: nil, position: nil, timeout: nil)
646
+ wrap_impl(@impl.uncheck(force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout)))
581
647
  end
582
648
 
583
649
  # Returns when the element satisfies the `state`.
@@ -614,6 +680,14 @@ module Playwright
614
680
  # const span = await div.waitForSelector('span', { state: 'attached' });
615
681
  # ```
616
682
  #
683
+ # ```java
684
+ # page.setContent("<div><span></span></div>");
685
+ # ElementHandle div = page.querySelector("div");
686
+ # // Waiting for the "span" selector relative to the div.
687
+ # ElementHandle span = div.waitForSelector("span", new ElementHandle.WaitForSelectorOptions()
688
+ # .setState(WaitForSelectorState.ATTACHED));
689
+ # ```
690
+ #
617
691
  # ```python async
618
692
  # await page.set_content("<div><span></span></div>")
619
693
  # div = await page.query_selector("div")
@@ -633,12 +707,6 @@ module Playwright
633
707
  wrap_impl(@impl.wait_for_selector(unwrap_impl(selector), state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
634
708
  end
635
709
 
636
- # -- inherited from EventEmitter --
637
- # @nodoc
638
- def off(event, callback)
639
- event_emitter_proxy.off(event, callback)
640
- end
641
-
642
710
  # -- inherited from EventEmitter --
643
711
  # @nodoc
644
712
  def once(event, callback)
@@ -651,6 +719,12 @@ module Playwright
651
719
  event_emitter_proxy.on(event, callback)
652
720
  end
653
721
 
722
+ # -- inherited from EventEmitter --
723
+ # @nodoc
724
+ def off(event, callback)
725
+ event_emitter_proxy.off(event, callback)
726
+ end
727
+
654
728
  private def event_emitter_proxy
655
729
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
656
730
  end
@@ -10,6 +10,11 @@ module Playwright
10
10
  # await fileChooser.setFiles('myfile.pdf');
11
11
  # ```
12
12
  #
13
+ # ```java
14
+ # FileChooser fileChooser = page.waitForFileChooser(() -> page.click("upload"));
15
+ # fileChooser.setFiles(Paths.get("myfile.pdf"));
16
+ # ```
17
+ #
13
18
  # ```python async
14
19
  # async with page.expect_file_chooser() as fc_info:
15
20
  # await page.click("upload")