playwright-ruby-client 0.5.8 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/documentation/README.md +33 -0
  4. data/documentation/babel.config.js +3 -0
  5. data/documentation/docs/api/accessibility.md +7 -0
  6. data/documentation/docs/api/browser.md +187 -0
  7. data/documentation/docs/api/browser_context.md +397 -0
  8. data/documentation/docs/api/browser_type.md +105 -0
  9. data/documentation/docs/api/cdp_session.md +7 -0
  10. data/documentation/docs/api/console_message.md +41 -0
  11. data/documentation/docs/api/dialog.md +71 -0
  12. data/documentation/docs/api/element_handle.md +618 -0
  13. data/documentation/docs/api/experimental/_category_.yml +3 -0
  14. data/documentation/docs/api/experimental/android.md +25 -0
  15. data/documentation/docs/api/experimental/android_device.md +92 -0
  16. data/documentation/docs/api/experimental/android_input.md +38 -0
  17. data/documentation/docs/api/experimental/android_socket.md +7 -0
  18. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  19. data/documentation/docs/api/file_chooser.md +50 -0
  20. data/documentation/docs/api/frame.md +866 -0
  21. data/documentation/docs/api/js_handle.md +113 -0
  22. data/documentation/docs/api/keyboard.md +157 -0
  23. data/documentation/docs/api/mouse.md +69 -0
  24. data/documentation/docs/api/page.md +1402 -0
  25. data/documentation/docs/api/playwright.md +63 -0
  26. data/documentation/docs/api/request.md +188 -0
  27. data/documentation/docs/api/response.md +97 -0
  28. data/documentation/docs/api/route.md +80 -0
  29. data/documentation/docs/api/selectors.md +23 -0
  30. data/documentation/docs/api/touchscreen.md +8 -0
  31. data/documentation/docs/api/tracing.md +54 -0
  32. data/documentation/docs/api/web_socket.md +7 -0
  33. data/documentation/docs/api/worker.md +24 -0
  34. data/documentation/docs/article/api_coverage.mdx +11 -0
  35. data/documentation/docs/article/getting_started.md +152 -0
  36. data/documentation/docs/article/guides/_category_.yml +3 -0
  37. data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
  38. data/documentation/docs/article/guides/launch_browser.md +119 -0
  39. data/documentation/docs/article/guides/rails_integration.md +51 -0
  40. data/{docs → documentation/docs/include}/api_coverage.md +13 -2
  41. data/documentation/docusaurus.config.js +107 -0
  42. data/documentation/package.json +39 -0
  43. data/documentation/sidebars.js +15 -0
  44. data/documentation/src/components/HomepageFeatures.js +61 -0
  45. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  46. data/documentation/src/css/custom.css +44 -0
  47. data/documentation/src/pages/index.js +50 -0
  48. data/documentation/src/pages/index.module.css +41 -0
  49. data/documentation/src/pages/markdown-page.md +7 -0
  50. data/documentation/static/.nojekyll +0 -0
  51. data/documentation/static/img/playwright-logo.svg +9 -0
  52. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  53. data/documentation/static/img/undraw_web_development.svg +1 -0
  54. data/documentation/static/img/undraw_windows.svg +1 -0
  55. data/documentation/yarn.lock +8805 -0
  56. data/lib/playwright/channel_owners/binding_call.rb +33 -0
  57. data/lib/playwright/channel_owners/browser.rb +27 -2
  58. data/lib/playwright/channel_owners/browser_context.rb +54 -3
  59. data/lib/playwright/channel_owners/browser_type.rb +8 -1
  60. data/lib/playwright/channel_owners/element_handle.rb +17 -16
  61. data/lib/playwright/channel_owners/frame.rb +29 -34
  62. data/lib/playwright/channel_owners/js_handle.rb +2 -10
  63. data/lib/playwright/channel_owners/page.rb +35 -51
  64. data/lib/playwright/channel_owners/worker.rb +4 -0
  65. data/lib/playwright/download.rb +3 -2
  66. data/lib/playwright/events.rb +4 -0
  67. data/lib/playwright/input_files.rb +0 -8
  68. data/lib/playwright/javascript.rb +0 -10
  69. data/lib/playwright/javascript/expression.rb +2 -7
  70. data/lib/playwright/playwright_api.rb +16 -1
  71. data/lib/playwright/tracing_impl.rb +31 -0
  72. data/lib/playwright/version.rb +2 -1
  73. data/lib/playwright_api/accessibility.rb +7 -88
  74. data/lib/playwright_api/android.rb +2 -59
  75. data/lib/playwright_api/android_device.rb +6 -5
  76. data/lib/playwright_api/browser.rb +13 -122
  77. data/lib/playwright_api/browser_context.rb +66 -433
  78. data/lib/playwright_api/browser_type.rb +28 -78
  79. data/lib/playwright_api/cdp_session.rb +2 -25
  80. data/lib/playwright_api/console_message.rb +2 -0
  81. data/lib/playwright_api/dialog.rb +5 -63
  82. data/lib/playwright_api/element_handle.rb +96 -294
  83. data/lib/playwright_api/file_chooser.rb +0 -21
  84. data/lib/playwright_api/frame.rb +99 -565
  85. data/lib/playwright_api/js_handle.rb +10 -67
  86. data/lib/playwright_api/keyboard.rb +22 -166
  87. data/lib/playwright_api/mouse.rb +1 -45
  88. data/lib/playwright_api/page.rb +222 -1223
  89. data/lib/playwright_api/playwright.rb +8 -93
  90. data/lib/playwright_api/request.rb +9 -87
  91. data/lib/playwright_api/response.rb +1 -1
  92. data/lib/playwright_api/route.rb +3 -80
  93. data/lib/playwright_api/selectors.rb +0 -66
  94. data/lib/playwright_api/tracing.rb +39 -0
  95. data/lib/playwright_api/web_socket.rb +1 -1
  96. data/lib/playwright_api/worker.rb +28 -42
  97. data/playwright.gemspec +2 -2
  98. metadata +60 -20
  99. data/lib/playwright/javascript/function.rb +0 -67
@@ -14,19 +14,11 @@ module Playwright
14
14
  end
15
15
 
16
16
  def evaluate(pageFunction, arg: nil)
17
- if JavaScript.function?(pageFunction)
18
- JavaScript::Function.new(pageFunction, arg).evaluate(@channel)
19
- else
20
- JavaScript::Expression.new(pageFunction).evaluate(@channel)
21
- end
17
+ JavaScript::Expression.new(pageFunction, arg).evaluate(@channel)
22
18
  end
23
19
 
24
20
  def evaluate_handle(pageFunction, arg: nil)
25
- if JavaScript.function?(pageFunction)
26
- JavaScript::Function.new(pageFunction, arg).evaluate_handle(@channel)
27
- else
28
- JavaScript::Expression.new(pageFunction).evaluate_handle(@channel)
29
- end
21
+ JavaScript::Expression.new(pageFunction, arg).evaluate_handle(@channel)
30
22
  end
31
23
 
32
24
  def get_properties
@@ -30,6 +30,7 @@ module Playwright
30
30
  @frames << @main_frame
31
31
  @opener = ChannelOwners::Page.from_nullable(@initializer['opener'])
32
32
 
33
+ @channel.on('bindingCall', ->(params) { on_binding(ChannelOwners::BindingCall.from(params['binding'])) })
33
34
  @channel.once('close', ->(_) { on_close })
34
35
  @channel.on('console', ->(params) {
35
36
  console_message = ChannelOwners::ConsoleMessage.from(params['message'])
@@ -56,25 +57,6 @@ module Playwright
56
57
  @channel.on('pageError', ->(params) {
57
58
  emit(Events::Page::PageError, Error.parse(params['error']['error']))
58
59
  })
59
- @channel.on('request', ->(params) {
60
- emit(Events::Page::Request, ChannelOwners::Request.from(params['request']))
61
- })
62
- @channel.on('requestFailed', ->(params) {
63
- on_request_failed(
64
- ChannelOwners::Request.from(params['request']),
65
- params['responseEndTiming'],
66
- params['failureText'],
67
- )
68
- })
69
- @channel.on('requestFinished', ->(params) {
70
- on_request_finished(
71
- ChannelOwners::Request.from(params['request']),
72
- params['responseEndTiming'],
73
- )
74
- })
75
- @channel.on('response', ->(params) {
76
- emit(Events::Page::Response, ChannelOwners::Response.from(params['response']))
77
- })
78
60
  @channel.on('route', ->(params) {
79
61
  on_route(ChannelOwners::Route.from(params['route']), ChannelOwners::Request.from(params['request']))
80
62
  })
@@ -95,17 +77,6 @@ module Playwright
95
77
  :viewport_size,
96
78
  :main_frame
97
79
 
98
- private def on_request_failed(request, response_end_timing, failure_text)
99
- request.send(:update_failure_text, failure_text)
100
- request.send(:update_response_end_timing, response_end_timing)
101
- emit(Events::Page::RequestFailed, request)
102
- end
103
-
104
- private def on_request_finished(request, response_end_timing)
105
- request.send(:update_response_end_timing, response_end_timing)
106
- emit(Events::Page::RequestFinished, request)
107
- end
108
-
109
80
  private def on_frame_attached(frame)
110
81
  frame.send(:update_page_from_page, self)
111
82
  @frames << frame
@@ -130,6 +101,14 @@ module Playwright
130
101
  end
131
102
  end
132
103
 
104
+ private def on_binding(binding_call)
105
+ func = @bindings[binding_call.name]
106
+ if func
107
+ binding_call.call_async(func)
108
+ end
109
+ @browser_context.send(:on_binding, binding_call)
110
+ end
111
+
133
112
  private def on_close
134
113
  @closed = true
135
114
  @browser_context.send(:remove_page, self)
@@ -145,6 +124,7 @@ module Playwright
145
124
 
146
125
  private def on_download(params)
147
126
  download = Download.new(
127
+ page: self,
148
128
  url: params['url'],
149
129
  suggested_filename: params['suggestedFilename'],
150
130
  artifact: ChannelOwners::Artifact.from(params['artifact']),
@@ -335,7 +315,7 @@ module Playwright
335
315
  timeout: timeout,
336
316
  waitUntil: waitUntil,
337
317
  }.compact
338
- resp = @channel.send_message_to_server('reoad', params)
318
+ resp = @channel.send_message_to_server('reload', params)
339
319
  ChannelOwners::Response.from_nullable(resp)
340
320
  end
341
321
 
@@ -359,10 +339,11 @@ module Playwright
359
339
  ChannelOwners::Response.from_nullable(resp)
360
340
  end
361
341
 
362
- def emulate_media(colorScheme: nil, media: nil)
342
+ def emulate_media(colorScheme: nil, media: nil, reducedMotion: nil)
363
343
  params = {
364
344
  colorScheme: colorScheme,
365
345
  media: media,
346
+ reducedMotion: reducedMotion,
366
347
  }.compact
367
348
  @channel.send_message_to_server('emulateMedia', params)
368
349
 
@@ -464,7 +445,8 @@ module Playwright
464
445
  modifiers: nil,
465
446
  noWaitAfter: nil,
466
447
  position: nil,
467
- timeout: nil)
448
+ timeout: nil,
449
+ trial: nil)
468
450
 
469
451
  @main_frame.click(
470
452
  selector,
@@ -476,6 +458,7 @@ module Playwright
476
458
  noWaitAfter: noWaitAfter,
477
459
  position: position,
478
460
  timeout: timeout,
461
+ trial: trial,
479
462
  )
480
463
  end
481
464
 
@@ -487,7 +470,8 @@ module Playwright
487
470
  modifiers: nil,
488
471
  noWaitAfter: nil,
489
472
  position: nil,
490
- timeout: nil)
473
+ timeout: nil,
474
+ trial: nil)
491
475
  @main_frame.dblclick(
492
476
  selector,
493
477
  button: button,
@@ -497,6 +481,7 @@ module Playwright
497
481
  noWaitAfter: noWaitAfter,
498
482
  position: position,
499
483
  timeout: timeout,
484
+ trial: trial,
500
485
  )
501
486
  end
502
487
 
@@ -506,7 +491,8 @@ module Playwright
506
491
  modifiers: nil,
507
492
  noWaitAfter: nil,
508
493
  position: nil,
509
- timeout: nil)
494
+ timeout: nil,
495
+ trial: nil)
510
496
  @main_frame.tap_point(
511
497
  selector,
512
498
  force: force,
@@ -514,6 +500,7 @@ module Playwright
514
500
  noWaitAfter: noWaitAfter,
515
501
  position: position,
516
502
  timeout: timeout,
503
+ trial: trial,
517
504
  )
518
505
  end
519
506
 
@@ -546,13 +533,15 @@ module Playwright
546
533
  force: nil,
547
534
  modifiers: nil,
548
535
  position: nil,
549
- timeout: nil)
536
+ timeout: nil,
537
+ trial: nil)
550
538
  @main_frame.hover(
551
539
  selector,
552
540
  force: force,
553
541
  modifiers: modifiers,
554
542
  position: position,
555
543
  timeout: timeout,
544
+ trial: trial,
556
545
  )
557
546
  end
558
547
 
@@ -604,9 +593,10 @@ module Playwright
604
593
  force: nil,
605
594
  noWaitAfter: nil,
606
595
  position: nil,
607
- timeout: nil)
596
+ timeout: nil,
597
+ trial: nil)
608
598
 
609
- @main_frame.check(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout)
599
+ @main_frame.check(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout, trial: trial)
610
600
  end
611
601
 
612
602
  def uncheck(
@@ -614,9 +604,10 @@ module Playwright
614
604
  force: nil,
615
605
  noWaitAfter: nil,
616
606
  position: nil,
617
- timeout: nil)
607
+ timeout: nil,
608
+ trial: nil)
618
609
 
619
- @main_frame.uncheck(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout)
610
+ @main_frame.uncheck(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout, trial: trial)
620
611
  end
621
612
 
622
613
  def wait_for_function(pageFunction, arg: nil, polling: nil, timeout: nil)
@@ -723,7 +714,6 @@ module Playwright
723
714
  end
724
715
 
725
716
  wait_helper.wait_for_event(self, event, predicate: predicate)
726
-
727
717
  block&.call
728
718
 
729
719
  wait_helper.promise.value!
@@ -753,7 +743,7 @@ module Playwright
753
743
  expect_event(Events::Page::Popup, predicate: predicate, timeout: timeout, &block)
754
744
  end
755
745
 
756
- def expect_request(urlOrPredicate, timeout: nil)
746
+ def expect_request(urlOrPredicate, timeout: nil, &block)
757
747
  predicate =
758
748
  case urlOrPredicate
759
749
  when String, Regexp
@@ -765,10 +755,10 @@ module Playwright
765
755
  -> (_) { true }
766
756
  end
767
757
 
768
- expect_event(Events::Page::Request, predicate: predicate, timeout: timeout)
758
+ expect_event(Events::Page::Request, predicate: predicate, timeout: timeout, &block)
769
759
  end
770
760
 
771
- def expect_response(urlOrPredicate, timeout: nil)
761
+ def expect_response(urlOrPredicate, timeout: nil, &block)
772
762
  predicate =
773
763
  case urlOrPredicate
774
764
  when String, Regexp
@@ -780,13 +770,7 @@ module Playwright
780
770
  -> (_) { true }
781
771
  end
782
772
 
783
- expect_event(Events::Page::Response, predicate: predicate, timeout: timeout)
784
- end
785
-
786
- # called from BrowserContext#on_page with send(:update_browser_context, page), so keep private.
787
- private def update_browser_context(context)
788
- @browser_context = context
789
- @timeout_settings = TimeoutSettings.new(context.send(:_timeout_settings))
773
+ expect_event(Events::Page::Response, predicate: predicate, timeout: timeout, &block)
790
774
  end
791
775
 
792
776
  # called from Frame with send(:timeout_settings)
@@ -0,0 +1,4 @@
1
+ module Playwright
2
+ define_channel_owner :Worker do
3
+ end
4
+ end
@@ -1,12 +1,13 @@
1
1
  module Playwright
2
2
  class Download
3
- def initialize(url:, suggested_filename:, artifact:)
3
+ def initialize(page:, url:, suggested_filename:, artifact:)
4
+ @page = page
4
5
  @url = url
5
6
  @suggested_filename = suggested_filename
6
7
  @artifact = artifact
7
8
  end
8
9
 
9
- attr_reader :url, :suggested_filename
10
+ attr_reader :page, :url, :suggested_filename
10
11
 
11
12
  def delete
12
13
  @artifact.delete
@@ -28,6 +28,10 @@ end
28
28
  Close: 'close',
29
29
  Page: 'page',
30
30
  ServiceWorker: 'serviceworker',
31
+ Request: 'request',
32
+ Response: 'response',
33
+ RequestFailed: 'requestfailed',
34
+ RequestFinished: 'requestfinished',
31
35
  },
32
36
 
33
37
  BrowserServer: {
@@ -1,5 +1,4 @@
1
1
  require 'base64'
2
- require 'mime/types'
3
2
 
4
3
  module Playwright
5
4
  class InputFiles
@@ -19,13 +18,11 @@ module Playwright
19
18
  when String
20
19
  {
21
20
  name: File.basename(file),
22
- mimeType: mime_type_for(file),
23
21
  buffer: Base64.strict_encode64(File.read(file)),
24
22
  }
25
23
  when File
26
24
  {
27
25
  name: File.basename(file.path),
28
- mimeType: mime_type_for(file.path),
29
26
  buffer: Base64.strict_encode64(file.read),
30
27
  }
31
28
  else
@@ -33,10 +30,5 @@ module Playwright
33
30
  end
34
31
  end
35
32
  end
36
-
37
- private def mime_type_for(filepath)
38
- mime_types = MIME::Types.type_for(filepath)
39
- mime_types.first.to_s || 'application/octet-stream'
40
- end
41
33
  end
42
34
  end
@@ -1,13 +1,3 @@
1
1
  require_relative './javascript/expression'
2
- require_relative './javascript/function'
3
2
  require_relative './javascript/value_parser'
4
3
  require_relative './javascript/value_serializer'
5
-
6
- module Playwright
7
- module JavaScript
8
- # Detect if str is likely to be a function
9
- module_function def function?(str)
10
- ['async', 'function'].any? { |key| str.strip.start_with?(key) } || str.include?('=>')
11
- end
12
- end
13
- end
@@ -1,16 +1,15 @@
1
1
  module Playwright
2
2
  module JavaScript
3
3
  class Expression
4
- def initialize(expression)
4
+ def initialize(expression, arg)
5
5
  @expression = expression
6
- @serialized_arg = ValueSerializer.new(nil).serialize
6
+ @serialized_arg = ValueSerializer.new(arg).serialize
7
7
  end
8
8
 
9
9
  def evaluate(channel)
10
10
  value = channel.send_message_to_server(
11
11
  'evaluateExpression',
12
12
  expression: @expression,
13
- isFunction: false,
14
13
  arg: @serialized_arg,
15
14
  )
16
15
  ValueParser.new(value).parse
@@ -20,7 +19,6 @@ module Playwright
20
19
  resp = channel.send_message_to_server(
21
20
  'evaluateExpressionHandle',
22
21
  expression: @expression,
23
- isFunction: false,
24
22
  arg: @serialized_arg,
25
23
  )
26
24
  ::Playwright::ChannelOwner.from(resp)
@@ -31,7 +29,6 @@ module Playwright
31
29
  'evalOnSelector',
32
30
  selector: selector,
33
31
  expression: @expression,
34
- isFunction: false,
35
32
  arg: @serialized_arg,
36
33
  )
37
34
  ValueParser.new(value).parse
@@ -42,7 +39,6 @@ module Playwright
42
39
  'evalOnSelectorAll',
43
40
  selector: selector,
44
41
  expression: @expression,
45
- isFunction: false,
46
42
  arg: @serialized_arg,
47
43
  )
48
44
  ValueParser.new(value).parse
@@ -51,7 +47,6 @@ module Playwright
51
47
  def wait_for_function(channel, polling:, timeout:)
52
48
  params = {
53
49
  expression: @expression,
54
- isFunction: false,
55
50
  arg: @serialized_arg,
56
51
  polling: polling,
57
52
  timeout: timeout,
@@ -18,6 +18,17 @@ module Playwright
18
18
  end
19
19
  end
20
20
 
21
+ # Unwrap ChannelOwner / ApiImplementation.
22
+ # @note Intended for internal use only.
23
+ def self.unwrap(api)
24
+ case api
25
+ when PlaywrightApi
26
+ api.instance_variable_get(:@impl)
27
+ else
28
+ api
29
+ end
30
+ end
31
+
21
32
  class ChannelOwnerWrapper
22
33
  def initialize(impl)
23
34
  impl_class_name = impl.class.name
@@ -114,6 +125,8 @@ module Playwright
114
125
  private def wrap_impl(object)
115
126
  if object.is_a?(Array)
116
127
  object.map { |obj| wrap_impl(obj) }
128
+ elsif object.is_a?(Hash)
129
+ object.map { |key, obj| [key, wrap_impl(obj)] }.to_h
117
130
  else
118
131
  ::Playwright::PlaywrightApi.wrap(object)
119
132
  end
@@ -122,8 +135,10 @@ module Playwright
122
135
  private def unwrap_impl(object)
123
136
  if object.is_a?(Array)
124
137
  object.map { |obj| unwrap_impl(obj) }
138
+ elsif object.is_a?(Hash)
139
+ object.map { |key, obj| [key, unwrap_impl(obj)] }.to_h
125
140
  elsif object.is_a?(PlaywrightApi)
126
- object.instance_variable_get(:@impl)
141
+ ::Playwright::PlaywrightApi.unwrap(object)
127
142
  else
128
143
  object
129
144
  end
@@ -0,0 +1,31 @@
1
+ module Playwright
2
+ define_api_implementation :TracingImpl do
3
+ def initialize(channel, context)
4
+ @channel = channel
5
+ @context = context
6
+ end
7
+
8
+ def start(name: nil, screenshots: nil, snapshots: nil)
9
+ params = {
10
+ name: name,
11
+ screenshots: screenshots,
12
+ snapshots: snapshots,
13
+ }.compact
14
+ @channel.send_message_to_server('tracingStart', params)
15
+ end
16
+
17
+ # Stop tracing.
18
+ def stop
19
+ @channel.send_message_to_server('tracingStop')
20
+ end
21
+
22
+ def export(path)
23
+ resp = @channel.send_message_to_server('tracingExport')
24
+ artifact = ChannelOwners::Artifact.from(resp)
25
+ # if self._context._browser:
26
+ # artifact._is_remote = self._context._browser._is_remote
27
+ artifact.save_as(path)
28
+ artifact.delete
29
+ end
30
+ end
31
+ end