playwright-ruby-client 0.5.9 → 0.6.3

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 +162 -0
  40. data/{docs → documentation/docs/include}/api_coverage.md +12 -1
  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 +11 -2
  58. data/lib/playwright/channel_owners/browser_context.rb +58 -6
  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 +24 -34
  62. data/lib/playwright/channel_owners/js_handle.rb +2 -10
  63. data/lib/playwright/channel_owners/page.rb +37 -52
  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 +98 -564
  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 +223 -1224
  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
  })
@@ -83,7 +65,8 @@ module Playwright
83
65
  emit(Events::Page::WebSocket, ChannelOwners::WebSocket.from(params['webSocket']))
84
66
  })
85
67
  @channel.on('worker', ->(params) {
86
- on_worker(ChannelOwners::Worker.from(params['worker']))
68
+ worker = ChannelOwners::Worker.from(params['worker'])
69
+ # on_worker(worker)
87
70
  })
88
71
  end
89
72
 
@@ -95,17 +78,6 @@ module Playwright
95
78
  :viewport_size,
96
79
  :main_frame
97
80
 
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
81
  private def on_frame_attached(frame)
110
82
  frame.send(:update_page_from_page, self)
111
83
  @frames << frame
@@ -130,6 +102,14 @@ module Playwright
130
102
  end
131
103
  end
132
104
 
105
+ private def on_binding(binding_call)
106
+ func = @bindings[binding_call.name]
107
+ if func
108
+ binding_call.call_async(func)
109
+ end
110
+ @browser_context.send(:on_binding, binding_call)
111
+ end
112
+
133
113
  private def on_close
134
114
  @closed = true
135
115
  @browser_context.send(:remove_page, self)
@@ -145,6 +125,7 @@ module Playwright
145
125
 
146
126
  private def on_download(params)
147
127
  download = Download.new(
128
+ page: self,
148
129
  url: params['url'],
149
130
  suggested_filename: params['suggestedFilename'],
150
131
  artifact: ChannelOwners::Artifact.from(params['artifact']),
@@ -335,7 +316,7 @@ module Playwright
335
316
  timeout: timeout,
336
317
  waitUntil: waitUntil,
337
318
  }.compact
338
- resp = @channel.send_message_to_server('reoad', params)
319
+ resp = @channel.send_message_to_server('reload', params)
339
320
  ChannelOwners::Response.from_nullable(resp)
340
321
  end
341
322
 
@@ -359,10 +340,11 @@ module Playwright
359
340
  ChannelOwners::Response.from_nullable(resp)
360
341
  end
361
342
 
362
- def emulate_media(colorScheme: nil, media: nil)
343
+ def emulate_media(colorScheme: nil, media: nil, reducedMotion: nil)
363
344
  params = {
364
345
  colorScheme: colorScheme,
365
346
  media: media,
347
+ reducedMotion: reducedMotion,
366
348
  }.compact
367
349
  @channel.send_message_to_server('emulateMedia', params)
368
350
 
@@ -464,7 +446,8 @@ module Playwright
464
446
  modifiers: nil,
465
447
  noWaitAfter: nil,
466
448
  position: nil,
467
- timeout: nil)
449
+ timeout: nil,
450
+ trial: nil)
468
451
 
469
452
  @main_frame.click(
470
453
  selector,
@@ -476,6 +459,7 @@ module Playwright
476
459
  noWaitAfter: noWaitAfter,
477
460
  position: position,
478
461
  timeout: timeout,
462
+ trial: trial,
479
463
  )
480
464
  end
481
465
 
@@ -487,7 +471,8 @@ module Playwright
487
471
  modifiers: nil,
488
472
  noWaitAfter: nil,
489
473
  position: nil,
490
- timeout: nil)
474
+ timeout: nil,
475
+ trial: nil)
491
476
  @main_frame.dblclick(
492
477
  selector,
493
478
  button: button,
@@ -497,6 +482,7 @@ module Playwright
497
482
  noWaitAfter: noWaitAfter,
498
483
  position: position,
499
484
  timeout: timeout,
485
+ trial: trial,
500
486
  )
501
487
  end
502
488
 
@@ -506,7 +492,8 @@ module Playwright
506
492
  modifiers: nil,
507
493
  noWaitAfter: nil,
508
494
  position: nil,
509
- timeout: nil)
495
+ timeout: nil,
496
+ trial: nil)
510
497
  @main_frame.tap_point(
511
498
  selector,
512
499
  force: force,
@@ -514,6 +501,7 @@ module Playwright
514
501
  noWaitAfter: noWaitAfter,
515
502
  position: position,
516
503
  timeout: timeout,
504
+ trial: trial,
517
505
  )
518
506
  end
519
507
 
@@ -546,13 +534,15 @@ module Playwright
546
534
  force: nil,
547
535
  modifiers: nil,
548
536
  position: nil,
549
- timeout: nil)
537
+ timeout: nil,
538
+ trial: nil)
550
539
  @main_frame.hover(
551
540
  selector,
552
541
  force: force,
553
542
  modifiers: modifiers,
554
543
  position: position,
555
544
  timeout: timeout,
545
+ trial: trial,
556
546
  )
557
547
  end
558
548
 
@@ -604,9 +594,10 @@ module Playwright
604
594
  force: nil,
605
595
  noWaitAfter: nil,
606
596
  position: nil,
607
- timeout: nil)
597
+ timeout: nil,
598
+ trial: nil)
608
599
 
609
- @main_frame.check(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout)
600
+ @main_frame.check(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout, trial: trial)
610
601
  end
611
602
 
612
603
  def uncheck(
@@ -614,9 +605,10 @@ module Playwright
614
605
  force: nil,
615
606
  noWaitAfter: nil,
616
607
  position: nil,
617
- timeout: nil)
608
+ timeout: nil,
609
+ trial: nil)
618
610
 
619
- @main_frame.uncheck(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout)
611
+ @main_frame.uncheck(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout, trial: trial)
620
612
  end
621
613
 
622
614
  def wait_for_function(pageFunction, arg: nil, polling: nil, timeout: nil)
@@ -723,7 +715,6 @@ module Playwright
723
715
  end
724
716
 
725
717
  wait_helper.wait_for_event(self, event, predicate: predicate)
726
-
727
718
  block&.call
728
719
 
729
720
  wait_helper.promise.value!
@@ -753,7 +744,7 @@ module Playwright
753
744
  expect_event(Events::Page::Popup, predicate: predicate, timeout: timeout, &block)
754
745
  end
755
746
 
756
- def expect_request(urlOrPredicate, timeout: nil)
747
+ def expect_request(urlOrPredicate, timeout: nil, &block)
757
748
  predicate =
758
749
  case urlOrPredicate
759
750
  when String, Regexp
@@ -765,10 +756,10 @@ module Playwright
765
756
  -> (_) { true }
766
757
  end
767
758
 
768
- expect_event(Events::Page::Request, predicate: predicate, timeout: timeout)
759
+ expect_event(Events::Page::Request, predicate: predicate, timeout: timeout, &block)
769
760
  end
770
761
 
771
- def expect_response(urlOrPredicate, timeout: nil)
762
+ def expect_response(urlOrPredicate, timeout: nil, &block)
772
763
  predicate =
773
764
  case urlOrPredicate
774
765
  when String, Regexp
@@ -780,13 +771,7 @@ module Playwright
780
771
  -> (_) { true }
781
772
  end
782
773
 
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))
774
+ expect_event(Events::Page::Response, predicate: predicate, timeout: timeout, &block)
790
775
  end
791
776
 
792
777
  # 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