playwright-ruby-client 1.51.0 → 1.56.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 +4 -4
- data/CONTRIBUTING.md +5 -0
- data/README.md +4 -0
- data/documentation/docs/api/browser_context.md +7 -3
- data/documentation/docs/api/console_message.md +0 -3
- data/documentation/docs/api/experimental/android.md +10 -0
- data/documentation/docs/api/frame.md +1 -0
- data/documentation/docs/api/frame_locator.md +1 -0
- data/documentation/docs/api/locator.md +24 -0
- data/documentation/docs/api/locator_assertions.md +47 -1
- data/documentation/docs/api/mouse.md +2 -0
- data/documentation/docs/api/page.md +34 -2
- data/documentation/docs/api/route.md +2 -0
- data/documentation/docs/api/selectors.md +10 -0
- data/documentation/docs/api/tracing.md +8 -0
- data/documentation/docs/article/guides/inspector.md +1 -1
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +9 -69
- data/documentation/docs/include/api_coverage.md +8 -2
- data/documentation/package.json +3 -3
- data/documentation/yarn.lock +12372 -8623
- data/lib/playwright/channel.rb +6 -3
- data/lib/playwright/channel_owners/android.rb +12 -0
- data/lib/playwright/channel_owners/android_device.rb +6 -5
- data/lib/playwright/channel_owners/api_request_context.rb +6 -1
- data/lib/playwright/channel_owners/browser.rb +37 -6
- data/lib/playwright/channel_owners/browser_context.rb +47 -38
- data/lib/playwright/channel_owners/browser_type.rb +43 -14
- data/lib/playwright/channel_owners/element_handle.rb +22 -17
- data/lib/playwright/channel_owners/frame.rb +65 -34
- data/lib/playwright/channel_owners/page.rb +39 -9
- data/lib/playwright/channel_owners/playwright.rb +10 -4
- data/lib/playwright/channel_owners/web_socket.rb +1 -1
- data/lib/playwright/connection.rb +3 -0
- data/lib/playwright/console_message_impl.rb +3 -2
- data/lib/playwright/file_chooser_impl.rb +3 -2
- data/lib/playwright/frame_locator_impl.rb +5 -8
- data/lib/playwright/javascript/value_parser.rb +54 -2
- data/lib/playwright/locator_assertions_impl.rb +100 -34
- data/lib/playwright/locator_impl.rb +26 -36
- data/lib/playwright/page_assertions_impl.rb +16 -11
- data/lib/playwright/selectors_impl.rb +45 -0
- data/lib/playwright/test.rb +21 -3
- data/lib/playwright/timeout_settings.rb +5 -0
- data/lib/playwright/transport.rb +1 -1
- data/lib/playwright/utils.rb +0 -33
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright/web_socket_client.rb +4 -1
- data/lib/playwright/web_socket_transport.rb +3 -1
- data/lib/playwright.rb +14 -14
- data/lib/playwright_api/android.rb +12 -7
- data/lib/playwright_api/android_device.rb +8 -8
- data/lib/playwright_api/api_request.rb +1 -0
- data/lib/playwright_api/api_request_context.rb +6 -6
- data/lib/playwright_api/browser.rb +6 -6
- data/lib/playwright_api/browser_context.rb +17 -17
- data/lib/playwright_api/browser_type.rb +6 -6
- data/lib/playwright_api/cdp_session.rb +6 -6
- data/lib/playwright_api/console_message.rb +0 -4
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/element_handle.rb +6 -6
- data/lib/playwright_api/frame.rb +12 -6
- data/lib/playwright_api/frame_locator.rb +1 -0
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/locator.rb +30 -3
- data/lib/playwright_api/locator_assertions.rb +47 -3
- data/lib/playwright_api/mouse.rb +2 -0
- data/lib/playwright_api/page.rb +41 -13
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +6 -6
- data/lib/playwright_api/response.rb +6 -6
- data/lib/playwright_api/route.rb +8 -6
- data/lib/playwright_api/selectors.rb +1 -28
- data/lib/playwright_api/tracing.rb +14 -6
- data/lib/playwright_api/web_socket.rb +6 -6
- data/lib/playwright_api/worker.rb +8 -8
- data/sig/playwright.rbs +15 -1
- metadata +6 -5
- 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,
|
|
14
|
+
def initialize(locator, default_expect_timeout, is_not, message)
|
|
15
15
|
@locator = locator
|
|
16
|
-
@
|
|
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] ||=
|
|
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"]
|
|
@@ -49,8 +49,11 @@ module Playwright
|
|
|
49
49
|
"\n#{message}"
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
if result['errorMessage']
|
|
53
|
+
error_message = "\n#{result['errorMessage']}"
|
|
54
|
+
end
|
|
55
|
+
out = "#{out_message}\nActual value #{actual}#{error_message} #{log}"
|
|
56
|
+
raise AssertionError.new(out)
|
|
54
57
|
else
|
|
55
58
|
true
|
|
56
59
|
end
|
|
@@ -59,7 +62,7 @@ module Playwright
|
|
|
59
62
|
private def _not # "not" is reserved in Ruby
|
|
60
63
|
LocatorAssertionsImpl.new(
|
|
61
64
|
@locator,
|
|
62
|
-
@
|
|
65
|
+
@default_expect_timeout,
|
|
63
66
|
!@is_not,
|
|
64
67
|
@message
|
|
65
68
|
)
|
|
@@ -124,7 +127,8 @@ module Playwright
|
|
|
124
127
|
timeout: timeout,
|
|
125
128
|
},
|
|
126
129
|
expected,
|
|
127
|
-
"Locator expected to contain text"
|
|
130
|
+
"Locator expected to contain text",
|
|
131
|
+
'Expect "to_contain_text"',
|
|
128
132
|
)
|
|
129
133
|
else
|
|
130
134
|
expected_text = to_expected_text_values(
|
|
@@ -142,7 +146,8 @@ module Playwright
|
|
|
142
146
|
timeout: timeout,
|
|
143
147
|
},
|
|
144
148
|
expected,
|
|
145
|
-
"Locator expected to contain text"
|
|
149
|
+
"Locator expected to contain text",
|
|
150
|
+
'Expect "to_contain_text"',
|
|
146
151
|
)
|
|
147
152
|
end
|
|
148
153
|
end
|
|
@@ -157,7 +162,8 @@ module Playwright
|
|
|
157
162
|
timeout: timeout,
|
|
158
163
|
},
|
|
159
164
|
name,
|
|
160
|
-
"Locator expected to have accessible name"
|
|
165
|
+
"Locator expected to have accessible name",
|
|
166
|
+
'Expect "to_have_accessible_name"',
|
|
161
167
|
)
|
|
162
168
|
end
|
|
163
169
|
_define_negation :to_have_accessible_name
|
|
@@ -171,7 +177,8 @@ module Playwright
|
|
|
171
177
|
timeout: timeout,
|
|
172
178
|
},
|
|
173
179
|
name,
|
|
174
|
-
"Locator expected to have accessible description"
|
|
180
|
+
"Locator expected to have accessible description",
|
|
181
|
+
'Expect "to_have_accessible_description"',
|
|
175
182
|
)
|
|
176
183
|
end
|
|
177
184
|
_define_negation :to_have_accessible_description
|
|
@@ -185,7 +192,8 @@ module Playwright
|
|
|
185
192
|
timeout: timeout,
|
|
186
193
|
},
|
|
187
194
|
errorMessage,
|
|
188
|
-
"Locator expected to have accessible error message"
|
|
195
|
+
"Locator expected to have accessible error message",
|
|
196
|
+
'Expect "to_have_accessible_error_message"',
|
|
189
197
|
)
|
|
190
198
|
end
|
|
191
199
|
_define_negation :to_have_accessible_error_message
|
|
@@ -200,7 +208,8 @@ module Playwright
|
|
|
200
208
|
timeout: timeout,
|
|
201
209
|
},
|
|
202
210
|
value,
|
|
203
|
-
"Locator expected to have attribute"
|
|
211
|
+
"Locator expected to have attribute",
|
|
212
|
+
'Expect "to_have_attribute"',
|
|
204
213
|
)
|
|
205
214
|
end
|
|
206
215
|
_define_negation :to_have_attribute
|
|
@@ -215,7 +224,8 @@ module Playwright
|
|
|
215
224
|
timeout: timeout,
|
|
216
225
|
},
|
|
217
226
|
expected,
|
|
218
|
-
"Locator expected to have class"
|
|
227
|
+
"Locator expected to have class",
|
|
228
|
+
'Expect "to_have_class"',
|
|
219
229
|
)
|
|
220
230
|
else
|
|
221
231
|
expected_text = to_expected_text_values([expected])
|
|
@@ -226,12 +236,48 @@ module Playwright
|
|
|
226
236
|
timeout: timeout,
|
|
227
237
|
},
|
|
228
238
|
expected,
|
|
229
|
-
"Locator expected to have class"
|
|
239
|
+
"Locator expected to have class",
|
|
240
|
+
'Expect "to_have_class"',
|
|
230
241
|
)
|
|
231
242
|
end
|
|
232
243
|
end
|
|
233
244
|
_define_negation :to_have_class
|
|
234
245
|
|
|
246
|
+
def to_contain_class(expected, timeout: nil)
|
|
247
|
+
if expected.is_a?(Enumerable)
|
|
248
|
+
if expected.any? { |e| e.is_a?(Regexp) }
|
|
249
|
+
raise ArgumentError.new('"expected" argument in toContainClass cannot contain RegExp values')
|
|
250
|
+
end
|
|
251
|
+
expected_text = to_expected_text_values(expected)
|
|
252
|
+
expect_impl(
|
|
253
|
+
"to.contain.class.array",
|
|
254
|
+
{
|
|
255
|
+
expectedText: expected_text,
|
|
256
|
+
timeout: timeout,
|
|
257
|
+
},
|
|
258
|
+
expected,
|
|
259
|
+
"Locator expected to contain class names",
|
|
260
|
+
'Expect "to_contain_class"',
|
|
261
|
+
)
|
|
262
|
+
else # Single string
|
|
263
|
+
if expected.is_a?(Regexp)
|
|
264
|
+
raise ArgumentError.new('"expected" argument in toContainClass cannot be a RegExp value')
|
|
265
|
+
end
|
|
266
|
+
expected_text = to_expected_text_values([expected])
|
|
267
|
+
expect_impl(
|
|
268
|
+
"to.contain.class",
|
|
269
|
+
{
|
|
270
|
+
expectedText: expected_text,
|
|
271
|
+
timeout: timeout,
|
|
272
|
+
},
|
|
273
|
+
expected,
|
|
274
|
+
"Locator expected to contain class",
|
|
275
|
+
'Expect "to_contain_class"',
|
|
276
|
+
)
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
_define_negation :to_contain_class
|
|
280
|
+
|
|
235
281
|
def to_have_count(count, timeout: nil)
|
|
236
282
|
expect_impl(
|
|
237
283
|
"to.have.count",
|
|
@@ -240,7 +286,8 @@ module Playwright
|
|
|
240
286
|
timeout: timeout,
|
|
241
287
|
},
|
|
242
288
|
count,
|
|
243
|
-
"Locator expected to have count"
|
|
289
|
+
"Locator expected to have count",
|
|
290
|
+
'Expect "to_have_count"',
|
|
244
291
|
)
|
|
245
292
|
end
|
|
246
293
|
_define_negation :to_have_count
|
|
@@ -255,7 +302,8 @@ module Playwright
|
|
|
255
302
|
timeout: timeout,
|
|
256
303
|
},
|
|
257
304
|
value,
|
|
258
|
-
"Locator expected to have CSS"
|
|
305
|
+
"Locator expected to have CSS",
|
|
306
|
+
'Expect "to_have_css"',
|
|
259
307
|
)
|
|
260
308
|
end
|
|
261
309
|
_define_negation :to_have_css
|
|
@@ -269,7 +317,8 @@ module Playwright
|
|
|
269
317
|
timeout: timeout,
|
|
270
318
|
},
|
|
271
319
|
id,
|
|
272
|
-
"Locator expected to have ID"
|
|
320
|
+
"Locator expected to have ID",
|
|
321
|
+
'Expect "to_have_id"',
|
|
273
322
|
)
|
|
274
323
|
end
|
|
275
324
|
_define_negation :to_have_id
|
|
@@ -283,7 +332,8 @@ module Playwright
|
|
|
283
332
|
timeout: timeout,
|
|
284
333
|
},
|
|
285
334
|
value,
|
|
286
|
-
"Locator expected to have JS Property"
|
|
335
|
+
"Locator expected to have JS Property",
|
|
336
|
+
'Expect "to_have_js_property"',
|
|
287
337
|
)
|
|
288
338
|
end
|
|
289
339
|
_define_negation :to_have_js_property
|
|
@@ -302,6 +352,7 @@ module Playwright
|
|
|
302
352
|
},
|
|
303
353
|
role,
|
|
304
354
|
"Locator expected to have accessible role",
|
|
355
|
+
'Expect "to_have_role"',
|
|
305
356
|
)
|
|
306
357
|
end
|
|
307
358
|
_define_negation :to_have_role
|
|
@@ -316,7 +367,8 @@ module Playwright
|
|
|
316
367
|
timeout: timeout,
|
|
317
368
|
},
|
|
318
369
|
value,
|
|
319
|
-
"Locator expected to have Value"
|
|
370
|
+
"Locator expected to have Value",
|
|
371
|
+
'Expect "to_have_value"',
|
|
320
372
|
)
|
|
321
373
|
end
|
|
322
374
|
_define_negation :to_have_value
|
|
@@ -331,7 +383,8 @@ module Playwright
|
|
|
331
383
|
timeout: timeout,
|
|
332
384
|
},
|
|
333
385
|
values,
|
|
334
|
-
"Locator expected to have Values"
|
|
386
|
+
"Locator expected to have Values",
|
|
387
|
+
'Expect "to_have_values"',
|
|
335
388
|
)
|
|
336
389
|
end
|
|
337
390
|
_define_negation :to_have_values
|
|
@@ -352,7 +405,8 @@ module Playwright
|
|
|
352
405
|
timeout: timeout,
|
|
353
406
|
},
|
|
354
407
|
expected,
|
|
355
|
-
"Locator expected to have text"
|
|
408
|
+
"Locator expected to have text",
|
|
409
|
+
'Expect "to_have_text"',
|
|
356
410
|
)
|
|
357
411
|
else
|
|
358
412
|
expected_text = to_expected_text_values(
|
|
@@ -369,7 +423,8 @@ module Playwright
|
|
|
369
423
|
timeout: timeout,
|
|
370
424
|
},
|
|
371
425
|
expected,
|
|
372
|
-
"Locator expected to have text"
|
|
426
|
+
"Locator expected to have text",
|
|
427
|
+
'Expect "to_have_text"',
|
|
373
428
|
)
|
|
374
429
|
end
|
|
375
430
|
end
|
|
@@ -384,6 +439,7 @@ module Playwright
|
|
|
384
439
|
},
|
|
385
440
|
expected,
|
|
386
441
|
'Locator expected to match Aria snapshot',
|
|
442
|
+
'Expect "to_match_aria_snapshot"',
|
|
387
443
|
)
|
|
388
444
|
end
|
|
389
445
|
_define_negation :to_match_aria_snapshot
|
|
@@ -393,7 +449,8 @@ module Playwright
|
|
|
393
449
|
(attached || attached.nil?) ? "to.be.attached" : "to.be.detached",
|
|
394
450
|
{ timeout: timeout },
|
|
395
451
|
nil,
|
|
396
|
-
"Locator expected to be attached"
|
|
452
|
+
"Locator expected to be attached",
|
|
453
|
+
'Expect "to_be_attached"',
|
|
397
454
|
)
|
|
398
455
|
end
|
|
399
456
|
_define_negation :to_be_attached
|
|
@@ -416,7 +473,8 @@ module Playwright
|
|
|
416
473
|
"to.be.checked",
|
|
417
474
|
{ timeout: timeout, expectedValue: expected_value },
|
|
418
475
|
nil,
|
|
419
|
-
"Locator expected to be checked"
|
|
476
|
+
"Locator expected to be checked",
|
|
477
|
+
'Expect "to_be_checked"',
|
|
420
478
|
)
|
|
421
479
|
end
|
|
422
480
|
_define_negation :to_be_checked
|
|
@@ -426,7 +484,8 @@ module Playwright
|
|
|
426
484
|
"to.be.disabled",
|
|
427
485
|
{ timeout: timeout },
|
|
428
486
|
nil,
|
|
429
|
-
"Locator expected to be disabled"
|
|
487
|
+
"Locator expected to be disabled",
|
|
488
|
+
'Expect "to_be_disabled"',
|
|
430
489
|
)
|
|
431
490
|
end
|
|
432
491
|
_define_negation :to_be_disabled
|
|
@@ -436,7 +495,8 @@ module Playwright
|
|
|
436
495
|
(editable || editable.nil?) ? "to.be.editable" : "to.be.readonly",
|
|
437
496
|
{ timeout: timeout },
|
|
438
497
|
nil,
|
|
439
|
-
"Locator expected to be editable"
|
|
498
|
+
"Locator expected to be editable",
|
|
499
|
+
'Expect "to_be_editable"',
|
|
440
500
|
)
|
|
441
501
|
end
|
|
442
502
|
_define_negation :to_be_editable
|
|
@@ -446,7 +506,8 @@ module Playwright
|
|
|
446
506
|
"to.be.empty",
|
|
447
507
|
{ timeout: timeout },
|
|
448
508
|
nil,
|
|
449
|
-
"Locator expected to be empty"
|
|
509
|
+
"Locator expected to be empty",
|
|
510
|
+
'Expect "to_be_empty"',
|
|
450
511
|
)
|
|
451
512
|
end
|
|
452
513
|
_define_negation :to_be_empty
|
|
@@ -456,7 +517,8 @@ module Playwright
|
|
|
456
517
|
(enabled || enabled.nil?) ? "to.be.enabled" : "to.be.disabled",
|
|
457
518
|
{ timeout: timeout },
|
|
458
519
|
nil,
|
|
459
|
-
"Locator expected to be enabled"
|
|
520
|
+
"Locator expected to be enabled",
|
|
521
|
+
'Expect "to_be_enabled"',
|
|
460
522
|
)
|
|
461
523
|
end
|
|
462
524
|
_define_negation :to_be_enabled
|
|
@@ -466,7 +528,8 @@ module Playwright
|
|
|
466
528
|
"to.be.hidden",
|
|
467
529
|
{ timeout: timeout },
|
|
468
530
|
nil,
|
|
469
|
-
"Locator expected to be hidden"
|
|
531
|
+
"Locator expected to be hidden",
|
|
532
|
+
'Expect "to_be_hidden"',
|
|
470
533
|
)
|
|
471
534
|
end
|
|
472
535
|
_define_negation :to_be_hidden
|
|
@@ -476,7 +539,8 @@ module Playwright
|
|
|
476
539
|
(visible || visible.nil?) ? "to.be.visible" : "to.be.hidden",
|
|
477
540
|
{ timeout: timeout },
|
|
478
541
|
nil,
|
|
479
|
-
"Locator expected to be visible"
|
|
542
|
+
"Locator expected to be visible",
|
|
543
|
+
'Expect "to_be_visible"',
|
|
480
544
|
)
|
|
481
545
|
end
|
|
482
546
|
_define_negation :to_be_visible
|
|
@@ -486,7 +550,8 @@ module Playwright
|
|
|
486
550
|
"to.be.focused",
|
|
487
551
|
{ timeout: timeout },
|
|
488
552
|
nil,
|
|
489
|
-
"Locator expected to be focused"
|
|
553
|
+
"Locator expected to be focused",
|
|
554
|
+
'Expect "to_be_focused"',
|
|
490
555
|
)
|
|
491
556
|
end
|
|
492
557
|
_define_negation :to_be_focused
|
|
@@ -496,7 +561,8 @@ module Playwright
|
|
|
496
561
|
"to.be.in.viewport",
|
|
497
562
|
{ timeout: timeout, expectedNumber: ratio }.compact,
|
|
498
563
|
nil,
|
|
499
|
-
"Locator expected to be in viewport"
|
|
564
|
+
"Locator expected to be in viewport",
|
|
565
|
+
'Expect "to_be_in_viewport"',
|
|
500
566
|
)
|
|
501
567
|
end
|
|
502
568
|
_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:,
|
|
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
|
-
|
|
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 =
|
|
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 resolve_selector
|
|
338
|
+
@frame.channel.send_message_to_server('resolveSelector', { selector: @selector })
|
|
339
|
+
end
|
|
340
|
+
|
|
332
341
|
def hover(
|
|
333
342
|
force: nil,
|
|
334
343
|
modifiers: nil,
|
|
@@ -400,7 +409,7 @@ module Playwright
|
|
|
400
409
|
def aria_snapshot(timeout: nil)
|
|
401
410
|
@frame.channel.send_message_to_server('ariaSnapshot', {
|
|
402
411
|
selector: @selector,
|
|
403
|
-
timeout: timeout,
|
|
412
|
+
timeout: _timeout(timeout),
|
|
404
413
|
}.compact)
|
|
405
414
|
end
|
|
406
415
|
|
|
@@ -508,27 +517,8 @@ module Playwright
|
|
|
508
517
|
@frame.highlight(@selector)
|
|
509
518
|
end
|
|
510
519
|
|
|
511
|
-
def expect(expression, options)
|
|
512
|
-
|
|
513
|
-
options[:expectedValue] = JavaScript::ValueSerializer
|
|
514
|
-
.new(options[:expectedValue])
|
|
515
|
-
.serialize
|
|
516
|
-
end
|
|
517
|
-
|
|
518
|
-
result = @frame.channel.send_message_to_server_result(
|
|
519
|
-
"expect",
|
|
520
|
-
{
|
|
521
|
-
selector: @selector,
|
|
522
|
-
expression: expression,
|
|
523
|
-
**options,
|
|
524
|
-
}
|
|
525
|
-
)
|
|
526
|
-
|
|
527
|
-
if result.key?('received')
|
|
528
|
-
result['received'] = JavaScript::ValueParser.new(result['received']).parse
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
result
|
|
520
|
+
def expect(expression, options, title)
|
|
521
|
+
@frame.expect(@selector, expression, options, title)
|
|
532
522
|
end
|
|
533
523
|
end
|
|
534
524
|
end
|
|
@@ -11,21 +11,21 @@ module Playwright
|
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def initialize(page,
|
|
14
|
+
def initialize(page, default_expect_timeout, is_not, message)
|
|
15
15
|
@page = PlaywrightApi.unwrap(page)
|
|
16
|
-
@
|
|
17
|
-
@
|
|
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] ||=
|
|
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 = @
|
|
28
|
+
result = @frame.expect(nil, expression, expect_options, title)
|
|
29
29
|
|
|
30
30
|
if result["matches"] == @is_not
|
|
31
31
|
actual = result["received"]
|
|
@@ -50,8 +50,11 @@ module Playwright
|
|
|
50
50
|
"\n#{message}"
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
if result['errorMessage']
|
|
54
|
+
error_message = "\n#{result['errorMessage']}"
|
|
55
|
+
end
|
|
56
|
+
out = "#{out_message}\nActual value #{actual}#{error_message} #{log}"
|
|
57
|
+
raise AssertionError.new(out)
|
|
55
58
|
else
|
|
56
59
|
true
|
|
57
60
|
end
|
|
@@ -60,7 +63,7 @@ module Playwright
|
|
|
60
63
|
private def _not # "not" is reserved in Ruby
|
|
61
64
|
PageAssertionsImpl.new(
|
|
62
65
|
@page,
|
|
63
|
-
@
|
|
66
|
+
@default_expect_timeout,
|
|
64
67
|
!@is_not,
|
|
65
68
|
@message
|
|
66
69
|
)
|
|
@@ -117,7 +120,8 @@ module Playwright
|
|
|
117
120
|
timeout: timeout,
|
|
118
121
|
},
|
|
119
122
|
title_or_regex,
|
|
120
|
-
"Page title expected to be"
|
|
123
|
+
"Page title expected to be",
|
|
124
|
+
'Expect "to_have_title"',
|
|
121
125
|
)
|
|
122
126
|
end
|
|
123
127
|
_define_negation :to_have_title
|
|
@@ -141,7 +145,8 @@ module Playwright
|
|
|
141
145
|
timeout: timeout,
|
|
142
146
|
},
|
|
143
147
|
expected,
|
|
144
|
-
"Page URL expected to be"
|
|
148
|
+
"Page URL expected to be",
|
|
149
|
+
'Expect "to_have_url"',
|
|
145
150
|
)
|
|
146
151
|
end
|
|
147
152
|
_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
|
data/lib/playwright/test.rb
CHANGED
|
@@ -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
|
-
@
|
|
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
|
-
@
|
|
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
|
-
@
|
|
44
|
+
@default_expect_timeout,
|
|
27
45
|
is_not,
|
|
28
46
|
nil,
|
|
29
47
|
)
|