playwright-ruby-client 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8e526e28e95751a08697bc93b14ec33f4f82e827b8adf4dc45aed4bf44dd1d2
4
- data.tar.gz: 647596db5628a1014a7816bb43d2ca41a21eeb6cf8c7263dea701d8f9a6ba4e7
3
+ metadata.gz: eecde37d8ee0ad9fdb1f0df5a64a5a646f2706915a24a2a2d83a8f176bcc8519
4
+ data.tar.gz: cb97a5926b3a25c8c3b2fe8c88946747ec89d3d579f71d36350c7cf2839c83e0
5
5
  SHA512:
6
- metadata.gz: 0051320ee1e574680ebc6be4d5cf359a28bd8ada9a737fc60d734f017c43142b6f267553f15d0e1ac0ed368f12d57dac5a887a39695f59a11f774344405dcfd1
7
- data.tar.gz: 14f97b51a9462a8bfb587c5752eb13b3db0c132d0d56d7bdaab829389f2cb7c17bb879b171773e1e21259bb6b352f6020a5b7165be577bb147b22b5b0155c28e
6
+ metadata.gz: 2e1bb8eee779773afd9e3b165a03f3c91bb25ae076ae00d6d1603e34afe8eaf3876f847559841c68403588a79b766f3e4afe680f7056286c64ba16ce5be149bc
7
+ data.tar.gz: e55e7895a26b5a579cae82101cd9ae0bf3cebd4f9ecc0c18692b4a18fa5a7e649b4121d9ac5c6029101131cdd56c59af64ba8b65d6c325cfbe7ffe56c8ee632c
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/playwright-ruby-client.svg)](https://badge.fury.io/rb/playwright-ruby-client)
2
2
 
3
- # playwright-ruby-client
4
-
5
- A Ruby client for Playwright driver.
3
+ # 🎭 Playwright client for Ruby
6
4
 
7
5
  Note: Currently, this Gem is just a PoC (Proof of Concept). If you want to develop browser-automation for Chrome with Ruby, consider using [puppeteer-ruby](https://github.com/YusukeIwaki/puppeteer-ruby). The list of the available APIs of playwright-ruby-client is [here](./docs/api_coverage.md)
8
6
 
@@ -17,6 +15,8 @@ npm install playwright
17
15
 
18
16
  and then, set `playwright_cli_executable_path: ./node_modules/.bin/playwright` at `Playwright.create`.
19
17
 
18
+ **Prefer playwrighting without Node.js?**
19
+
20
20
  Instead of npm install, you can also directly download playwright driver from playwright.azureedge.net/builds/. The URL can be easily detected from [here](https://github.com/microsoft/playwright-python/blob/79f6ce0a6a69c480573372706df84af5ef99c4a4/setup.py#L56-L61)
21
21
 
22
22
  ### Capture a site
data/docs/api_coverage.md CHANGED
@@ -9,6 +9,7 @@
9
9
  * method
10
10
  * post_data
11
11
  * post_data_buffer
12
+ * post_data_json
12
13
  * redirected_from
13
14
  * redirected_to
14
15
  * resource_type
@@ -22,6 +23,7 @@
22
23
  * ~~finished~~
23
24
  * ~~frame~~
24
25
  * ~~headers~~
26
+ * ~~json~~
25
27
  * ~~ok~~
26
28
  * ~~request~~
27
29
  * ~~status~~
@@ -40,6 +42,8 @@
40
42
 
41
43
  * ~~closed?~~
42
44
  * ~~url~~
45
+ * ~~expect_event~~
46
+ * ~~wait_for_event~~
43
47
 
44
48
  ## Keyboard
45
49
 
@@ -197,7 +201,6 @@
197
201
 
198
202
  ## Download
199
203
 
200
- * ~~create_read_stream~~
201
204
  * delete
202
205
  * failure
203
206
  * path
@@ -273,6 +276,7 @@
273
276
  * url
274
277
  * ~~video~~
275
278
  * viewport_size
279
+ * expect_event
276
280
  * wait_for_function
277
281
  * wait_for_load_state
278
282
  * expect_navigation
@@ -281,8 +285,13 @@
281
285
  * wait_for_selector
282
286
  * ~~wait_for_timeout~~
283
287
  * ~~workers~~
288
+ * ~~expect_download~~
289
+ * ~~expect_popup~~
290
+ * ~~expect_worker~~
291
+ * ~~expect_console_message~~
292
+ * ~~expect_file_chooser~~
293
+ * ~~wait_for_event~~
284
294
  * accessibility
285
- * ~~coverage~~
286
295
  * keyboard
287
296
  * mouse
288
297
  * touchscreen
@@ -306,10 +315,12 @@
306
315
  * ~~set_default_timeout~~
307
316
  * ~~set_extra_http_headers~~
308
317
  * ~~set_geolocation~~
309
- * ~~set_http_credentials~~
310
318
  * ~~set_offline~~
311
319
  * ~~storage_state~~
312
320
  * ~~unroute~~
321
+ * ~~expect_event~~
322
+ * ~~expect_page~~
323
+ * ~~wait_for_event~~
313
324
 
314
325
  ## ~~CDPSession~~
315
326
 
@@ -333,19 +344,16 @@
333
344
 
334
345
  ## BrowserType
335
346
 
336
- * ~~connect~~
337
347
  * executable_path
338
348
  * launch
339
349
  * ~~launch_persistent_context~~
340
- * ~~launch_server~~
341
350
  * name
342
351
 
343
352
  ## Playwright
344
353
 
345
- * ~~close~~
354
+ * ~~stop~~
346
355
  * chromium
347
356
  * devices
348
- * ~~errors~~
349
357
  * firefox
350
358
  * ~~selectors~~
351
359
  * webkit
@@ -59,16 +59,14 @@ module Playwright
59
59
  "#<#{@guid}>"
60
60
  end
61
61
 
62
- private
63
-
64
- def after_initialize
62
+ private def after_initialize
65
63
  end
66
64
 
67
- def update_object_from_child(guid, child)
65
+ private def update_object_from_child(guid, child)
68
66
  @objects[guid] = child
69
67
  end
70
68
 
71
- def delete_object_from_child(guid)
69
+ private def delete_object_from_child(guid)
72
70
  @objects.delete(guid)
73
71
  end
74
72
  end
@@ -1,6 +1,6 @@
1
1
  module Playwright
2
2
  define_channel_owner :Android do
3
- def after_initialize
3
+ private def after_initialize
4
4
  @timeout_settings = TimeoutSettings.new
5
5
  end
6
6
 
@@ -2,7 +2,7 @@ module Playwright
2
2
  define_channel_owner :AndroidDevice do
3
3
  include Utils::PrepareBrowserContextOptions
4
4
 
5
- def after_initialize
5
+ private def after_initialize
6
6
  @input = AndroidInputImpl.new(@channel)
7
7
  end
8
8
 
@@ -104,17 +104,17 @@ module Playwright
104
104
  isMobile: nil,
105
105
  javaScriptEnabled: nil,
106
106
  locale: nil,
107
- logger: nil,
107
+ noViewport: nil,
108
108
  offline: nil,
109
109
  permissions: nil,
110
110
  proxy: nil,
111
- recordHar: nil,
112
- recordVideo: nil,
111
+ record_har_omit_content: nil,
112
+ record_har_path: nil,
113
+ record_video_dir: nil,
114
+ record_video_size: nil,
113
115
  storageState: nil,
114
116
  timezoneId: nil,
115
117
  userAgent: nil,
116
- videoSize: nil,
117
- videosPath: nil,
118
118
  viewport: nil,
119
119
  &block)
120
120
  params = {
@@ -131,17 +131,17 @@ module Playwright
131
131
  isMobile: isMobile,
132
132
  javaScriptEnabled: javaScriptEnabled,
133
133
  locale: locale,
134
- logger: logger,
134
+ noViewport: noViewport,
135
135
  offline: offline,
136
136
  permissions: permissions,
137
137
  proxy: proxy,
138
- recordHar: recordHar,
139
- recordVideo: recordVideo,
138
+ record_har_omit_content: record_har_omit_content,
139
+ record_har_path: record_har_path,
140
+ record_video_dir: record_video_dir,
141
+ record_video_size: record_video_size,
140
142
  storageState: storageState,
141
143
  timezoneId: timezoneId,
142
144
  userAgent: userAgent,
143
- videoSize: videoSize,
144
- videosPath: videosPath,
145
145
  viewport: viewport,
146
146
  }.compact
147
147
  prepare_browser_context_options(params)
@@ -4,7 +4,7 @@ module Playwright
4
4
  include Utils::Errors::SafeCloseError
5
5
  include Utils::PrepareBrowserContextOptions
6
6
 
7
- def after_initialize
7
+ private def after_initialize
8
8
  @contexts = Set.new
9
9
  @channel.on('close', method(:on_close))
10
10
  end
@@ -4,7 +4,7 @@ module Playwright
4
4
  include Utils::Errors::SafeCloseError
5
5
  attr_writer :browser, :owner_page, :options
6
6
 
7
- def after_initialize
7
+ private def after_initialize
8
8
  @pages = Set.new
9
9
 
10
10
  @channel.once('close', ->(_) { on_close })
@@ -136,8 +136,19 @@ module Playwright
136
136
  nil
137
137
  end
138
138
 
139
- def select_option(values, noWaitAfter: nil, timeout: nil)
140
- base_params = SelectOptionValues.new(values).as_params
139
+ def select_option(
140
+ element: nil,
141
+ index: nil,
142
+ value: nil,
143
+ label: nil,
144
+ noWaitAfter: nil,
145
+ timeout: nil)
146
+ base_params = SelectOptionValues.new(
147
+ element: element,
148
+ index: index,
149
+ value: value,
150
+ label: label,
151
+ ).as_params
141
152
  params = base_params + { noWaitAfter: noWaitAfter, timeout: timeout }.compact
142
153
  @channel.send_message_to_server('selectOption', params)
143
154
 
@@ -1,7 +1,7 @@
1
1
  module Playwright
2
2
  # @ref https://github.com/microsoft/playwright-python/blob/master/playwright/_impl/_frame.py
3
3
  define_channel_owner :Frame do
4
- def after_initialize
4
+ private def after_initialize
5
5
  if @initializer['parentFrame']
6
6
  @parent_frame = ChannelOwners::Frame.from(@initializer['parentFrame'])
7
7
  @parent_frame.send(:append_child_frame_from_child, self)
@@ -398,8 +398,20 @@ module Playwright
398
398
  nil
399
399
  end
400
400
 
401
- def select_option(selector, values, noWaitAfter: nil, timeout: nil)
402
- base_params = SelectOptionValues.new(values).as_params
401
+ def select_option(
402
+ selector,
403
+ element: nil,
404
+ index: nil,
405
+ value: nil,
406
+ label: nil,
407
+ noWaitAfter: nil,
408
+ timeout: nil)
409
+ base_params = SelectOptionValues.new(
410
+ element: element,
411
+ index: index,
412
+ value: value,
413
+ label: label,
414
+ ).as_params
403
415
  params = base_params + { selector: selector, noWaitAfter: noWaitAfter, timeout: timeout }.compact
404
416
  @channel.send_message_to_server('selectOption', params)
405
417
 
@@ -1,6 +1,6 @@
1
1
  module Playwright
2
2
  define_channel_owner :JSHandle do
3
- def after_initialize
3
+ private def after_initialize
4
4
  @preview = @initializer['preview']
5
5
  @channel.on('previewUpdated', method(:on_preview_updated))
6
6
  end
@@ -6,7 +6,7 @@ module Playwright
6
6
  include Utils::Errors::SafeCloseError
7
7
  attr_writer :owned_context
8
8
 
9
- def after_initialize
9
+ private def after_initialize
10
10
  @browser_context = @parent
11
11
  @timeout_settings = TimeoutSettings.new(@browser_context.send(:_timeout_settings))
12
12
  @accessibility = Accessibility.new(@channel)
@@ -167,14 +167,7 @@ module Playwright
167
167
  ChannelOwners::Page.from(resp)
168
168
  end
169
169
 
170
- def frame(frameSelector)
171
- name, url =
172
- if frameSelector.is_a?(Hash)
173
- [frameSelector[:name], frameSelector[:url]]
174
- else
175
- [frameSelector, nil]
176
- end
177
-
170
+ def frame(name: nil, url: nil)
178
171
  if name
179
172
  @frames.find { |f| f.name == name }
180
173
  elsif url
@@ -351,9 +344,17 @@ module Playwright
351
344
  nil
352
345
  end
353
346
 
354
- def add_init_script(script, arg: nil)
347
+ def add_init_script(path: nil, script: nil)
348
+ source =
349
+ if path
350
+ File.read(path, 'r')
351
+ elsif script
352
+ script
353
+ else
354
+ raise ArgumentError.new('Either path or script parameter must be specified')
355
+ end
356
+
355
357
  @channel.send_message_to_server('addInitScript', source: script)
356
- # FIXME: handling `arg` for function `script`
357
358
  nil
358
359
  end
359
360
 
@@ -502,8 +503,23 @@ module Playwright
502
503
  )
503
504
  end
504
505
 
505
- def select_option(selector, values, noWaitAfter: nil, timeout: nil)
506
- @main_frame.select_option(selector, values, noWaitAfter: noWaitAfter, timeout: timeout)
506
+ def select_option(
507
+ selector,
508
+ element: nil,
509
+ index: nil,
510
+ value: nil,
511
+ label: nil,
512
+ noWaitAfter: nil,
513
+ timeout: nil)
514
+ @main_frame.select_option(
515
+ selector,
516
+ element: element,
517
+ index: index,
518
+ value: value,
519
+ label: label,
520
+ noWaitAfter: noWaitAfter,
521
+ timeout: timeout,
522
+ )
507
523
  end
508
524
 
509
525
  def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
@@ -599,20 +615,9 @@ module Playwright
599
615
  end
600
616
  end
601
617
 
602
- def expect_event(event, optionsOrPredicate: nil, &block)
603
- predicate, timeout =
604
- case optionsOrPredicate
605
- when Proc
606
- [optionsOrPredicate, nil]
607
- when Hash
608
- [optionsOrPredicate[:predicate], optionsOrPredicate[:timeout]]
609
- else
610
- [nil, nil]
611
- end
612
- timeout ||= @timeout_settings.timeout
613
-
618
+ def expect_event(event, predicate: nil, timeout: nil, &block)
614
619
  wait_helper = WaitHelper.new
615
- wait_helper.reject_on_timeout(timeout, "Timeout while waiting for event \"#{event}\"")
620
+ wait_helper.reject_on_timeout(timeout || @timeout_settings.timeout, "Timeout while waiting for event \"#{event}\"")
616
621
 
617
622
  unless event == Events::Page::Crash
618
623
  wait_helper.reject_on_event(self, Events::Page::Crash, CrashedError.new)
@@ -649,7 +654,7 @@ module Playwright
649
654
  -> (_) { true }
650
655
  end
651
656
 
652
- expect_event(Events::Page::Request, optionsOrPredicate: { predicate: predicate, timeout: timeout})
657
+ expect_event(Events::Page::Request, predicate: predicate, timeout: timeout)
653
658
  end
654
659
 
655
660
  def expect_response(urlOrPredicate, timeout: nil)
@@ -664,7 +669,7 @@ module Playwright
664
669
  -> (_) { true }
665
670
  end
666
671
 
667
- expect_event(Events::Page::Response, optionsOrPredicate: { predicate: predicate, timeout: timeout})
672
+ expect_event(Events::Page::Response, predicate: predicate, timeout: timeout)
668
673
  end
669
674
 
670
675
  # called from BrowserContext#on_page with send(:update_browser_context, page), so keep private.
@@ -3,7 +3,7 @@ require 'base64'
3
3
  module Playwright
4
4
  # @ref https://github.com/microsoft/playwright-python/blob/master/playwright/_impl/_network.py
5
5
  define_channel_owner :Request do
6
- def after_initialize
6
+ private def after_initialize
7
7
  @redirected_from = ChannelOwners::Request.from_nullable(@initializer['redirectedFrom'])
8
8
  @redirected_from&.send(:update_redirected_to, self)
9
9
  @timing = {
@@ -1,7 +1,18 @@
1
1
  module Playwright
2
2
  class SelectOptionValues
3
- def initialize(values)
4
- @params = convert(values)
3
+ def initialize(element: nil, index: nil, value: nil, label: nil)
4
+ @params =
5
+ if element
6
+ convert(elmeent)
7
+ elsif index
8
+ convert(index)
9
+ elsif value
10
+ convert(value)
11
+ elsif label
12
+ convert(label)
13
+ else
14
+ {}
15
+ end
5
16
  end
6
17
 
7
18
  # @return [Hash]
@@ -10,8 +21,7 @@ module Playwright
10
21
  end
11
22
 
12
23
  private def convert(values)
13
- return {} unless values
14
- return convert([values]) unless values.is_a?('Array')
24
+ return convert([values]) unless values.is_a?(Enumerable)
15
25
  return {} if values.empty?
16
26
  values.each_with_index do |value, index|
17
27
  unless values
@@ -3,8 +3,8 @@ module Playwright
3
3
  module PrepareBrowserContextOptions
4
4
  # @see https://github.com/microsoft/playwright/blob/5a2cfdbd47ed3c3deff77bb73e5fac34241f649d/src/client/browserContext.ts#L265
5
5
  private def prepare_browser_context_options(params)
6
- if params[:viewport] == 0
7
- params.delete(:viewport)
6
+ if params[:noViewport] == 0
7
+ params.delete(:noViewport)
8
8
  params[:noDefaultViewport] = true
9
9
  end
10
10
  if params[:extraHTTPHeaders]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Playwright
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -7,11 +7,6 @@ module Playwright
7
7
  wrap_impl(@impl.devices)
8
8
  end
9
9
 
10
- # @nodoc
11
- def after_initialize
12
- wrap_impl(@impl.after_initialize)
13
- end
14
-
15
10
  # -- inherited from EventEmitter --
16
11
  # @nodoc
17
12
  def once(event, callback)
@@ -12,11 +12,6 @@ module Playwright
12
12
  wrap_impl(@impl.close)
13
13
  end
14
14
 
15
- # @nodoc
16
- def after_initialize
17
- wrap_impl(@impl.after_initialize)
18
- end
19
-
20
15
  # @nodoc
21
16
  def tap_on(selector, duration: nil, timeout: nil)
22
17
  wrap_impl(@impl.tap_on(unwrap_impl(selector), duration: unwrap_impl(duration), timeout: unwrap_impl(timeout)))
@@ -38,8 +33,8 @@ module Playwright
38
33
  end
39
34
 
40
35
  # @nodoc
41
- def launch_browser(pkg: nil, acceptDownloads: nil, bypassCSP: nil, colorScheme: nil, deviceScaleFactor: nil, extraHTTPHeaders: nil, geolocation: nil, hasTouch: nil, httpCredentials: nil, ignoreHTTPSErrors: nil, isMobile: nil, javaScriptEnabled: nil, locale: nil, logger: nil, offline: nil, permissions: nil, proxy: nil, recordHar: nil, recordVideo: nil, storageState: nil, timezoneId: nil, userAgent: nil, videoSize: nil, videosPath: nil, viewport: nil, &block)
42
- wrap_impl(@impl.launch_browser(pkg: unwrap_impl(pkg), acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), logger: unwrap_impl(logger), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), recordHar: unwrap_impl(recordHar), recordVideo: unwrap_impl(recordVideo), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), videoSize: unwrap_impl(videoSize), videosPath: unwrap_impl(videosPath), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
36
+ def launch_browser(pkg: nil, acceptDownloads: nil, bypassCSP: nil, colorScheme: nil, deviceScaleFactor: nil, extraHTTPHeaders: nil, geolocation: nil, hasTouch: nil, httpCredentials: nil, ignoreHTTPSErrors: nil, isMobile: nil, javaScriptEnabled: nil, locale: nil, noViewport: nil, offline: nil, permissions: nil, proxy: nil, record_har_omit_content: nil, record_har_path: nil, record_video_dir: nil, record_video_size: nil, storageState: nil, timezoneId: nil, userAgent: nil, viewport: nil, &block)
37
+ wrap_impl(@impl.launch_browser(pkg: unwrap_impl(pkg), acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
43
38
  end
44
39
 
45
40
  # @nodoc
@@ -135,21 +135,20 @@ module Playwright
135
135
  isMobile: nil,
136
136
  javaScriptEnabled: nil,
137
137
  locale: nil,
138
- logger: nil,
138
+ noViewport: nil,
139
139
  offline: nil,
140
140
  permissions: nil,
141
141
  proxy: nil,
142
- recordHar: nil,
143
- recordVideo: nil,
142
+ record_har_omit_content: nil,
143
+ record_har_path: nil,
144
+ record_video_dir: nil,
145
+ record_video_size: nil,
144
146
  storageState: nil,
145
- storageStatePath: nil,
146
147
  timezoneId: nil,
147
148
  userAgent: nil,
148
- videoSize: nil,
149
- videosPath: nil,
150
149
  viewport: nil,
151
150
  &block)
152
- wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), logger: unwrap_impl(logger), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), recordHar: unwrap_impl(recordHar), recordVideo: unwrap_impl(recordVideo), storageState: unwrap_impl(storageState), storageStatePath: unwrap_impl(storageStatePath), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), videoSize: unwrap_impl(videoSize), videosPath: unwrap_impl(videosPath), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
151
+ wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
153
152
  end
154
153
 
155
154
  # Creates a new page in a new browser context. Closing this page will close the context as well.
@@ -170,20 +169,19 @@ module Playwright
170
169
  isMobile: nil,
171
170
  javaScriptEnabled: nil,
172
171
  locale: nil,
173
- logger: nil,
172
+ noViewport: nil,
174
173
  offline: nil,
175
174
  permissions: nil,
176
175
  proxy: nil,
177
- recordHar: nil,
178
- recordVideo: nil,
176
+ record_har_omit_content: nil,
177
+ record_har_path: nil,
178
+ record_video_dir: nil,
179
+ record_video_size: nil,
179
180
  storageState: nil,
180
- storageStatePath: nil,
181
181
  timezoneId: nil,
182
182
  userAgent: nil,
183
- videoSize: nil,
184
- videosPath: nil,
185
183
  viewport: nil)
186
- wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), logger: unwrap_impl(logger), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), recordHar: unwrap_impl(recordHar), recordVideo: unwrap_impl(recordVideo), storageState: unwrap_impl(storageState), storageStatePath: unwrap_impl(storageStatePath), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), videoSize: unwrap_impl(videoSize), videosPath: unwrap_impl(videosPath), viewport: unwrap_impl(viewport)))
184
+ wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport)))
187
185
  end
188
186
 
189
187
  # Returns the browser version.
@@ -191,11 +189,6 @@ module Playwright
191
189
  wrap_impl(@impl.version)
192
190
  end
193
191
 
194
- # @nodoc
195
- def after_initialize
196
- wrap_impl(@impl.after_initialize)
197
- end
198
-
199
192
  # -- inherited from EventEmitter --
200
193
  # @nodoc
201
194
  def once(event, callback)
@@ -96,7 +96,7 @@ module Playwright
96
96
  #
97
97
  # > NOTE: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
98
98
  # [`method: Page.addInitScript`] is not defined.
99
- def add_init_script(script, arg: nil)
99
+ def add_init_script(path: nil, script: nil)
100
100
  raise NotImplementedError.new('add_init_script is not implemented yet.')
101
101
  end
102
102
 
@@ -523,12 +523,6 @@ module Playwright
523
523
  end
524
524
  alias_method :geolocation=, :set_geolocation
525
525
 
526
- # **DEPRECATED** Browsers may cache credentials after successful authentication. Create a new browser context instead.
527
- def set_http_credentials(httpCredentials)
528
- raise NotImplementedError.new('set_http_credentials is not implemented yet.')
529
- end
530
- alias_method :http_credentials=, :set_http_credentials
531
-
532
526
  def set_offline(offline)
533
527
  raise NotImplementedError.new('set_offline is not implemented yet.')
534
528
  end
@@ -545,9 +539,46 @@ module Playwright
545
539
  raise NotImplementedError.new('unroute is not implemented yet.')
546
540
  end
547
541
 
548
- # @nodoc
549
- def after_initialize
550
- wrap_impl(@impl.after_initialize)
542
+ # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
543
+ # value. Will throw an error if the context closes before the event is fired. Returns the event data value.
544
+ #
545
+ #
546
+ # ```js
547
+ # const [page, _] = await Promise.all([
548
+ # context.waitForEvent('page'),
549
+ # page.click('button')
550
+ # ]);
551
+ # ```
552
+ #
553
+ # ```python async
554
+ # async with context.expect_event("page") as event_info:
555
+ # await page.click("button")
556
+ # page = await event_info.value
557
+ # ```
558
+ #
559
+ # ```python sync
560
+ # with context.expect_event("page") as event_info:
561
+ # page.click("button")
562
+ # page = event_info.value
563
+ # ```
564
+ def expect_event(event, predicate: nil, timeout: nil)
565
+ raise NotImplementedError.new('expect_event is not implemented yet.')
566
+ end
567
+
568
+ # Performs action and waits for `page` event to fire. If predicate is provided, it passes `Page` value into the
569
+ # `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
570
+ # closed before the worker event is fired.
571
+ def expect_page(predicate: nil, timeout: nil)
572
+ raise NotImplementedError.new('expect_page is not implemented yet.')
573
+ end
574
+
575
+ # > NOTE: In most cases, you should use [`method: BrowserContext.waitForEvent`].
576
+ #
577
+ # Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function and
578
+ # waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is closed before the `event` is
579
+ # fired.
580
+ def wait_for_event(event, predicate: nil, timeout: nil)
581
+ raise NotImplementedError.new('wait_for_event is not implemented yet.')
551
582
  end
552
583
 
553
584
  # @nodoc
@@ -49,11 +49,6 @@ module Playwright
49
49
  # ```
50
50
  class BrowserType < PlaywrightApi
51
51
 
52
- # This methods attaches Playwright to an existing browser instance.
53
- def connect(params)
54
- raise NotImplementedError.new('connect is not implemented yet.')
55
- end
56
-
57
52
  # A path where Playwright expects to find a bundled browser executable.
58
53
  def executable_path
59
54
  wrap_impl(@impl.executable_path)
@@ -108,14 +103,12 @@ module Playwright
108
103
  handleSIGINT: nil,
109
104
  handleSIGTERM: nil,
110
105
  headless: nil,
111
- ignoreAllDefaultArgs: nil,
112
106
  ignoreDefaultArgs: nil,
113
- logger: nil,
114
107
  proxy: nil,
115
108
  slowMo: nil,
116
109
  timeout: nil,
117
110
  &block)
118
- wrap_impl(@impl.launch(args: unwrap_impl(args), chromiumSandbox: unwrap_impl(chromiumSandbox), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), firefoxUserPrefs: unwrap_impl(firefoxUserPrefs), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), headless: unwrap_impl(headless), ignoreAllDefaultArgs: unwrap_impl(ignoreAllDefaultArgs), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), logger: unwrap_impl(logger), proxy: unwrap_impl(proxy), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
111
+ wrap_impl(@impl.launch(args: unwrap_impl(args), chromiumSandbox: unwrap_impl(chromiumSandbox), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), firefoxUserPrefs: unwrap_impl(firefoxUserPrefs), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), headless: unwrap_impl(headless), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), proxy: unwrap_impl(proxy), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
119
112
  end
120
113
 
121
114
  # Returns the persistent browser context instance.
@@ -142,64 +135,27 @@ module Playwright
142
135
  hasTouch: nil,
143
136
  headless: nil,
144
137
  httpCredentials: nil,
145
- ignoreAllDefaultArgs: nil,
146
138
  ignoreDefaultArgs: nil,
147
139
  ignoreHTTPSErrors: nil,
148
140
  isMobile: nil,
149
141
  javaScriptEnabled: nil,
150
142
  locale: nil,
151
- logger: nil,
143
+ noViewport: nil,
152
144
  offline: nil,
153
145
  permissions: nil,
154
146
  proxy: nil,
155
- recordHar: nil,
156
- recordVideo: nil,
147
+ record_har_omit_content: nil,
148
+ record_har_path: nil,
149
+ record_video_dir: nil,
150
+ record_video_size: nil,
157
151
  slowMo: nil,
158
152
  timeout: nil,
159
153
  timezoneId: nil,
160
154
  userAgent: nil,
161
- videoSize: nil,
162
- videosPath: nil,
163
155
  viewport: nil)
164
156
  raise NotImplementedError.new('launch_persistent_context is not implemented yet.')
165
157
  end
166
158
 
167
- # Returns the browser app instance.
168
- #
169
- # Launches browser server that client can connect to. An example of launching a browser executable and connecting to it
170
- # later:
171
- #
172
- #
173
- # ```js
174
- # const { chromium } = require('playwright'); // Or 'webkit' or 'firefox'.
175
- #
176
- # (async () => {
177
- # const browserServer = await chromium.launchServer();
178
- # const wsEndpoint = browserServer.wsEndpoint();
179
- # // Use web socket endpoint later to establish a connection.
180
- # const browser = await chromium.connect({ wsEndpoint });
181
- # // Close browser instance.
182
- # await browserServer.close();
183
- # })();
184
- # ```
185
- def launch_server(
186
- args: nil,
187
- chromiumSandbox: nil,
188
- devtools: nil,
189
- downloadsPath: nil,
190
- executablePath: nil,
191
- firefoxUserPrefs: nil,
192
- handleSIGHUP: nil,
193
- handleSIGINT: nil,
194
- handleSIGTERM: nil,
195
- headless: nil,
196
- logger: nil,
197
- port: nil,
198
- proxy: nil,
199
- timeout: nil)
200
- raise NotImplementedError.new('launch_server is not implemented yet.')
201
- end
202
-
203
159
  # Returns browser name. For example: `'chromium'`, `'webkit'` or `'firefox'`.
204
160
  def name
205
161
  wrap_impl(@impl.name)
@@ -37,11 +37,6 @@ module Playwright
37
37
  # performed and user has no access to the downloaded files.
38
38
  class Download < PlaywrightApi
39
39
 
40
- # Returns readable stream for current download or `null` if download failed.
41
- def create_read_stream
42
- raise NotImplementedError.new('create_read_stream is not implemented yet.')
43
- end
44
-
45
40
  # Deletes the downloaded file.
46
41
  def delete
47
42
  wrap_impl(@impl.delete)
@@ -467,8 +467,14 @@ module Playwright
467
467
  # # multiple selection for blue, red and second option
468
468
  # handle.select_option(value="blue", { index: 2 }, "red")
469
469
  # ```
470
- def select_option(values, noWaitAfter: nil, timeout: nil)
471
- wrap_impl(@impl.select_option(unwrap_impl(values), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
470
+ def select_option(
471
+ element: nil,
472
+ index: nil,
473
+ value: nil,
474
+ label: nil,
475
+ noWaitAfter: nil,
476
+ timeout: nil)
477
+ wrap_impl(@impl.select_option(element: unwrap_impl(element), index: unwrap_impl(index), value: unwrap_impl(value), label: unwrap_impl(label), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
472
478
  end
473
479
 
474
480
  # This method waits for [actionability](./actionability.md) checks, then focuses the element and selects all its text
@@ -645,8 +645,15 @@ module Playwright
645
645
  # # multiple selection
646
646
  # frame.select_option("select#colors", value=["red", "green", "blue"])
647
647
  # ```
648
- def select_option(selector, values, noWaitAfter: nil, timeout: nil)
649
- wrap_impl(@impl.select_option(unwrap_impl(selector), unwrap_impl(values), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
648
+ def select_option(
649
+ selector,
650
+ element: nil,
651
+ index: nil,
652
+ value: nil,
653
+ label: nil,
654
+ noWaitAfter: nil,
655
+ timeout: nil)
656
+ 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)))
650
657
  end
651
658
 
652
659
  def set_content(html, timeout: nil, waitUntil: nil)
@@ -953,11 +960,6 @@ module Playwright
953
960
  wrap_impl(@impl.detached=(unwrap_impl(req)))
954
961
  end
955
962
 
956
- # @nodoc
957
- def after_initialize
958
- wrap_impl(@impl.after_initialize)
959
- end
960
-
961
963
  # -- inherited from EventEmitter --
962
964
  # @nodoc
963
965
  def once(event, callback)
@@ -122,11 +122,6 @@ module Playwright
122
122
  wrap_impl(@impl.json_value)
123
123
  end
124
124
 
125
- # @nodoc
126
- def after_initialize
127
- wrap_impl(@impl.after_initialize)
128
- end
129
-
130
125
  # -- inherited from EventEmitter --
131
126
  # @nodoc
132
127
  def once(event, callback)
@@ -96,12 +96,6 @@ module Playwright
96
96
  wrap_impl(@impl.accessibility)
97
97
  end
98
98
 
99
- # Browser-specific Coverage implementation, only available for Chromium atm. See
100
- # `ChromiumCoverage`(#class-chromiumcoverage) for more details.
101
- def coverage # property
102
- raise NotImplementedError.new('coverage is not implemented yet.')
103
- end
104
-
105
99
  def keyboard # property
106
100
  wrap_impl(@impl.keyboard)
107
101
  end
@@ -148,8 +142,8 @@ module Playwright
148
142
  #
149
143
  # > NOTE: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
150
144
  # [`method: Page.addInitScript`] is not defined.
151
- def add_init_script(script, arg: nil)
152
- wrap_impl(@impl.add_init_script(unwrap_impl(script), arg: unwrap_impl(arg)))
145
+ def add_init_script(path: nil, script: nil)
146
+ wrap_impl(@impl.add_init_script(path: unwrap_impl(path), script: unwrap_impl(script)))
153
147
  end
154
148
 
155
149
  # Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload
@@ -880,8 +874,8 @@ module Playwright
880
874
  # ```py
881
875
  # frame = page.frame(url=r".*domain.*")
882
876
  # ```
883
- def frame(frameSelector)
884
- wrap_impl(@impl.frame(unwrap_impl(frameSelector)))
877
+ def frame(name: nil, url: nil)
878
+ wrap_impl(@impl.frame(name: unwrap_impl(name), url: unwrap_impl(url)))
885
879
  end
886
880
 
887
881
  # An array of all frames attached to the page.
@@ -1299,8 +1293,15 @@ module Playwright
1299
1293
  # ```
1300
1294
  #
1301
1295
  # Shortcut for main frame's [`method: Frame.selectOption`]
1302
- def select_option(selector, values, noWaitAfter: nil, timeout: nil)
1303
- wrap_impl(@impl.select_option(unwrap_impl(selector), unwrap_impl(values), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
1296
+ def select_option(
1297
+ selector,
1298
+ element: nil,
1299
+ index: nil,
1300
+ value: nil,
1301
+ label: nil,
1302
+ noWaitAfter: nil,
1303
+ timeout: nil)
1304
+ 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)))
1304
1305
  end
1305
1306
 
1306
1307
  def set_content(html, timeout: nil, waitUntil: nil)
@@ -1483,6 +1484,32 @@ module Playwright
1483
1484
  wrap_impl(@impl.viewport_size)
1484
1485
  end
1485
1486
 
1487
+ # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
1488
+ # value. Will throw an error if the page is closed before the event is fired. Returns the event data value.
1489
+ #
1490
+ #
1491
+ # ```js
1492
+ # const [frame, _] = await Promise.all([
1493
+ # page.waitForEvent('framenavigated'),
1494
+ # page.click('button')
1495
+ # ]);
1496
+ # ```
1497
+ #
1498
+ # ```python async
1499
+ # async with page.expect_event("framenavigated") as event_info:
1500
+ # await page.click("button")
1501
+ # frame = await event_info.value
1502
+ # ```
1503
+ #
1504
+ # ```python sync
1505
+ # with page.expect_event("framenavigated") as event_info:
1506
+ # page.click("button")
1507
+ # frame = event_info.value
1508
+ # ```
1509
+ def expect_event(event, predicate: nil, timeout: nil, &block)
1510
+ wrap_impl(@impl.expect_event(unwrap_impl(event), predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
1511
+ end
1512
+
1486
1513
  # Returns when the `expression` returns a truthy value. It resolves to a JSHandle of the truthy value.
1487
1514
  #
1488
1515
  # The [`method: Page.waitForFunction`] can be used to observe viewport size change:
@@ -1807,14 +1834,48 @@ module Playwright
1807
1834
  raise NotImplementedError.new('workers is not implemented yet.')
1808
1835
  end
1809
1836
 
1810
- # @nodoc
1811
- def after_initialize
1812
- wrap_impl(@impl.after_initialize)
1837
+ # Performs action and waits for `download` event to fire. If predicate is provided, it passes `Download` value into the
1838
+ # `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
1839
+ # closed before the download event is fired.
1840
+ def expect_download(predicate: nil, timeout: nil)
1841
+ raise NotImplementedError.new('expect_download is not implemented yet.')
1813
1842
  end
1814
1843
 
1815
- # @nodoc
1816
- def expect_event(event, optionsOrPredicate: nil, &block)
1817
- wrap_impl(@impl.expect_event(unwrap_impl(event), optionsOrPredicate: unwrap_impl(optionsOrPredicate), &wrap_block_call(block)))
1844
+ # Performs action and waits for `popup` event to fire. If predicate is provided, it passes [Popup] value into the
1845
+ # `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
1846
+ # closed before the popup event is fired.
1847
+ def expect_popup(predicate: nil, timeout: nil)
1848
+ raise NotImplementedError.new('expect_popup is not implemented yet.')
1849
+ end
1850
+
1851
+ # Performs action and waits for `worker` event to fire. If predicate is provided, it passes `Worker` value into the
1852
+ # `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
1853
+ # closed before the worker event is fired.
1854
+ def expect_worker(predicate: nil, timeout: nil)
1855
+ raise NotImplementedError.new('expect_worker is not implemented yet.')
1856
+ end
1857
+
1858
+ # Performs action and waits for `console` event to fire. If predicate is provided, it passes `ConsoleMessage` value into
1859
+ # the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
1860
+ # closed before the worker event is fired.
1861
+ def expect_console_message(predicate: nil, timeout: nil)
1862
+ raise NotImplementedError.new('expect_console_message is not implemented yet.')
1863
+ end
1864
+
1865
+ # Performs action and waits for `filechooser` event to fire. If predicate is provided, it passes `FileChooser` value into
1866
+ # the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
1867
+ # closed before the worker event is fired.
1868
+ def expect_file_chooser(predicate: nil, timeout: nil)
1869
+ raise NotImplementedError.new('expect_file_chooser is not implemented yet.')
1870
+ end
1871
+
1872
+ # > NOTE: In most cases, you should use [`method: Page.waitForEvent`].
1873
+ #
1874
+ # Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function and
1875
+ # waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is closed before the `event` is
1876
+ # fired.
1877
+ def wait_for_event(event, predicate: nil, timeout: nil)
1878
+ raise NotImplementedError.new('wait_for_event is not implemented yet.')
1818
1879
  end
1819
1880
 
1820
1881
  # @nodoc
@@ -113,42 +113,6 @@ module Playwright
113
113
  wrap_impl(@impl.devices)
114
114
  end
115
115
 
116
- # Playwright methods might throw errors if they are unable to fulfill a request. For example,
117
- # [`method: Page.waitForSelector`] might fail if the selector doesn't match any nodes during the given timeframe.
118
- #
119
- # For certain types of errors Playwright uses specific error classes. These classes are available via
120
- # [`playwright.errors`](#playwrighterrors).
121
- #
122
- # An example of handling a timeout error:
123
- #
124
- #
125
- # ```js
126
- # try {
127
- # await page.waitForSelector('.foo');
128
- # } catch (e) {
129
- # if (e instanceof playwright.errors.TimeoutError) {
130
- # // Do something if this is a timeout.
131
- # }
132
- # }
133
- # ```
134
- #
135
- # ```python async
136
- # try:
137
- # await page.wait_for_selector(".foo")
138
- # except TimeoutError as e:
139
- # # do something if this is a timeout.
140
- # ```
141
- #
142
- # ```python sync
143
- # try:
144
- # page.wait_for_selector(".foo")
145
- # except TimeoutError as e:
146
- # # do something if this is a timeout.
147
- # ```
148
- def errors # property
149
- raise NotImplementedError.new('errors is not implemented yet.')
150
- end
151
-
152
116
  # This object can be used to launch or connect to Firefox, returning instances of `FirefoxBrowser`.
153
117
  def firefox # property
154
118
  wrap_impl(@impl.firefox)
@@ -165,19 +129,34 @@ module Playwright
165
129
  wrap_impl(@impl.webkit)
166
130
  end
167
131
 
168
- # Terminates this instance of Playwright, will also close all created browsers if they are still running.
169
- def close
170
- raise NotImplementedError.new('close is not implemented yet.')
132
+ # Terminates this instance of Playwright in case it was created bypassing the Python context manager. This is useful in
133
+ # REPL applications.
134
+ #
135
+ # ```py
136
+ # >>> from playwright.sync_api import sync_playwright
137
+ #
138
+ # >>> playwright = sync_playwright().start()
139
+ #
140
+ # >>> browser = playwright.chromium.launch()
141
+ # >>> page = browser.new_page()
142
+ # >>> page.goto("http://whatsmyuseragent.org/")
143
+ # >>> page.screenshot(path="example.png")
144
+ # >>> browser.close()
145
+ #
146
+ # >>> playwright.stop()
147
+ # ```
148
+ def stop
149
+ raise NotImplementedError.new('stop is not implemented yet.')
171
150
  end
172
151
 
173
152
  # @nodoc
174
- def electron
175
- wrap_impl(@impl.electron)
153
+ def android
154
+ wrap_impl(@impl.android)
176
155
  end
177
156
 
178
157
  # @nodoc
179
- def android
180
- wrap_impl(@impl.android)
158
+ def electron
159
+ wrap_impl(@impl.electron)
181
160
  end
182
161
 
183
162
  # -- inherited from EventEmitter --
@@ -62,6 +62,14 @@ module Playwright
62
62
  wrap_impl(@impl.post_data_buffer)
63
63
  end
64
64
 
65
+ # Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
66
+ #
67
+ # When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
68
+ # Otherwise it will be parsed as JSON.
69
+ def post_data_json
70
+ wrap_impl(@impl.post_data_json)
71
+ end
72
+
65
73
  # Request that was redirected by the server to this one, if any.
66
74
  #
67
75
  # When the server responds with a redirect, Playwright creates a new `Request` object. The two requests are connected by
@@ -170,16 +178,6 @@ module Playwright
170
178
  wrap_impl(@impl.url)
171
179
  end
172
180
 
173
- # @nodoc
174
- def post_data_json
175
- wrap_impl(@impl.post_data_json)
176
- end
177
-
178
- # @nodoc
179
- def after_initialize
180
- wrap_impl(@impl.after_initialize)
181
- end
182
-
183
181
  # -- inherited from EventEmitter --
184
182
  # @nodoc
185
183
  def once(event, callback)
@@ -22,6 +22,13 @@ module Playwright
22
22
  raise NotImplementedError.new('headers is not implemented yet.')
23
23
  end
24
24
 
25
+ # Returns the JSON representation of response body.
26
+ #
27
+ # This method will throw if the response body is not parsable via `JSON.parse`.
28
+ def json
29
+ raise NotImplementedError.new('json is not implemented yet.')
30
+ end
31
+
25
32
  # Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
26
33
  def ok
27
34
  raise NotImplementedError.new('ok is not implemented yet.')
@@ -97,7 +97,6 @@ module Playwright
97
97
  # ```
98
98
  def fulfill(
99
99
  body: nil,
100
- bodyBytes: nil,
101
100
  contentType: nil,
102
101
  headers: nil,
103
102
  path: nil,
@@ -48,7 +48,7 @@ module Playwright
48
48
  # ```python sync
49
49
  # # FIXME: add snippet
50
50
  # ```
51
- def register(name, script, contentScript: nil)
51
+ def register(name, contentScript: nil, path: nil, script: nil)
52
52
  raise NotImplementedError.new('register is not implemented yet.')
53
53
  end
54
54
 
@@ -11,5 +11,20 @@ module Playwright
11
11
  def url
12
12
  raise NotImplementedError.new('url is not implemented yet.')
13
13
  end
14
+
15
+ # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
16
+ # value. Will throw an error if the webSocket is closed before the event is fired. Returns the event data value.
17
+ def expect_event(event, predicate: nil, timeout: nil)
18
+ raise NotImplementedError.new('expect_event is not implemented yet.')
19
+ end
20
+
21
+ # > NOTE: In most cases, you should use [`method: WebSocket.waitForEvent`].
22
+ #
23
+ # Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function and
24
+ # waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is closed before the `event` is
25
+ # fired.
26
+ def wait_for_event(event, predicate: nil, timeout: nil)
27
+ raise NotImplementedError.new('wait_for_event is not implemented yet.')
28
+ end
14
29
  end
15
30
  end
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: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-18 00:00:00.000000000 Z
11
+ date: 2021-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby