playwright-ruby-client 1.19.0 → 1.20.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfbbc528927aa551597f30f0abb057a13609726f473cfd6c625a97d135d0b705
4
- data.tar.gz: f3f8dda3439bfaa0d3a8796ee8ed6eb453ae9934e9bf0b1768a8a0c9a62d5e4f
3
+ metadata.gz: a0ac92a21e56cb8136a67c37b4f0a7f5edd5668124c8f54a7d676fd384568fd6
4
+ data.tar.gz: 8d1f15d0f9c3dfc190d0cc0976814ab6bf90a927af722d4164861e57c93564a2
5
5
  SHA512:
6
- metadata.gz: 14e62113089e96e77fd11dabdda86582ac5c4004465a4007396b71a954927396e1a77c5abf2c10199e43b41b119a5879bbdf491400ec8de5d9f1bd2b3da19ef8
7
- data.tar.gz: 6ee4b4854cf14ba4cd1cad9dd4c847cea5dea58c892298e15daecce174754b35beccfaff8386f9c97ca103d500aeea476f82c232fa88291741d075685d2fc789
6
+ metadata.gz: 746dcb1563f9777c374572d2b7ecfbde7833a3ce1b546933958ae920a417d1e474e27c8b569b3fc25cc117735e07bdb420dec838baadebe6375ab83d13c959bd
7
+ data.tar.gz: a9dca767fdfec65ba0ef854677e600ef00fabfbdd60ad534fb5182e292c603eb4cbb1b1eb77440f85415d5189bce902d3899389033c591f6e1d1d925de67afc4
data/README.md CHANGED
@@ -162,7 +162,7 @@ If your environment doesn't accept installing browser or creating browser proces
162
162
  For launching Playwright server, just execute:
163
163
 
164
164
  ```
165
- npx playwright install && npx playwright run-server 8080
165
+ npx playwright install && npx playwright run-server --port 8080
166
166
  ```
167
167
 
168
168
  and we can connect to the server with the code like this:
@@ -435,6 +435,8 @@ The method finds all elements matching the specified selector in the [ElementHan
435
435
 
436
436
  ```
437
437
  def screenshot(
438
+ animations: nil,
439
+ mask: nil,
438
440
  omitBackground: nil,
439
441
  path: nil,
440
442
  quality: nil,
@@ -33,7 +33,7 @@ PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
33
33
  ## devices
34
34
 
35
35
  ```
36
- def devices
36
+ def devices(port: nil)
37
37
  ```
38
38
 
39
39
  Returns the list of detected Android devices.
@@ -325,6 +325,15 @@ def get_attribute(name, timeout: nil)
325
325
 
326
326
  Returns element attribute value.
327
327
 
328
+ ## highlight
329
+
330
+ ```
331
+ def highlight
332
+ ```
333
+
334
+ Highlight the corresponding element(s) on the screen. Useful for debugging, don't commit the code that uses
335
+ [Locator#highlight](./locator#highlight).
336
+
328
337
  ## hover
329
338
 
330
339
  ```
@@ -480,6 +489,8 @@ modifier, modifier is pressed and being held while the subsequent key is being p
480
489
 
481
490
  ```
482
491
  def screenshot(
492
+ animations: nil,
493
+ mask: nil,
483
494
  omitBackground: nil,
484
495
  path: nil,
485
496
  quality: nil,
@@ -1012,8 +1012,10 @@ To remove a route with its handler you can use [Page#unroute](./page#unroute).
1012
1012
 
1013
1013
  ```
1014
1014
  def screenshot(
1015
+ animations: nil,
1015
1016
  clip: nil,
1016
1017
  fullPage: nil,
1018
+ mask: nil,
1017
1019
  omitBackground: nil,
1018
1020
  path: nil,
1019
1021
  quality: nil,
@@ -1167,9 +1169,10 @@ alias: `viewport_size=`
1167
1169
  In the case of multiple pages in a single browser, each page can have its own viewport size. However,
1168
1170
  [Browser#new_context](./browser#new_context) allows to set viewport size (and more) for all pages in the context at once.
1169
1171
 
1170
- `page.setViewportSize` will resize the page. A lot of websites don't expect phones to change size, so you should set the
1171
- viewport size before navigating to the page. [Page#set_viewport_size](./page#set_viewport_size) will also reset `screen` size, use
1172
- [Browser#new_context](./browser#new_context) with `screen` and `viewport` parameters if you need better control of these properties.
1172
+ [Page#set_viewport_size](./page#set_viewport_size) will resize the page. A lot of websites don't expect phones to change size, so you
1173
+ should set the viewport size before navigating to the page. [Page#set_viewport_size](./page#set_viewport_size) will also reset `screen`
1174
+ size, use [Browser#new_context](./browser#new_context) with `screen` and `viewport` parameters if you need better control of these
1175
+ properties.
1173
1176
 
1174
1177
  ```ruby
1175
1178
  page.viewport_size = { width: 640, height: 480 }
@@ -27,7 +27,7 @@ This article introduces a way to separate environments into client (for executin
27
27
 
28
28
  ## Overview
29
29
 
30
- Playwrignt Ruby client is running on Alpine Linux. It just sends/receives JSON messages of Playwright-protocol via WebSocket.
30
+ Playwright Ruby client is running on Alpine Linux. It just sends/receives JSON messages of Playwright-protocol via WebSocket.
31
31
 
32
32
  Playwright server is running on a container of [official Docker image](https://hub.docker.com/_/microsoft-playwright). It just operates browsers in response to the JSON messages from WebSocket.
33
33
 
@@ -69,7 +69,7 @@ end
69
69
 
70
70
  ### Server code
71
71
 
72
- With the [official Docker image](https://hub.docker.com/_/microsoft-playwright) or in the local development environment with Node.js, just execute `npx playwright install && npx playwright run-server $PORT`. (`$PORT` is a port number of the server)
72
+ With the [official Docker image](https://hub.docker.com/_/microsoft-playwright) or in the local development environment with Node.js, just execute `npx playwright install && npx playwright run-server --port $PORT --path /ws`. (`$PORT` is a port number of the server)
73
73
 
74
74
  If custom Docker image is preferred, build it as follows:
75
75
 
@@ -80,7 +80,7 @@ WORKDIR /root
80
80
  RUN npm install playwright@1.12.3 && ./node_modules/.bin/playwright install
81
81
 
82
82
  ENV PORT 8888
83
- CMD ["./node_modules/.bin/playwright", "run-server", "$PORT"]
83
+ CMD ["./node_modules/.bin/playwright", "run-server", "--port", "$PORT", "--path", "/ws"]
84
84
  ```
85
85
 
86
86
  ## Browser server/client
@@ -100,7 +100,7 @@ end
100
100
 
101
101
  ### Server code
102
102
 
103
- For instant use, `npx playwright launch-server chromium` generates a WebSocket endpoint URL with a random path.
103
+ For instant use, `npx playwright launch-server --browser chromium` generates a WebSocket endpoint URL with a random path.
104
104
 
105
105
  More customization can be done by implementing JavaScript server like below:
106
106
 
@@ -138,7 +138,7 @@ DEBUG=1 bundle exec ruby some-automation-with-playwright.rb
138
138
  Just set an environment variable `DEBUG=pw:*` or `DEBUG=pw:server`
139
139
 
140
140
  ```
141
- DEBUG=pw:* npx playwright run-server 8888
141
+ DEBUG=pw:* npx playwright run-server --port 8888 --path /ws
142
142
  ```
143
143
 
144
144
  See [the official documentation](https://playwright.dev/docs/debug/#verbose-api-logs) for details.
@@ -417,6 +417,7 @@
417
417
  * focus
418
418
  * frame_locator
419
419
  * get_attribute
420
+ * highlight
420
421
  * hover
421
422
  * inner_html
422
423
  * inner_text
@@ -4,8 +4,8 @@ module Playwright
4
4
  @timeout_settings = TimeoutSettings.new
5
5
  end
6
6
 
7
- def devices
8
- resp = @channel.send_message_to_server('devices')
7
+ def devices(port: nil)
8
+ resp = @channel.send_message_to_server('devices', port: port)
9
9
  resp.map { |device| ChannelOwners::AndroidDevice.from(device) }
10
10
  end
11
11
  end
@@ -13,6 +13,7 @@ module Playwright
13
13
  @timeout_settings = TimeoutSettings.new
14
14
  @service_workers = Set.new
15
15
  @background_pages = Set.new
16
+ @owner_page = nil
16
17
 
17
18
  @tracing = ChannelOwners::Tracing.from(@initializer['tracing'])
18
19
  @request = ChannelOwners::APIRequestContext.from(@initializer['APIRequestContext'])
@@ -281,6 +281,8 @@ module Playwright
281
281
  end
282
282
 
283
283
  def screenshot(
284
+ animations: nil,
285
+ mask: nil,
284
286
  omitBackground: nil,
285
287
  path: nil,
286
288
  quality: nil,
@@ -288,12 +290,18 @@ module Playwright
288
290
  type: nil)
289
291
 
290
292
  params = {
293
+ animations: animations,
291
294
  omitBackground: omitBackground,
292
295
  path: path,
293
296
  quality: quality,
294
297
  timeout: timeout,
295
298
  type: type,
296
299
  }.compact
300
+ if mask.is_a?(Enumerable)
301
+ params[:mask] = mask.map do |locator|
302
+ locator.send(:to_protocol)
303
+ end
304
+ end
297
305
  encoded_binary = @channel.send_message_to_server('screenshot', params)
298
306
  decoded_binary = Base64.strict_decode64(encoded_binary)
299
307
  if path
@@ -615,6 +615,10 @@ module Playwright
615
615
  @channel.send_message_to_server('title')
616
616
  end
617
617
 
618
+ def highlight(selector)
619
+ @channel.send_message_to_server('highlight', selector: selector)
620
+ end
621
+
618
622
  # @param page [Page]
619
623
  # @note This method should be used internally. Accessed via .send method, so keep private!
620
624
  private def update_page_from_page(page)
@@ -414,6 +414,8 @@ module Playwright
414
414
  fullPage: nil,
415
415
  clip: nil,
416
416
  omitBackground: nil,
417
+ animations: nil,
418
+ mask: nil,
417
419
  timeout: nil)
418
420
 
419
421
  params = {
@@ -422,8 +424,14 @@ module Playwright
422
424
  fullPage: fullPage,
423
425
  clip: clip,
424
426
  omitBackground: omitBackground,
427
+ animations: animations,
425
428
  timeout: timeout,
426
429
  }.compact
430
+ if mask.is_a?(Enumerable)
431
+ params[:mask] = mask.map do |locator|
432
+ locator.send(:to_protocol)
433
+ end
434
+ end
427
435
  encoded_binary = @channel.send_message_to_server('screenshot', params)
428
436
  decoded_binary = Base64.strict_decode64(encoded_binary)
429
437
  if path
@@ -55,6 +55,13 @@ module Playwright
55
55
  "Locator@#{@selector}"
56
56
  end
57
57
 
58
+ private def to_protocol
59
+ {
60
+ frame: @frame.channel,
61
+ selector: @selector,
62
+ }
63
+ end
64
+
58
65
  class DifferentFrameError < StandardError
59
66
  def initialize
60
67
  super('Inner "has" locator must belong to the same frame.')
@@ -306,6 +313,8 @@ module Playwright
306
313
  end
307
314
 
308
315
  def screenshot(
316
+ animations: nil,
317
+ mask: nil,
309
318
  omitBackground: nil,
310
319
  path: nil,
311
320
  quality: nil,
@@ -313,6 +322,8 @@ module Playwright
313
322
  type: nil)
314
323
  with_element(timeout: timeout) do |handle, options|
315
324
  handle.screenshot(
325
+ animations: animations,
326
+ mask: mask,
316
327
  omitBackground: omitBackground,
317
328
  path: path,
318
329
  quality: quality,
@@ -416,5 +427,9 @@ module Playwright
416
427
  def all_text_contents
417
428
  @frame.eval_on_selector_all(@selector, "ee => ee.map(e => e.textContent || '')")
418
429
  end
430
+
431
+ def highlight
432
+ @frame.highlight(@selector)
433
+ end
419
434
  end
420
435
  end
@@ -51,9 +51,11 @@ module Playwright
51
51
  @counter.increment
52
52
 
53
53
  Concurrent::Promises.future do
54
- @handler.call(route, request)
55
- rescue => err
56
- puts err, err.backtrace
54
+ begin
55
+ @handler.call(route, request)
56
+ rescue => err
57
+ puts err, err.backtrace
58
+ end
57
59
  end
58
60
  end
59
61
 
@@ -46,7 +46,8 @@ module Playwright
46
46
  #
47
47
  # @note This method blocks until playwright-cli exited. Consider using Thread or Future.
48
48
  def async_run
49
- @stdin, @stdout, @stderr, @thread = Open3.popen3("#{@driver_executable_path} run-driver", { pgroup: true })
49
+ popen3_args = {}
50
+ @stdin, @stdout, @stderr, @thread = run_driver_with_open3
50
51
  @stdin.binmode # Ensure Strings are written 1:1 without encoding conversion, necessary for integer values
51
52
 
52
53
  Thread.new { handle_stdout }
@@ -55,6 +56,18 @@ module Playwright
55
56
 
56
57
  private
57
58
 
59
+ def run_driver_with_open3
60
+ Open3.popen3("#{@driver_executable_path} run-driver", { pgroup: true })
61
+ rescue ArgumentError => err
62
+ # Windows doesn't accept pgroup parameter.
63
+ # ArgumentError: wrong exec option symbol: pgroup
64
+ if err.message =~ /pgroup/
65
+ Open3.popen3("#{@driver_executable_path} run-driver")
66
+ else
67
+ raise
68
+ end
69
+ end
70
+
58
71
  def handle_stdout(packet_size: 32_768)
59
72
  while chunk = @stdout.read(4)
60
73
  length = chunk.unpack1('V') # unsigned 32bit, little endian
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Playwright
4
- VERSION = '1.19.0'
5
- COMPATIBLE_PLAYWRIGHT_VERSION = '1.19.0'
4
+ VERSION = '1.20.1'
5
+ COMPATIBLE_PLAYWRIGHT_VERSION = '1.20.1'
6
6
  end
@@ -26,8 +26,8 @@ module Playwright
26
26
  class Android < PlaywrightApi
27
27
 
28
28
  # Returns the list of detected Android devices.
29
- def devices
30
- wrap_impl(@impl.devices)
29
+ def devices(port: nil)
30
+ wrap_impl(@impl.devices(port: unwrap_impl(port)))
31
31
  end
32
32
 
33
33
  # This setting will change the default maximum time for all the methods accepting `timeout` option.
@@ -346,12 +346,14 @@ module Playwright
346
346
  # This method waits for the [actionability](./actionability.md) checks, then scrolls element into view before taking a
347
347
  # screenshot. If the element is detached from DOM, the method throws an error.
348
348
  def screenshot(
349
+ animations: nil,
350
+ mask: nil,
349
351
  omitBackground: nil,
350
352
  path: nil,
351
353
  quality: nil,
352
354
  timeout: nil,
353
355
  type: nil)
354
- wrap_impl(@impl.screenshot(omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
356
+ wrap_impl(@impl.screenshot(animations: unwrap_impl(animations), mask: unwrap_impl(mask), omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
355
357
  end
356
358
 
357
359
  # This method waits for [actionability](./actionability.md) checks, then tries to scroll element into view, unless it is
@@ -788,6 +788,11 @@ module Playwright
788
788
  wrap_impl(@impl.detached=(unwrap_impl(req)))
789
789
  end
790
790
 
791
+ # @nodoc
792
+ def highlight(selector)
793
+ wrap_impl(@impl.highlight(unwrap_impl(selector)))
794
+ end
795
+
791
796
  # -- inherited from EventEmitter --
792
797
  # @nodoc
793
798
  def off(event, callback)
@@ -250,6 +250,12 @@ module Playwright
250
250
  wrap_impl(@impl.get_attribute(unwrap_impl(name), timeout: unwrap_impl(timeout)))
251
251
  end
252
252
 
253
+ # Highlight the corresponding element(s) on the screen. Useful for debugging, don't commit the code that uses
254
+ # [`method: Locator.highlight`].
255
+ def highlight
256
+ wrap_impl(@impl.highlight)
257
+ end
258
+
253
259
  # This method hovers over the element by performing the following steps:
254
260
  # 1. Wait for [actionability](./actionability.md) checks on the element, unless `force` option is set.
255
261
  # 1. Scroll the element into view if needed.
@@ -361,12 +367,14 @@ module Playwright
361
367
  # This method waits for the [actionability](./actionability.md) checks, then scrolls element into view before taking a
362
368
  # screenshot. If the element is detached from DOM, the method throws an error.
363
369
  def screenshot(
370
+ animations: nil,
371
+ mask: nil,
364
372
  omitBackground: nil,
365
373
  path: nil,
366
374
  quality: nil,
367
375
  timeout: nil,
368
376
  type: nil)
369
- wrap_impl(@impl.screenshot(omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
377
+ wrap_impl(@impl.screenshot(animations: unwrap_impl(animations), mask: unwrap_impl(mask), omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
370
378
  end
371
379
 
372
380
  # This method waits for [actionability](./actionability.md) checks, then tries to scroll element into view, unless it is
@@ -891,14 +891,16 @@ module Playwright
891
891
 
892
892
  # Returns the buffer with the captured screenshot.
893
893
  def screenshot(
894
+ animations: nil,
894
895
  clip: nil,
895
896
  fullPage: nil,
897
+ mask: nil,
896
898
  omitBackground: nil,
897
899
  path: nil,
898
900
  quality: nil,
899
901
  timeout: nil,
900
902
  type: nil)
901
- wrap_impl(@impl.screenshot(clip: unwrap_impl(clip), fullPage: unwrap_impl(fullPage), omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
903
+ wrap_impl(@impl.screenshot(animations: unwrap_impl(animations), clip: unwrap_impl(clip), fullPage: unwrap_impl(fullPage), mask: unwrap_impl(mask), omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
902
904
  end
903
905
 
904
906
  # This method waits for an element matching `selector`, waits for [actionability](./actionability.md) checks, waits until
@@ -1016,9 +1018,10 @@ module Playwright
1016
1018
  # In the case of multiple pages in a single browser, each page can have its own viewport size. However,
1017
1019
  # [`method: Browser.newContext`] allows to set viewport size (and more) for all pages in the context at once.
1018
1020
  #
1019
- # `page.setViewportSize` will resize the page. A lot of websites don't expect phones to change size, so you should set the
1020
- # viewport size before navigating to the page. [`method: Page.setViewportSize`] will also reset `screen` size, use
1021
- # [`method: Browser.newContext`] with `screen` and `viewport` parameters if you need better control of these properties.
1021
+ # [`method: Page.setViewportSize`] will resize the page. A lot of websites don't expect phones to change size, so you
1022
+ # should set the viewport size before navigating to the page. [`method: Page.setViewportSize`] will also reset `screen`
1023
+ # size, use [`method: Browser.newContext`] with `screen` and `viewport` parameters if you need better control of these
1024
+ # properties.
1022
1025
  #
1023
1026
  # ```python sync
1024
1027
  # page = browser.new_page()
@@ -1387,13 +1390,13 @@ module Playwright
1387
1390
  end
1388
1391
 
1389
1392
  # @nodoc
1390
- def start_css_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
1391
- wrap_impl(@impl.start_css_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
1393
+ def start_js_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
1394
+ wrap_impl(@impl.start_js_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
1392
1395
  end
1393
1396
 
1394
1397
  # @nodoc
1395
- def stop_css_coverage
1396
- wrap_impl(@impl.stop_css_coverage)
1398
+ def start_css_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
1399
+ wrap_impl(@impl.start_css_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
1397
1400
  end
1398
1401
 
1399
1402
  # @nodoc
@@ -1402,8 +1405,8 @@ module Playwright
1402
1405
  end
1403
1406
 
1404
1407
  # @nodoc
1405
- def start_js_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
1406
- wrap_impl(@impl.start_js_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
1408
+ def stop_css_coverage
1409
+ wrap_impl(@impl.stop_css_coverage)
1407
1410
  end
1408
1411
 
1409
1412
  # @nodoc
@@ -87,13 +87,13 @@ module Playwright
87
87
  end
88
88
 
89
89
  # @nodoc
90
- def electron
91
- wrap_impl(@impl.electron)
90
+ def android
91
+ wrap_impl(@impl.android)
92
92
  end
93
93
 
94
94
  # @nodoc
95
- def android
96
- wrap_impl(@impl.android)
95
+ def electron
96
+ wrap_impl(@impl.electron)
97
97
  end
98
98
 
99
99
  # -- inherited from EventEmitter --
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playwright-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.0
4
+ version: 1.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-23 00:00:00.000000000 Z
11
+ date: 2022-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -396,5 +396,5 @@ requirements: []
396
396
  rubygems_version: 3.3.7
397
397
  signing_key:
398
398
  specification_version: 4
399
- summary: The Ruby binding of playwright driver 1.19.0
399
+ summary: The Ruby binding of playwright driver 1.20.1
400
400
  test_files: []