playwright-ruby-client 1.52.0 → 1.54.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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/browser_context.md +1 -1
  3. data/documentation/docs/api/console_message.md +0 -3
  4. data/documentation/docs/api/experimental/android.md +10 -0
  5. data/documentation/docs/api/frame.md +1 -0
  6. data/documentation/docs/api/frame_locator.md +1 -0
  7. data/documentation/docs/api/locator.md +25 -1
  8. data/documentation/docs/api/locator_assertions.md +4 -7
  9. data/documentation/docs/api/mouse.md +2 -0
  10. data/documentation/docs/api/page.md +2 -1
  11. data/documentation/docs/api/selectors.md +10 -0
  12. data/documentation/docs/api/tracing.md +8 -0
  13. data/documentation/docs/include/api_coverage.md +3 -2
  14. data/lib/playwright/channel.rb +6 -3
  15. data/lib/playwright/channel_owners/android.rb +12 -0
  16. data/lib/playwright/channel_owners/android_device.rb +6 -5
  17. data/lib/playwright/channel_owners/api_request_context.rb +6 -1
  18. data/lib/playwright/channel_owners/browser.rb +37 -6
  19. data/lib/playwright/channel_owners/browser_context.rb +44 -23
  20. data/lib/playwright/channel_owners/browser_type.rb +45 -12
  21. data/lib/playwright/channel_owners/element_handle.rb +22 -17
  22. data/lib/playwright/channel_owners/frame.rb +65 -34
  23. data/lib/playwright/channel_owners/page.rb +19 -8
  24. data/lib/playwright/channel_owners/playwright.rb +10 -4
  25. data/lib/playwright/channel_owners/web_socket.rb +1 -1
  26. data/lib/playwright/connection.rb +3 -0
  27. data/lib/playwright/file_chooser_impl.rb +3 -2
  28. data/lib/playwright/frame_locator_impl.rb +5 -8
  29. data/lib/playwright/locator_assertions_impl.rb +64 -34
  30. data/lib/playwright/locator_impl.rb +27 -38
  31. data/lib/playwright/page_assertions_impl.rb +11 -9
  32. data/lib/playwright/selectors_impl.rb +45 -0
  33. data/lib/playwright/test.rb +21 -3
  34. data/lib/playwright/timeout_settings.rb +5 -0
  35. data/lib/playwright/transport.rb +1 -1
  36. data/lib/playwright/utils.rb +0 -33
  37. data/lib/playwright/version.rb +2 -2
  38. data/lib/playwright_api/android.rb +12 -7
  39. data/lib/playwright_api/android_device.rb +8 -8
  40. data/lib/playwright_api/api_request_context.rb +6 -6
  41. data/lib/playwright_api/browser.rb +6 -6
  42. data/lib/playwright_api/browser_context.rb +11 -11
  43. data/lib/playwright_api/browser_type.rb +6 -6
  44. data/lib/playwright_api/cdp_session.rb +6 -6
  45. data/lib/playwright_api/console_message.rb +0 -4
  46. data/lib/playwright_api/dialog.rb +6 -6
  47. data/lib/playwright_api/element_handle.rb +6 -6
  48. data/lib/playwright_api/frame.rb +14 -8
  49. data/lib/playwright_api/frame_locator.rb +1 -0
  50. data/lib/playwright_api/js_handle.rb +6 -6
  51. data/lib/playwright_api/locator.rb +31 -4
  52. data/lib/playwright_api/locator_assertions.rb +3 -3
  53. data/lib/playwright_api/mouse.rb +2 -0
  54. data/lib/playwright_api/page.rb +14 -8
  55. data/lib/playwright_api/playwright.rb +8 -8
  56. data/lib/playwright_api/request.rb +8 -8
  57. data/lib/playwright_api/response.rb +8 -8
  58. data/lib/playwright_api/route.rb +6 -6
  59. data/lib/playwright_api/selectors.rb +1 -28
  60. data/lib/playwright_api/tracing.rb +14 -6
  61. data/lib/playwright_api/web_socket.rb +6 -6
  62. data/lib/playwright_api/worker.rb +8 -8
  63. data/sig/playwright.rbs +11 -2
  64. metadata +4 -4
  65. data/lib/playwright/channel_owners/selectors.rb +0 -26
@@ -4,12 +4,15 @@ module Playwright
4
4
  define_api_implementation :FrameLocatorImpl do
5
5
  include LocatorUtils
6
6
 
7
- def initialize(frame:, timeout_settings:, frame_selector:)
7
+ def initialize(frame:, frame_selector:)
8
8
  @frame = frame
9
- @timeout_settings = timeout_settings
10
9
  @frame_selector = frame_selector
11
10
  end
12
11
 
12
+ private def _timeout(timeout)
13
+ @frame.send(:_timeout, timeout)
14
+ end
15
+
13
16
  def locator(
14
17
  selector,
15
18
  has: nil,
@@ -18,7 +21,6 @@ module Playwright
18
21
  hasText: nil)
19
22
  LocatorImpl.new(
20
23
  frame: @frame,
21
- timeout_settings: @timeout_settings,
22
24
  selector: "#{@frame_selector} >> internal:control=enter-frame >> #{selector}",
23
25
  has: has,
24
26
  hasNot: hasNot,
@@ -29,7 +31,6 @@ module Playwright
29
31
  def owner
30
32
  LocatorImpl.new(
31
33
  frame: @frame,
32
- timeout_settings: @timeout_settings,
33
34
  selector: @frame_selector,
34
35
  )
35
36
  end
@@ -37,7 +38,6 @@ module Playwright
37
38
  def frame_locator(selector)
38
39
  FrameLocatorImpl.new(
39
40
  frame: @frame,
40
- timeout_settings: @timeout_settings,
41
41
  frame_selector: "#{@frame_selector} >> internal:control=enter-frame >> #{selector}",
42
42
  )
43
43
  end
@@ -45,7 +45,6 @@ module Playwright
45
45
  def first
46
46
  FrameLocatorImpl.new(
47
47
  frame: @frame,
48
- timeout_settings: @timeout_settings,
49
48
  frame_selector: "#{@frame_selector} >> nth=0",
50
49
  )
51
50
  end
@@ -53,7 +52,6 @@ module Playwright
53
52
  def last
54
53
  FrameLocatorImpl.new(
55
54
  frame: @frame,
56
- timeout_settings: @timeout_settings,
57
55
  frame_selector: "#{@frame_selector} >> nth=-1",
58
56
  )
59
57
  end
@@ -61,7 +59,6 @@ module Playwright
61
59
  def nth(index)
62
60
  FrameLocatorImpl.new(
63
61
  frame: @frame,
64
- timeout_settings: @timeout_settings,
65
62
  frame_selector: "#{@frame_selector} >> nth=#{index}",
66
63
  )
67
64
  end
@@ -11,20 +11,20 @@ module Playwright
11
11
  end
12
12
  end
13
13
 
14
- def initialize(locator, timeout, is_not, message)
14
+ def initialize(locator, default_expect_timeout, is_not, message)
15
15
  @locator = locator
16
- @timeout = timeout
16
+ @default_expect_timeout = default_expect_timeout
17
17
  @is_not = is_not
18
18
  @custom_message = message
19
19
  end
20
20
 
21
- private def expect_impl(expression, expect_options, expected, message)
22
- expect_options[:timeout] ||= 5000
21
+ private def expect_impl(expression, expect_options, expected, message, title)
22
+ expect_options[:timeout] ||= @default_expect_timeout
23
23
  expect_options[:isNot] = @is_not
24
24
  message.gsub!("expected to", "not expected to") if @is_not
25
25
  expect_options.delete(:useInnerText) if expect_options.key?(:useInnerText) && expect_options[:useInnerText].nil?
26
26
 
27
- result = @locator.expect(expression, expect_options)
27
+ result = @locator.expect(expression, expect_options, title)
28
28
 
29
29
  if result["matches"] == @is_not
30
30
  actual = result["received"]
@@ -59,7 +59,7 @@ module Playwright
59
59
  private def _not # "not" is reserved in Ruby
60
60
  LocatorAssertionsImpl.new(
61
61
  @locator,
62
- @timeout,
62
+ @default_expect_timeout,
63
63
  !@is_not,
64
64
  @message
65
65
  )
@@ -124,7 +124,8 @@ module Playwright
124
124
  timeout: timeout,
125
125
  },
126
126
  expected,
127
- "Locator expected to contain text"
127
+ "Locator expected to contain text",
128
+ 'Expect "to_contain_text"',
128
129
  )
129
130
  else
130
131
  expected_text = to_expected_text_values(
@@ -142,7 +143,8 @@ module Playwright
142
143
  timeout: timeout,
143
144
  },
144
145
  expected,
145
- "Locator expected to contain text"
146
+ "Locator expected to contain text",
147
+ 'Expect "to_contain_text"',
146
148
  )
147
149
  end
148
150
  end
@@ -157,7 +159,8 @@ module Playwright
157
159
  timeout: timeout,
158
160
  },
159
161
  name,
160
- "Locator expected to have accessible name"
162
+ "Locator expected to have accessible name",
163
+ 'Expect "to_have_accessible_name"',
161
164
  )
162
165
  end
163
166
  _define_negation :to_have_accessible_name
@@ -171,7 +174,8 @@ module Playwright
171
174
  timeout: timeout,
172
175
  },
173
176
  name,
174
- "Locator expected to have accessible description"
177
+ "Locator expected to have accessible description",
178
+ 'Expect "to_have_accessible_description"',
175
179
  )
176
180
  end
177
181
  _define_negation :to_have_accessible_description
@@ -185,7 +189,8 @@ module Playwright
185
189
  timeout: timeout,
186
190
  },
187
191
  errorMessage,
188
- "Locator expected to have accessible error message"
192
+ "Locator expected to have accessible error message",
193
+ 'Expect "to_have_accessible_error_message"',
189
194
  )
190
195
  end
191
196
  _define_negation :to_have_accessible_error_message
@@ -200,7 +205,8 @@ module Playwright
200
205
  timeout: timeout,
201
206
  },
202
207
  value,
203
- "Locator expected to have attribute"
208
+ "Locator expected to have attribute",
209
+ 'Expect "to_have_attribute"',
204
210
  )
205
211
  end
206
212
  _define_negation :to_have_attribute
@@ -215,7 +221,8 @@ module Playwright
215
221
  timeout: timeout,
216
222
  },
217
223
  expected,
218
- "Locator expected to have class"
224
+ "Locator expected to have class",
225
+ 'Expect "to_have_class"',
219
226
  )
220
227
  else
221
228
  expected_text = to_expected_text_values([expected])
@@ -226,7 +233,8 @@ module Playwright
226
233
  timeout: timeout,
227
234
  },
228
235
  expected,
229
- "Locator expected to have class"
236
+ "Locator expected to have class",
237
+ 'Expect "to_have_class"',
230
238
  )
231
239
  end
232
240
  end
@@ -245,7 +253,8 @@ module Playwright
245
253
  timeout: timeout,
246
254
  },
247
255
  expected,
248
- "Locator expected to contain class names"
256
+ "Locator expected to contain class names",
257
+ 'Expect "to_contain_class"',
249
258
  )
250
259
  else # Single string
251
260
  if expected.is_a?(Regexp)
@@ -259,7 +268,8 @@ module Playwright
259
268
  timeout: timeout,
260
269
  },
261
270
  expected,
262
- "Locator expected to contain class"
271
+ "Locator expected to contain class",
272
+ 'Expect "to_contain_class"',
263
273
  )
264
274
  end
265
275
  end
@@ -273,7 +283,8 @@ module Playwright
273
283
  timeout: timeout,
274
284
  },
275
285
  count,
276
- "Locator expected to have count"
286
+ "Locator expected to have count",
287
+ 'Expect "to_have_count"',
277
288
  )
278
289
  end
279
290
  _define_negation :to_have_count
@@ -288,7 +299,8 @@ module Playwright
288
299
  timeout: timeout,
289
300
  },
290
301
  value,
291
- "Locator expected to have CSS"
302
+ "Locator expected to have CSS",
303
+ 'Expect "to_have_css"',
292
304
  )
293
305
  end
294
306
  _define_negation :to_have_css
@@ -302,7 +314,8 @@ module Playwright
302
314
  timeout: timeout,
303
315
  },
304
316
  id,
305
- "Locator expected to have ID"
317
+ "Locator expected to have ID",
318
+ 'Expect "to_have_id"',
306
319
  )
307
320
  end
308
321
  _define_negation :to_have_id
@@ -316,7 +329,8 @@ module Playwright
316
329
  timeout: timeout,
317
330
  },
318
331
  value,
319
- "Locator expected to have JS Property"
332
+ "Locator expected to have JS Property",
333
+ 'Expect "to_have_js_property"',
320
334
  )
321
335
  end
322
336
  _define_negation :to_have_js_property
@@ -335,6 +349,7 @@ module Playwright
335
349
  },
336
350
  role,
337
351
  "Locator expected to have accessible role",
352
+ 'Expect "to_have_role"',
338
353
  )
339
354
  end
340
355
  _define_negation :to_have_role
@@ -349,7 +364,8 @@ module Playwright
349
364
  timeout: timeout,
350
365
  },
351
366
  value,
352
- "Locator expected to have Value"
367
+ "Locator expected to have Value",
368
+ 'Expect "to_have_value"',
353
369
  )
354
370
  end
355
371
  _define_negation :to_have_value
@@ -364,7 +380,8 @@ module Playwright
364
380
  timeout: timeout,
365
381
  },
366
382
  values,
367
- "Locator expected to have Values"
383
+ "Locator expected to have Values",
384
+ 'Expect "to_have_values"',
368
385
  )
369
386
  end
370
387
  _define_negation :to_have_values
@@ -385,7 +402,8 @@ module Playwright
385
402
  timeout: timeout,
386
403
  },
387
404
  expected,
388
- "Locator expected to have text"
405
+ "Locator expected to have text",
406
+ 'Expect "to_have_text"',
389
407
  )
390
408
  else
391
409
  expected_text = to_expected_text_values(
@@ -402,7 +420,8 @@ module Playwright
402
420
  timeout: timeout,
403
421
  },
404
422
  expected,
405
- "Locator expected to have text"
423
+ "Locator expected to have text",
424
+ 'Expect "to_have_text"',
406
425
  )
407
426
  end
408
427
  end
@@ -417,6 +436,7 @@ module Playwright
417
436
  },
418
437
  expected,
419
438
  'Locator expected to match Aria snapshot',
439
+ 'Expect "to_match_aria_snapshot"',
420
440
  )
421
441
  end
422
442
  _define_negation :to_match_aria_snapshot
@@ -426,7 +446,8 @@ module Playwright
426
446
  (attached || attached.nil?) ? "to.be.attached" : "to.be.detached",
427
447
  { timeout: timeout },
428
448
  nil,
429
- "Locator expected to be attached"
449
+ "Locator expected to be attached",
450
+ 'Expect "to_be_attached"',
430
451
  )
431
452
  end
432
453
  _define_negation :to_be_attached
@@ -449,7 +470,8 @@ module Playwright
449
470
  "to.be.checked",
450
471
  { timeout: timeout, expectedValue: expected_value },
451
472
  nil,
452
- "Locator expected to be checked"
473
+ "Locator expected to be checked",
474
+ 'Expect "to_be_checked"',
453
475
  )
454
476
  end
455
477
  _define_negation :to_be_checked
@@ -459,7 +481,8 @@ module Playwright
459
481
  "to.be.disabled",
460
482
  { timeout: timeout },
461
483
  nil,
462
- "Locator expected to be disabled"
484
+ "Locator expected to be disabled",
485
+ 'Expect "to_be_disabled"',
463
486
  )
464
487
  end
465
488
  _define_negation :to_be_disabled
@@ -469,7 +492,8 @@ module Playwright
469
492
  (editable || editable.nil?) ? "to.be.editable" : "to.be.readonly",
470
493
  { timeout: timeout },
471
494
  nil,
472
- "Locator expected to be editable"
495
+ "Locator expected to be editable",
496
+ 'Expect "to_be_editable"',
473
497
  )
474
498
  end
475
499
  _define_negation :to_be_editable
@@ -479,7 +503,8 @@ module Playwright
479
503
  "to.be.empty",
480
504
  { timeout: timeout },
481
505
  nil,
482
- "Locator expected to be empty"
506
+ "Locator expected to be empty",
507
+ 'Expect "to_be_empty"',
483
508
  )
484
509
  end
485
510
  _define_negation :to_be_empty
@@ -489,7 +514,8 @@ module Playwright
489
514
  (enabled || enabled.nil?) ? "to.be.enabled" : "to.be.disabled",
490
515
  { timeout: timeout },
491
516
  nil,
492
- "Locator expected to be enabled"
517
+ "Locator expected to be enabled",
518
+ 'Expect "to_be_enabled"',
493
519
  )
494
520
  end
495
521
  _define_negation :to_be_enabled
@@ -499,7 +525,8 @@ module Playwright
499
525
  "to.be.hidden",
500
526
  { timeout: timeout },
501
527
  nil,
502
- "Locator expected to be hidden"
528
+ "Locator expected to be hidden",
529
+ 'Expect "to_be_hidden"',
503
530
  )
504
531
  end
505
532
  _define_negation :to_be_hidden
@@ -509,7 +536,8 @@ module Playwright
509
536
  (visible || visible.nil?) ? "to.be.visible" : "to.be.hidden",
510
537
  { timeout: timeout },
511
538
  nil,
512
- "Locator expected to be visible"
539
+ "Locator expected to be visible",
540
+ 'Expect "to_be_visible"',
513
541
  )
514
542
  end
515
543
  _define_negation :to_be_visible
@@ -519,7 +547,8 @@ module Playwright
519
547
  "to.be.focused",
520
548
  { timeout: timeout },
521
549
  nil,
522
- "Locator expected to be focused"
550
+ "Locator expected to be focused",
551
+ 'Expect "to_be_focused"',
523
552
  )
524
553
  end
525
554
  _define_negation :to_be_focused
@@ -529,7 +558,8 @@ module Playwright
529
558
  "to.be.in.viewport",
530
559
  { timeout: timeout, expectedNumber: ratio }.compact,
531
560
  nil,
532
- "Locator expected to be in viewport"
561
+ "Locator expected to be in viewport",
562
+ 'Expect "to_be_in_viewport"',
533
563
  )
534
564
  end
535
565
  _define_negation :to_be_in_viewport
@@ -5,9 +5,8 @@ module Playwright
5
5
  define_api_implementation :LocatorImpl do
6
6
  include LocatorUtils
7
7
 
8
- def initialize(frame:, timeout_settings:, selector:, has: nil, hasNot: nil, hasNotText: nil, hasText: nil, visible: nil)
8
+ def initialize(frame:, selector:, has: nil, hasNot: nil, hasNotText: nil, hasText: nil, visible: nil)
9
9
  @frame = frame
10
- @timeout_settings = timeout_settings
11
10
  selector_scopes = [selector]
12
11
 
13
12
  if hasText
@@ -40,7 +39,11 @@ module Playwright
40
39
  end
41
40
 
42
41
  def to_s
43
- "Locator@#{@selector}"
42
+ if @description
43
+ "Locator@#{@selector} (#{@description})"
44
+ else
45
+ "Locator@#{@selector}"
46
+ end
44
47
  end
45
48
 
46
49
  private def to_protocol
@@ -64,8 +67,12 @@ module Playwright
64
67
  @selector.to_json
65
68
  end
66
69
 
70
+ private def _timeout(timeout)
71
+ @frame.send(:_timeout, timeout)
72
+ end
73
+
67
74
  private def with_element(timeout: nil, &block)
68
- timeout_or_default = @timeout_settings.timeout(timeout)
75
+ timeout_or_default = _timeout(timeout)
69
76
  start_time = Time.now
70
77
 
71
78
  handle = @frame.wait_for_selector(@selector, strict: true, state: 'attached', timeout: timeout_or_default)
@@ -213,7 +220,6 @@ module Playwright
213
220
  hasText: nil)
214
221
  LocatorImpl.new(
215
222
  frame: @frame,
216
- timeout_settings: @timeout_settings,
217
223
  selector: "#{@selector} >> #{selector}",
218
224
  has: has,
219
225
  hasNot: hasNot,
@@ -224,7 +230,6 @@ module Playwright
224
230
  def frame_locator(selector)
225
231
  FrameLocatorImpl.new(
226
232
  frame: @frame,
227
- timeout_settings: @timeout_settings,
228
233
  frame_selector: "#{@selector} >> #{selector}",
229
234
  )
230
235
  end
@@ -240,15 +245,20 @@ module Playwright
240
245
  def content_frame
241
246
  FrameLocatorImpl.new(
242
247
  frame: @frame,
243
- timeout_settings: @timeout_settings,
244
248
  frame_selector: @selector,
245
249
  )
246
250
  end
247
251
 
252
+ def describe(description)
253
+ LocatorImpl.new(
254
+ frame: @frame,
255
+ selector: "#{@selector} >> internal:describe=#{description.to_json}",
256
+ )
257
+ end
258
+
248
259
  def filter(has: nil, hasNot: nil, hasNotText: nil, hasText: nil, visible: nil)
249
260
  LocatorImpl.new(
250
261
  frame: @frame,
251
- timeout_settings: @timeout_settings,
252
262
  selector: @selector,
253
263
  has: has,
254
264
  hasNot: hasNot,
@@ -261,7 +271,6 @@ module Playwright
261
271
  def first
262
272
  LocatorImpl.new(
263
273
  frame: @frame,
264
- timeout_settings: @timeout_settings,
265
274
  selector: "#{@selector} >> nth=0",
266
275
  )
267
276
  end
@@ -269,7 +278,6 @@ module Playwright
269
278
  def last
270
279
  LocatorImpl.new(
271
280
  frame: @frame,
272
- timeout_settings: @timeout_settings,
273
281
  selector: "#{@selector} >> nth=-1",
274
282
  )
275
283
  end
@@ -277,7 +285,6 @@ module Playwright
277
285
  def nth(index)
278
286
  LocatorImpl.new(
279
287
  frame: @frame,
280
- timeout_settings: @timeout_settings,
281
288
  selector: "#{@selector} >> nth=#{index}",
282
289
  )
283
290
  end
@@ -288,7 +295,6 @@ module Playwright
288
295
  end
289
296
  LocatorImpl.new(
290
297
  frame: @frame,
291
- timeout_settings: @timeout_settings,
292
298
  selector: "#{@selector} >> internal:and=#{locator.send(:selector_json)}",
293
299
  )
294
300
  end
@@ -299,7 +305,6 @@ module Playwright
299
305
  end
300
306
  LocatorImpl.new(
301
307
  frame: @frame,
302
- timeout_settings: @timeout_settings,
303
308
  selector: "#{@selector} >> internal:or=#{locator.send(:selector_json)}",
304
309
  )
305
310
  end
@@ -312,7 +317,7 @@ module Playwright
312
317
  params = {
313
318
  selector: @selector,
314
319
  strict: true,
315
- timeout: timeout,
320
+ timeout: _timeout(timeout),
316
321
  }.compact
317
322
  @frame.channel.send_message_to_server('blur', params)
318
323
  end
@@ -329,6 +334,10 @@ module Playwright
329
334
  @frame.get_attribute(@selector, name, strict: true, timeout: timeout)
330
335
  end
331
336
 
337
+ def generate_locator_string
338
+ @frame.channel.send_message_to_server('generateLocatorString', { selector: @selector })
339
+ end
340
+
332
341
  def hover(
333
342
  force: nil,
334
343
  modifiers: nil,
@@ -397,11 +406,10 @@ module Playwright
397
406
  end
398
407
  end
399
408
 
400
- def aria_snapshot(timeout: nil, ref: nil)
409
+ def aria_snapshot(timeout: nil)
401
410
  @frame.channel.send_message_to_server('ariaSnapshot', {
402
411
  selector: @selector,
403
- timeout: timeout,
404
- ref: ref,
412
+ timeout: _timeout(timeout),
405
413
  }.compact)
406
414
  end
407
415
 
@@ -509,27 +517,8 @@ module Playwright
509
517
  @frame.highlight(@selector)
510
518
  end
511
519
 
512
- def expect(expression, options)
513
- if options.key?(:expectedValue)
514
- options[:expectedValue] = JavaScript::ValueSerializer
515
- .new(options[:expectedValue])
516
- .serialize
517
- end
518
-
519
- result = @frame.channel.send_message_to_server_result(
520
- "expect",
521
- {
522
- selector: @selector,
523
- expression: expression,
524
- **options,
525
- }
526
- )
527
-
528
- if result.key?('received')
529
- result['received'] = JavaScript::ValueParser.new(result['received']).parse
530
- end
531
-
532
- result
520
+ def expect(expression, options, title)
521
+ @frame.expect(@selector, expression, options, title)
533
522
  end
534
523
  end
535
524
  end
@@ -11,21 +11,21 @@ module Playwright
11
11
  end
12
12
  end
13
13
 
14
- def initialize(page, timeout, is_not, message)
14
+ def initialize(page, default_expect_timeout, is_not, message)
15
15
  @page = PlaywrightApi.unwrap(page)
16
- @locator = @page.locator(":root")
17
- @timeout = timeout
16
+ @frame = @page.main_frame
17
+ @default_expect_timeout = default_expect_timeout
18
18
  @is_not = is_not
19
19
  @custom_message = message
20
20
  end
21
21
 
22
- private def expect_impl(expression, expect_options, expected, message)
23
- expect_options[:timeout] ||= 5000
22
+ private def expect_impl(expression, expect_options, expected, message, title)
23
+ expect_options[:timeout] ||= @default_expect_timeout
24
24
  expect_options[:isNot] = @is_not
25
25
  message.gsub!("expected to", "not expected to") if @is_not
26
26
  expect_options.delete(:useInnerText) if expect_options.key?(:useInnerText) && expect_options[:useInnerText].nil?
27
27
 
28
- result = @locator.expect(expression, expect_options)
28
+ result = @frame.expect(nil, expression, expect_options, title)
29
29
 
30
30
  if result["matches"] == @is_not
31
31
  actual = result["received"]
@@ -60,7 +60,7 @@ module Playwright
60
60
  private def _not # "not" is reserved in Ruby
61
61
  PageAssertionsImpl.new(
62
62
  @page,
63
- @timeout,
63
+ @default_expect_timeout,
64
64
  !@is_not,
65
65
  @message
66
66
  )
@@ -117,7 +117,8 @@ module Playwright
117
117
  timeout: timeout,
118
118
  },
119
119
  title_or_regex,
120
- "Page title expected to be"
120
+ "Page title expected to be",
121
+ 'Expect "to_have_title"',
121
122
  )
122
123
  end
123
124
  _define_negation :to_have_title
@@ -141,7 +142,8 @@ module Playwright
141
142
  timeout: timeout,
142
143
  },
143
144
  expected,
144
- "Page URL expected to be"
145
+ "Page URL expected to be",
146
+ 'Expect "to_have_url"',
145
147
  )
146
148
  end
147
149
  _define_negation :to_have_url
@@ -0,0 +1,45 @@
1
+ module Playwright
2
+ # https://github.com/microsoft/playwright-python/blob/master/playwright/_impl/_selectors.py
3
+ define_api_implementation :SelectorsImpl do
4
+ def initialize
5
+ @selector_engines = []
6
+ @contexts_for_selectors = Set.new
7
+ end
8
+
9
+ def register(name, contentScript: nil, path: nil, script: nil)
10
+ source =
11
+ if path
12
+ File.read(path)
13
+ elsif script
14
+ script
15
+ else
16
+ raise ArgumentError.new('Either path or script parameter must be specified')
17
+ end
18
+ selector_engine = { name: name, source: source }
19
+ if contentScript
20
+ selector_engine[:contentScript] = true
21
+ end
22
+ @contexts_for_selectors.each do |context|
23
+ context.send(:register_selector_engine, selector_engine)
24
+ end
25
+ @selector_engines << selector_engine
26
+
27
+ nil
28
+ end
29
+
30
+ def set_test_id_attribute(attribute_name)
31
+ @test_id_attribute_name = attribute_name
32
+ ::Playwright::LocatorUtils.instance_variable_set(:@test_id_attribute_name, attribute_name)
33
+ end
34
+
35
+ private def update_with_selector_options(options)
36
+ options[:selectorEngines] = @selector_engines unless @selector_engines.empty?
37
+ options[:testIdAttributeName] = @test_id_attribute_name if @test_id_attribute_name
38
+ options
39
+ end
40
+
41
+ private def contexts_for_selectors
42
+ @contexts_for_selectors
43
+ end
44
+ end
45
+ end