playwright-ruby-client 1.52.0 → 1.53.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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/experimental/android.md +10 -0
  3. data/documentation/docs/api/locator.md +24 -1
  4. data/documentation/docs/api/locator_assertions.md +4 -7
  5. data/documentation/docs/api/page.md +1 -1
  6. data/documentation/docs/api/selectors.md +10 -0
  7. data/documentation/docs/api/tracing.md +8 -0
  8. data/documentation/docs/include/api_coverage.md +3 -2
  9. data/lib/playwright/channel.rb +6 -3
  10. data/lib/playwright/channel_owners/android.rb +12 -0
  11. data/lib/playwright/channel_owners/android_device.rb +6 -5
  12. data/lib/playwright/channel_owners/api_request_context.rb +6 -1
  13. data/lib/playwright/channel_owners/browser.rb +37 -6
  14. data/lib/playwright/channel_owners/browser_context.rb +44 -23
  15. data/lib/playwright/channel_owners/browser_type.rb +45 -12
  16. data/lib/playwright/channel_owners/element_handle.rb +22 -17
  17. data/lib/playwright/channel_owners/frame.rb +40 -33
  18. data/lib/playwright/channel_owners/page.rb +19 -8
  19. data/lib/playwright/channel_owners/playwright.rb +10 -4
  20. data/lib/playwright/channel_owners/web_socket.rb +1 -1
  21. data/lib/playwright/connection.rb +3 -0
  22. data/lib/playwright/file_chooser_impl.rb +3 -2
  23. data/lib/playwright/frame_locator_impl.rb +5 -8
  24. data/lib/playwright/locator_assertions_impl.rb +64 -34
  25. data/lib/playwright/locator_impl.rb +31 -20
  26. data/lib/playwright/page_assertions_impl.rb +10 -8
  27. data/lib/playwright/selectors_impl.rb +45 -0
  28. data/lib/playwright/test.rb +21 -3
  29. data/lib/playwright/timeout_settings.rb +5 -0
  30. data/lib/playwright/utils.rb +0 -33
  31. data/lib/playwright/version.rb +2 -2
  32. data/lib/playwright_api/android.rb +12 -7
  33. data/lib/playwright_api/android_device.rb +8 -8
  34. data/lib/playwright_api/api_request_context.rb +6 -6
  35. data/lib/playwright_api/browser.rb +6 -6
  36. data/lib/playwright_api/browser_context.rb +10 -10
  37. data/lib/playwright_api/browser_type.rb +6 -6
  38. data/lib/playwright_api/cdp_session.rb +6 -6
  39. data/lib/playwright_api/dialog.rb +6 -6
  40. data/lib/playwright_api/element_handle.rb +6 -6
  41. data/lib/playwright_api/frame.rb +6 -6
  42. data/lib/playwright_api/js_handle.rb +6 -6
  43. data/lib/playwright_api/locator.rb +30 -4
  44. data/lib/playwright_api/locator_assertions.rb +3 -3
  45. data/lib/playwright_api/page.rb +13 -8
  46. data/lib/playwright_api/playwright.rb +6 -6
  47. data/lib/playwright_api/request.rb +8 -8
  48. data/lib/playwright_api/response.rb +6 -6
  49. data/lib/playwright_api/route.rb +6 -6
  50. data/lib/playwright_api/selectors.rb +1 -28
  51. data/lib/playwright_api/tracing.rb +14 -6
  52. data/lib/playwright_api/web_socket.rb +6 -6
  53. data/lib/playwright_api/worker.rb +8 -8
  54. data/sig/playwright.rbs +6 -1
  55. metadata +4 -4
  56. data/lib/playwright/channel_owners/selectors.rb +0 -26
@@ -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,12 @@ module Playwright
329
334
  @frame.get_attribute(@selector, name, strict: true, timeout: timeout)
330
335
  end
331
336
 
337
+ def generate_locator_string
338
+ with_element(timeout: nil) do |handle, _|
339
+ handle.channel.send_message_to_server('generateLocatorString')
340
+ end
341
+ end
342
+
332
343
  def hover(
333
344
  force: nil,
334
345
  modifiers: nil,
@@ -397,11 +408,10 @@ module Playwright
397
408
  end
398
409
  end
399
410
 
400
- def aria_snapshot(timeout: nil, ref: nil)
411
+ def aria_snapshot(timeout: nil)
401
412
  @frame.channel.send_message_to_server('ariaSnapshot', {
402
413
  selector: @selector,
403
- timeout: timeout,
404
- ref: ref,
414
+ timeout: _timeout(timeout),
405
415
  }.compact)
406
416
  end
407
417
 
@@ -509,7 +519,7 @@ module Playwright
509
519
  @frame.highlight(@selector)
510
520
  end
511
521
 
512
- def expect(expression, options)
522
+ def expect(expression, options, title)
513
523
  if options.key?(:expectedValue)
514
524
  options[:expectedValue] = JavaScript::ValueSerializer
515
525
  .new(options[:expectedValue])
@@ -517,8 +527,9 @@ module Playwright
517
527
  end
518
528
 
519
529
  result = @frame.channel.send_message_to_server_result(
520
- "expect",
521
- {
530
+ title, # title
531
+ "expect", # method
532
+ { # params
522
533
  selector: @selector,
523
534
  expression: expression,
524
535
  **options,
@@ -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
16
  @locator = @page.locator(":root")
17
- @timeout = timeout
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 = @locator.expect(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
@@ -2,10 +2,28 @@ module Playwright
2
2
  # this module is responsible for running playwright assertions and integrating
3
3
  # with test frameworks.
4
4
  module Test
5
+ @@expect_timeout = nil
6
+
7
+ def self.expect_timeout
8
+ @@expect_timeout || 5000 # default timeout is 5000ms
9
+ end
10
+
11
+ def self.expect_timeout=(timeout)
12
+ @@expect_timeout = timeout
13
+ end
14
+
15
+ def self.with_timeout(expect_timeout, &block)
16
+ old_timeout = @@expect_timeout
17
+ @@expect_timeout = expect_timeout
18
+ block.call
19
+ ensure
20
+ @@expect_timeout = old_timeout
21
+ end
22
+
5
23
  # ref: https://github.com/microsoft/playwright-python/blob/main/playwright/sync_api/__init__.py#L90
6
24
  class Expect
7
25
  def initialize
8
- @timeout_settings = TimeoutSettings.new
26
+ @default_expect_timeout = ::Playwright::Test.expect_timeout
9
27
  end
10
28
 
11
29
  def call(actual, is_not)
@@ -14,7 +32,7 @@ module Playwright
14
32
  PageAssertions.new(
15
33
  PageAssertionsImpl.new(
16
34
  actual,
17
- @timeout_settings.timeout,
35
+ @default_expect_timeout,
18
36
  is_not,
19
37
  nil,
20
38
  )
@@ -23,7 +41,7 @@ module Playwright
23
41
  LocatorAssertions.new(
24
42
  LocatorAssertionsImpl.new(
25
43
  actual,
26
- @timeout_settings.timeout,
44
+ @default_expect_timeout,
27
45
  is_not,
28
46
  nil,
29
47
  )
@@ -1,6 +1,7 @@
1
1
  module Playwright
2
2
  class TimeoutSettings
3
3
  DEFAULT_TIMEOUT = 30000
4
+ DEFAULT_LAUNCH_TIMEOUT = 180000 # 3 minutes
4
5
 
5
6
  def initialize(parent = nil)
6
7
  @parent = parent
@@ -15,5 +16,9 @@ module Playwright
15
16
  def timeout(timeout_override = nil)
16
17
  timeout_override || @default_timeout || @parent&.timeout || DEFAULT_TIMEOUT
17
18
  end
19
+
20
+ def launch_timeout(timeout_override = nil)
21
+ timeout_override || @default_timeout || @parent&.launch_timeout || DEFAULT_LAUNCH_TIMEOUT
22
+ end
18
23
  end
19
24
  end
@@ -3,36 +3,6 @@ require 'base64'
3
3
  module Playwright
4
4
  module Utils
5
5
  module PrepareBrowserContextOptions
6
- private def prepare_record_har_options(params)
7
- out_params = {
8
- path: params.delete(:record_har_path)
9
- }
10
- if params[:record_har_url_filter]
11
- opt = params.delete(:record_har_url_filter)
12
- if opt.is_a?(Regexp)
13
- regex = ::Playwright::JavaScript::Regex.new(opt)
14
- out_params[:urlRegexSource] = regex.source
15
- out_params[:urlRegexFlags] = regex.flag
16
- elsif opt.is_a?(String)
17
- out_params[:urlGlob] = opt
18
- end
19
- end
20
- if params[:record_har_mode]
21
- out_params[:mode] = params.delete(:record_har_mode)
22
- end
23
- if params[:record_har_content]
24
- out_params[:content] = params.delete(:record_har_content)
25
- end
26
- if params[:record_har_omit_content]
27
- old_api_omit_content = params.delete(:record_har_omit_content)
28
- if old_api_omit_content
29
- out_params[:content] ||= 'omit'
30
- end
31
- end
32
-
33
- out_params
34
- end
35
-
36
6
  # @see https://github.com/microsoft/playwright/blob/5a2cfdbd47ed3c3deff77bb73e5fac34241f649d/src/client/browserContext.ts#L265
37
7
  private def prepare_browser_context_options(params)
38
8
  if params[:noViewport] == 0
@@ -42,9 +12,6 @@ module Playwright
42
12
  if params[:extraHTTPHeaders]
43
13
  params[:extraHTTPHeaders] = ::Playwright::HttpHeaders.new(params[:extraHTTPHeaders]).as_serialized
44
14
  end
45
- if params[:record_har_path]
46
- params[:recordHar] = prepare_record_har_options(params)
47
- end
48
15
  if params[:record_video_dir]
49
16
  params[:recordVideo] = {
50
17
  dir: params.delete(:record_video_dir)