playwright-ruby-client 1.38.0 → 1.38.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/documentation/docs/api/locator_assertions.md +684 -0
- data/documentation/docs/include/api_coverage.md +43 -0
- data/lib/playwright/channel.rb +1 -1
- data/lib/playwright/errors.rb +2 -0
- data/lib/playwright/javascript/value_serializer.rb +1 -1
- data/lib/playwright/locator_assertions_impl.rb +417 -0
- data/lib/playwright/locator_impl.rb +24 -5
- data/lib/playwright/test.rb +68 -0
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright_api/locator.rb +5 -0
- data/lib/playwright_api/locator_assertions.rb +538 -0
- data/sig/playwright.rbs +43 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88f3401d3e186312c93e17fa2758d30cdd45c7a95676af608b87a8052d548355
|
4
|
+
data.tar.gz: c0ac53d04666186f7ae9dc892c5c4a8a5ea982739c4a38e0740c5cece26543d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf802105e56ef6c3b3786ac24c53092eb32780cb0d98232c940cdbd8fb2cc44355d741c5d27312517e3c7ff5b63d683a4c6f4e6b939f99f62b56dcc2741e28f9
|
7
|
+
data.tar.gz: 1b0a0e47e92cbeb8f5142b54416ceeeaf8a16d5428452225433da0449f85ecfe77f6157ea794c29c308d311eda0e0e79b4cdac48238b82c9b6175b65602768b3
|
@@ -0,0 +1,684 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 10
|
3
|
+
---
|
4
|
+
|
5
|
+
# LocatorAssertions
|
6
|
+
|
7
|
+
|
8
|
+
The [LocatorAssertions](./locator_assertions) class provides assertion methods that can be used to make assertions about the [Locator](./locator) state in the tests.
|
9
|
+
|
10
|
+
```python sync title=example_eff0600f575bf375d7372280ca8e6dfc51d927ced49fbcb75408c894b9e0564e.py
|
11
|
+
from playwright.sync_api import Page, expect
|
12
|
+
|
13
|
+
def test_status_becomes_submitted(page: Page) -> None:
|
14
|
+
# ..
|
15
|
+
page.get_by_role("button").click()
|
16
|
+
expect(page.locator(".status")).to_have_text("Submitted")
|
17
|
+
|
18
|
+
```
|
19
|
+
|
20
|
+
## not_to_be_attached
|
21
|
+
|
22
|
+
```
|
23
|
+
def not_to_be_attached(attached: nil, timeout: nil)
|
24
|
+
```
|
25
|
+
|
26
|
+
|
27
|
+
The opposite of [LocatorAssertions#to_be_attached](./locator_assertions#to_be_attached).
|
28
|
+
|
29
|
+
## not_to_be_checked
|
30
|
+
|
31
|
+
```
|
32
|
+
def not_to_be_checked(timeout: nil)
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
The opposite of [LocatorAssertions#to_be_checked](./locator_assertions#to_be_checked).
|
37
|
+
|
38
|
+
## not_to_be_disabled
|
39
|
+
|
40
|
+
```
|
41
|
+
def not_to_be_disabled(timeout: nil)
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
The opposite of [LocatorAssertions#to_be_disabled](./locator_assertions#to_be_disabled).
|
46
|
+
|
47
|
+
## not_to_be_editable
|
48
|
+
|
49
|
+
```
|
50
|
+
def not_to_be_editable(editable: nil, timeout: nil)
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
The opposite of [LocatorAssertions#to_be_editable](./locator_assertions#to_be_editable).
|
55
|
+
|
56
|
+
## not_to_be_empty
|
57
|
+
|
58
|
+
```
|
59
|
+
def not_to_be_empty(timeout: nil)
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
The opposite of [LocatorAssertions#to_be_empty](./locator_assertions#to_be_empty).
|
64
|
+
|
65
|
+
## not_to_be_enabled
|
66
|
+
|
67
|
+
```
|
68
|
+
def not_to_be_enabled(enabled: nil, timeout: nil)
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
The opposite of [LocatorAssertions#to_be_enabled](./locator_assertions#to_be_enabled).
|
73
|
+
|
74
|
+
## not_to_be_focused
|
75
|
+
|
76
|
+
```
|
77
|
+
def not_to_be_focused(timeout: nil)
|
78
|
+
```
|
79
|
+
|
80
|
+
|
81
|
+
The opposite of [LocatorAssertions#to_be_focused](./locator_assertions#to_be_focused).
|
82
|
+
|
83
|
+
## not_to_be_hidden
|
84
|
+
|
85
|
+
```
|
86
|
+
def not_to_be_hidden(timeout: nil)
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
The opposite of [LocatorAssertions#to_be_hidden](./locator_assertions#to_be_hidden).
|
91
|
+
|
92
|
+
## not_to_be_in_viewport
|
93
|
+
|
94
|
+
```
|
95
|
+
def not_to_be_in_viewport(ratio: nil, timeout: nil)
|
96
|
+
```
|
97
|
+
|
98
|
+
|
99
|
+
The opposite of [LocatorAssertions#to_be_in_viewport](./locator_assertions#to_be_in_viewport).
|
100
|
+
|
101
|
+
## not_to_be_visible
|
102
|
+
|
103
|
+
```
|
104
|
+
def not_to_be_visible(timeout: nil, visible: nil)
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
The opposite of [LocatorAssertions#to_be_visible](./locator_assertions#to_be_visible).
|
109
|
+
|
110
|
+
## not_to_contain_text
|
111
|
+
|
112
|
+
```
|
113
|
+
def not_to_contain_text(expected, ignoreCase: nil, timeout: nil, useInnerText: nil)
|
114
|
+
```
|
115
|
+
|
116
|
+
|
117
|
+
The opposite of [LocatorAssertions#to_contain_text](./locator_assertions#to_contain_text).
|
118
|
+
|
119
|
+
## not_to_have_attribute
|
120
|
+
|
121
|
+
```
|
122
|
+
def not_to_have_attribute(name, value, timeout: nil)
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
The opposite of [LocatorAssertions#to_have_attribute](./locator_assertions#to_have_attribute).
|
127
|
+
|
128
|
+
## not_to_have_class
|
129
|
+
|
130
|
+
```
|
131
|
+
def not_to_have_class(expected, timeout: nil)
|
132
|
+
```
|
133
|
+
|
134
|
+
|
135
|
+
The opposite of [LocatorAssertions#to_have_class](./locator_assertions#to_have_class).
|
136
|
+
|
137
|
+
## not_to_have_count
|
138
|
+
|
139
|
+
```
|
140
|
+
def not_to_have_count(count, timeout: nil)
|
141
|
+
```
|
142
|
+
|
143
|
+
|
144
|
+
The opposite of [LocatorAssertions#to_have_count](./locator_assertions#to_have_count).
|
145
|
+
|
146
|
+
## not_to_have_css
|
147
|
+
|
148
|
+
```
|
149
|
+
def not_to_have_css(name, value, timeout: nil)
|
150
|
+
```
|
151
|
+
|
152
|
+
|
153
|
+
The opposite of [LocatorAssertions#to_have_css](./locator_assertions#to_have_css).
|
154
|
+
|
155
|
+
## not_to_have_id
|
156
|
+
|
157
|
+
```
|
158
|
+
def not_to_have_id(id, timeout: nil)
|
159
|
+
```
|
160
|
+
|
161
|
+
|
162
|
+
The opposite of [LocatorAssertions#to_have_id](./locator_assertions#to_have_id).
|
163
|
+
|
164
|
+
## not_to_have_js_property
|
165
|
+
|
166
|
+
```
|
167
|
+
def not_to_have_js_property(name, value, timeout: nil)
|
168
|
+
```
|
169
|
+
|
170
|
+
|
171
|
+
The opposite of [LocatorAssertions#to_have_js_property](./locator_assertions#to_have_js_property).
|
172
|
+
|
173
|
+
## not_to_have_text
|
174
|
+
|
175
|
+
```
|
176
|
+
def not_to_have_text(expected, ignoreCase: nil, timeout: nil, useInnerText: nil)
|
177
|
+
```
|
178
|
+
|
179
|
+
|
180
|
+
The opposite of [LocatorAssertions#to_have_text](./locator_assertions#to_have_text).
|
181
|
+
|
182
|
+
## not_to_have_value
|
183
|
+
|
184
|
+
```
|
185
|
+
def not_to_have_value(value, timeout: nil)
|
186
|
+
```
|
187
|
+
|
188
|
+
|
189
|
+
The opposite of [LocatorAssertions#to_have_value](./locator_assertions#to_have_value).
|
190
|
+
|
191
|
+
## not_to_have_values
|
192
|
+
|
193
|
+
```
|
194
|
+
def not_to_have_values(values, timeout: nil)
|
195
|
+
```
|
196
|
+
|
197
|
+
|
198
|
+
The opposite of [LocatorAssertions#to_have_values](./locator_assertions#to_have_values).
|
199
|
+
|
200
|
+
## to_be_attached
|
201
|
+
|
202
|
+
```
|
203
|
+
def to_be_attached(attached: nil, timeout: nil)
|
204
|
+
```
|
205
|
+
|
206
|
+
|
207
|
+
Ensures that [Locator](./locator) points to an [attached](https://playwright.dev/python/docs/actionability#attached) DOM node.
|
208
|
+
|
209
|
+
**Usage**
|
210
|
+
|
211
|
+
```python sync title=example_781b6f44dd462fc3753b3e48d6888f2ef4d0794253bf6ffb4c42c76f5ec3b454.py
|
212
|
+
expect(page.get_by_text("Hidden text")).to_be_attached()
|
213
|
+
|
214
|
+
```
|
215
|
+
|
216
|
+
## to_be_checked
|
217
|
+
|
218
|
+
```
|
219
|
+
def to_be_checked(checked: nil, timeout: nil)
|
220
|
+
```
|
221
|
+
|
222
|
+
|
223
|
+
Ensures the [Locator](./locator) points to a checked input.
|
224
|
+
|
225
|
+
**Usage**
|
226
|
+
|
227
|
+
```python sync title=example_00a58b66eec12973ab87c0ce5004126aa1f1af5a971a9e89638669f729bbb1b6.py
|
228
|
+
from playwright.sync_api import expect
|
229
|
+
|
230
|
+
locator = page.get_by_label("Subscribe to newsletter")
|
231
|
+
expect(locator).to_be_checked()
|
232
|
+
|
233
|
+
```
|
234
|
+
|
235
|
+
## to_be_disabled
|
236
|
+
|
237
|
+
```
|
238
|
+
def to_be_disabled(timeout: nil)
|
239
|
+
```
|
240
|
+
|
241
|
+
|
242
|
+
Ensures the [Locator](./locator) points to a disabled element. Element is disabled if it has "disabled" attribute
|
243
|
+
or is disabled via ['aria-disabled'](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled).
|
244
|
+
Note that only native control elements such as HTML `button`, `input`, `select`, `textarea`, `option`, `optgroup`
|
245
|
+
can be disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored
|
246
|
+
by the browser.
|
247
|
+
|
248
|
+
**Usage**
|
249
|
+
|
250
|
+
```python sync title=example_fc3052bc38e6c1968f23f9185bda7f06478af4719ce96f6a49878ea7e72c9a82.py
|
251
|
+
from playwright.sync_api import expect
|
252
|
+
|
253
|
+
locator = page.locator("button.submit")
|
254
|
+
expect(locator).to_be_disabled()
|
255
|
+
|
256
|
+
```
|
257
|
+
|
258
|
+
## to_be_editable
|
259
|
+
|
260
|
+
```
|
261
|
+
def to_be_editable(editable: nil, timeout: nil)
|
262
|
+
```
|
263
|
+
|
264
|
+
|
265
|
+
Ensures the [Locator](./locator) points to an editable element.
|
266
|
+
|
267
|
+
**Usage**
|
268
|
+
|
269
|
+
```python sync title=example_a42b1e97cd0899ccd72bc4b74ab8f57c549814ca5b6d1bb912c870153d6d3f8d.py
|
270
|
+
from playwright.sync_api import expect
|
271
|
+
|
272
|
+
locator = page.get_by_role("textbox")
|
273
|
+
expect(locator).to_be_editable()
|
274
|
+
|
275
|
+
```
|
276
|
+
|
277
|
+
## to_be_empty
|
278
|
+
|
279
|
+
```
|
280
|
+
def to_be_empty(timeout: nil)
|
281
|
+
```
|
282
|
+
|
283
|
+
|
284
|
+
Ensures the [Locator](./locator) points to an empty editable element or to a DOM node that has no text.
|
285
|
+
|
286
|
+
**Usage**
|
287
|
+
|
288
|
+
```python sync title=example_1fb5a7ee389401cf5a6fb3ba90c5b58c42c93d43aa5e4e34d99a5c6265ce0b35.py
|
289
|
+
from playwright.sync_api import expect
|
290
|
+
|
291
|
+
locator = page.locator("div.warning")
|
292
|
+
expect(locator).to_be_empty()
|
293
|
+
|
294
|
+
```
|
295
|
+
|
296
|
+
## to_be_enabled
|
297
|
+
|
298
|
+
```
|
299
|
+
def to_be_enabled(enabled: nil, timeout: nil)
|
300
|
+
```
|
301
|
+
|
302
|
+
|
303
|
+
Ensures the [Locator](./locator) points to an enabled element.
|
304
|
+
|
305
|
+
**Usage**
|
306
|
+
|
307
|
+
```python sync title=example_0389b23d34a430ee418fd2138f9b8269df20fb6595f2618400e3d53b4f344a75.py
|
308
|
+
from playwright.sync_api import expect
|
309
|
+
|
310
|
+
locator = page.locator("button.submit")
|
311
|
+
expect(locator).to_be_enabled()
|
312
|
+
|
313
|
+
```
|
314
|
+
|
315
|
+
## to_be_focused
|
316
|
+
|
317
|
+
```
|
318
|
+
def to_be_focused(timeout: nil)
|
319
|
+
```
|
320
|
+
|
321
|
+
|
322
|
+
Ensures the [Locator](./locator) points to a focused DOM node.
|
323
|
+
|
324
|
+
**Usage**
|
325
|
+
|
326
|
+
```python sync title=example_9fc7c2560e0a8117bc4ba14d6133a3d9c66cf6461c29c5a74fe132dea8bd8d63.py
|
327
|
+
from playwright.sync_api import expect
|
328
|
+
|
329
|
+
locator = page.get_by_role("textbox")
|
330
|
+
expect(locator).to_be_focused()
|
331
|
+
|
332
|
+
```
|
333
|
+
|
334
|
+
## to_be_hidden
|
335
|
+
|
336
|
+
```
|
337
|
+
def to_be_hidden(timeout: nil)
|
338
|
+
```
|
339
|
+
|
340
|
+
|
341
|
+
Ensures that [Locator](./locator) either does not resolve to any DOM node, or resolves to a [non-visible](https://playwright.dev/python/docs/actionability#visible) one.
|
342
|
+
|
343
|
+
**Usage**
|
344
|
+
|
345
|
+
```python sync title=example_55b9181de8eb71936b5e5289631fca33d2100f47f4c4e832d92c23f923779c62.py
|
346
|
+
from playwright.sync_api import expect
|
347
|
+
|
348
|
+
locator = page.locator('.my-element')
|
349
|
+
expect(locator).to_be_hidden()
|
350
|
+
|
351
|
+
```
|
352
|
+
|
353
|
+
## to_be_in_viewport
|
354
|
+
|
355
|
+
```
|
356
|
+
def to_be_in_viewport(ratio: nil, timeout: nil)
|
357
|
+
```
|
358
|
+
|
359
|
+
|
360
|
+
Ensures the [Locator](./locator) points to an element that intersects viewport, according to the [intersection observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API).
|
361
|
+
|
362
|
+
**Usage**
|
363
|
+
|
364
|
+
```python sync title=example_7d5d5657528a32a8fb24cbf30e7bb3154cdf4c426e84e40131445a38fe8df2ee.py
|
365
|
+
from playwright.sync_api import expect
|
366
|
+
|
367
|
+
locator = page.get_by_role("button")
|
368
|
+
# Make sure at least some part of element intersects viewport.
|
369
|
+
expect(locator).to_be_in_viewport()
|
370
|
+
# Make sure element is fully outside of viewport.
|
371
|
+
expect(locator).not_to_be_in_viewport()
|
372
|
+
# Make sure that at least half of the element intersects viewport.
|
373
|
+
expect(locator).to_be_in_viewport(ratio=0.5)
|
374
|
+
|
375
|
+
```
|
376
|
+
|
377
|
+
## to_be_visible
|
378
|
+
|
379
|
+
```
|
380
|
+
def to_be_visible(timeout: nil, visible: nil)
|
381
|
+
```
|
382
|
+
|
383
|
+
|
384
|
+
Ensures that [Locator](./locator) points to an [attached](https://playwright.dev/python/docs/actionability#attached) and [visible](https://playwright.dev/python/docs/actionability#visible) DOM node.
|
385
|
+
|
386
|
+
**Usage**
|
387
|
+
|
388
|
+
```python sync title=example_84ccd2ec31f9f00136a2931e9abb9c766eab967a6e892d3dcf90c02f14e5117f.py
|
389
|
+
expect(page.get_by_text("Welcome")).to_be_visible()
|
390
|
+
|
391
|
+
```
|
392
|
+
|
393
|
+
## to_contain_text
|
394
|
+
|
395
|
+
```
|
396
|
+
def to_contain_text(expected, ignoreCase: nil, timeout: nil, useInnerText: nil)
|
397
|
+
```
|
398
|
+
|
399
|
+
|
400
|
+
Ensures the [Locator](./locator) points to an element that contains the given text. You can use regular expressions for the value as well.
|
401
|
+
|
402
|
+
**Usage**
|
403
|
+
|
404
|
+
```python sync title=example_3553a48e2a15853f4869604ef20dae14952c16abfa0570b8f02e9b74e3d84faa.py
|
405
|
+
import re
|
406
|
+
from playwright.sync_api import expect
|
407
|
+
|
408
|
+
locator = page.locator('.title')
|
409
|
+
expect(locator).to_contain_text("substring")
|
410
|
+
expect(locator).to_contain_text(re.compile(r"\d messages"))
|
411
|
+
|
412
|
+
```
|
413
|
+
|
414
|
+
If you pass an array as an expected value, the expectations are:
|
415
|
+
1. Locator resolves to a list of elements.
|
416
|
+
1. Elements from a **subset** of this list contain text from the expected array, respectively.
|
417
|
+
1. The matching subset of elements has the same order as the expected array.
|
418
|
+
1. Each text value from the expected array is matched by some element from the list.
|
419
|
+
|
420
|
+
For example, consider the following list:
|
421
|
+
|
422
|
+
```html
|
423
|
+
<ul>
|
424
|
+
<li>Item Text 1</li>
|
425
|
+
<li>Item Text 2</li>
|
426
|
+
<li>Item Text 3</li>
|
427
|
+
</ul>
|
428
|
+
```
|
429
|
+
|
430
|
+
Let's see how we can use the assertion:
|
431
|
+
|
432
|
+
```python sync title=example_fb3cde55b658aefe2e54f93e5b78d26f25cd376eaa469434631af079bb8d8a62.py
|
433
|
+
from playwright.sync_api import expect
|
434
|
+
|
435
|
+
# ✓ Contains the right items in the right order
|
436
|
+
expect(page.locator("ul > li")).to_contain_text(["Text 1", "Text 3", "Text 4"])
|
437
|
+
|
438
|
+
# ✖ Wrong order
|
439
|
+
expect(page.locator("ul > li")).to_contain_text(["Text 3", "Text 2"])
|
440
|
+
|
441
|
+
# ✖ No item contains this text
|
442
|
+
expect(page.locator("ul > li")).to_contain_text(["Some 33"])
|
443
|
+
|
444
|
+
# ✖ Locator points to the outer list element, not to the list items
|
445
|
+
expect(page.locator("ul")).to_contain_text(["Text 3"])
|
446
|
+
|
447
|
+
```
|
448
|
+
|
449
|
+
## to_have_attribute
|
450
|
+
|
451
|
+
```
|
452
|
+
def to_have_attribute(name, value, timeout: nil)
|
453
|
+
```
|
454
|
+
|
455
|
+
|
456
|
+
Ensures the [Locator](./locator) points to an element with given attribute.
|
457
|
+
|
458
|
+
**Usage**
|
459
|
+
|
460
|
+
```python sync title=example_709faaa456b4775109b1fbaca74a86ac5107af5e4801ea07cb690942f1d37f88.py
|
461
|
+
from playwright.sync_api import expect
|
462
|
+
|
463
|
+
locator = page.locator("input")
|
464
|
+
expect(locator).to_have_attribute("type", "text")
|
465
|
+
|
466
|
+
```
|
467
|
+
|
468
|
+
## to_have_class
|
469
|
+
|
470
|
+
```
|
471
|
+
def to_have_class(expected, timeout: nil)
|
472
|
+
```
|
473
|
+
|
474
|
+
|
475
|
+
Ensures the [Locator](./locator) points to an element with given CSS classes. This needs to be a full match
|
476
|
+
or using a relaxed regular expression.
|
477
|
+
|
478
|
+
**Usage**
|
479
|
+
|
480
|
+
```html
|
481
|
+
<div class='selected row' id='component'></div>
|
482
|
+
```
|
483
|
+
|
484
|
+
```python sync title=example_c16c6c567ee66b6d60de634c8a8a7c7c2b26f0e9ea8556e50a47d0c151935aa1.py
|
485
|
+
from playwright.sync_api import expect
|
486
|
+
|
487
|
+
locator = page.locator("#component")
|
488
|
+
expect(locator).to_have_class(re.compile(r"selected"))
|
489
|
+
expect(locator).to_have_class("selected row")
|
490
|
+
|
491
|
+
```
|
492
|
+
|
493
|
+
Note that if array is passed as an expected value, entire lists of elements can be asserted:
|
494
|
+
|
495
|
+
```python sync title=example_96b9affd86317eeafe4a419f6ec484d33cea4ee947297f44b7b4ebb373261f1d.py
|
496
|
+
from playwright.sync_api import expect
|
497
|
+
|
498
|
+
locator = page.locator("list > .component")
|
499
|
+
expect(locator).to_have_class(["component", "component selected", "component"])
|
500
|
+
|
501
|
+
```
|
502
|
+
|
503
|
+
## to_have_count
|
504
|
+
|
505
|
+
```
|
506
|
+
def to_have_count(count, timeout: nil)
|
507
|
+
```
|
508
|
+
|
509
|
+
|
510
|
+
Ensures the [Locator](./locator) resolves to an exact number of DOM nodes.
|
511
|
+
|
512
|
+
**Usage**
|
513
|
+
|
514
|
+
```python sync title=example_b3e3d5c7f2ff3a225541e57968953a77e32048daddaabe29ba84e93a1fcee84f.py
|
515
|
+
from playwright.sync_api import expect
|
516
|
+
|
517
|
+
locator = page.locator("list > .component")
|
518
|
+
expect(locator).to_have_count(3)
|
519
|
+
|
520
|
+
```
|
521
|
+
|
522
|
+
## to_have_css
|
523
|
+
|
524
|
+
```
|
525
|
+
def to_have_css(name, value, timeout: nil)
|
526
|
+
```
|
527
|
+
|
528
|
+
|
529
|
+
Ensures the [Locator](./locator) resolves to an element with the given computed CSS style.
|
530
|
+
|
531
|
+
**Usage**
|
532
|
+
|
533
|
+
```python sync title=example_12c52b928c1fac117b68573a914ce0ef9595becead95a0ee7c1f487ba1ad9010.py
|
534
|
+
from playwright.sync_api import expect
|
535
|
+
|
536
|
+
locator = page.get_by_role("button")
|
537
|
+
expect(locator).to_have_css("display", "flex")
|
538
|
+
|
539
|
+
```
|
540
|
+
|
541
|
+
## to_have_id
|
542
|
+
|
543
|
+
```
|
544
|
+
def to_have_id(id, timeout: nil)
|
545
|
+
```
|
546
|
+
|
547
|
+
|
548
|
+
Ensures the [Locator](./locator) points to an element with the given DOM Node ID.
|
549
|
+
|
550
|
+
**Usage**
|
551
|
+
|
552
|
+
```python sync title=example_5a4c0b1802f0751c2e1068d831ecd499b36a7860605050ba976c2290452bbd89.py
|
553
|
+
from playwright.sync_api import expect
|
554
|
+
|
555
|
+
locator = page.get_by_role("textbox")
|
556
|
+
expect(locator).to_have_id("lastname")
|
557
|
+
|
558
|
+
```
|
559
|
+
|
560
|
+
## to_have_js_property
|
561
|
+
|
562
|
+
```
|
563
|
+
def to_have_js_property(name, value, timeout: nil)
|
564
|
+
```
|
565
|
+
|
566
|
+
|
567
|
+
Ensures the [Locator](./locator) points to an element with given JavaScript property. Note that this property can be
|
568
|
+
of a primitive type as well as a plain serializable JavaScript object.
|
569
|
+
|
570
|
+
**Usage**
|
571
|
+
|
572
|
+
```python sync title=example_01cad4288f995d4b6253003eb0f4acb227e80553410cea0a8db0ab6927247d92.py
|
573
|
+
from playwright.sync_api import expect
|
574
|
+
|
575
|
+
locator = page.locator(".component")
|
576
|
+
expect(locator).to_have_js_property("loaded", True)
|
577
|
+
|
578
|
+
```
|
579
|
+
|
580
|
+
## to_have_text
|
581
|
+
|
582
|
+
```
|
583
|
+
def to_have_text(expected, ignoreCase: nil, timeout: nil, useInnerText: nil)
|
584
|
+
```
|
585
|
+
|
586
|
+
|
587
|
+
Ensures the [Locator](./locator) points to an element with the given text. You can use regular expressions for the value as well.
|
588
|
+
|
589
|
+
**Usage**
|
590
|
+
|
591
|
+
```python sync title=example_4ece81163bcb1edeccd7cea8f8c6158cf794c8ef88a673e8c5350a10eaa81542.py
|
592
|
+
import re
|
593
|
+
from playwright.sync_api import expect
|
594
|
+
|
595
|
+
locator = page.locator(".title")
|
596
|
+
expect(locator).to_have_text(re.compile(r"Welcome, Test User"))
|
597
|
+
expect(locator).to_have_text(re.compile(r"Welcome, .*"))
|
598
|
+
|
599
|
+
```
|
600
|
+
|
601
|
+
If you pass an array as an expected value, the expectations are:
|
602
|
+
1. Locator resolves to a list of elements.
|
603
|
+
1. The number of elements equals the number of expected values in the array.
|
604
|
+
1. Elements from the list have text matching expected array values, one by one, in order.
|
605
|
+
|
606
|
+
For example, consider the following list:
|
607
|
+
|
608
|
+
```html
|
609
|
+
<ul>
|
610
|
+
<li>Text 1</li>
|
611
|
+
<li>Text 2</li>
|
612
|
+
<li>Text 3</li>
|
613
|
+
</ul>
|
614
|
+
```
|
615
|
+
|
616
|
+
Let's see how we can use the assertion:
|
617
|
+
|
618
|
+
```python sync title=example_2caa32069462b536399b1e7e9ade6388ab8b83912ae46ba293cf8ed241c48e85.py
|
619
|
+
from playwright.sync_api import expect
|
620
|
+
|
621
|
+
# ✓ Has the right items in the right order
|
622
|
+
expect(page.locator("ul > li")).to_have_text(["Text 1", "Text 2", "Text 3"])
|
623
|
+
|
624
|
+
# ✖ Wrong order
|
625
|
+
expect(page.locator("ul > li")).to_have_text(["Text 3", "Text 2", "Text 1"])
|
626
|
+
|
627
|
+
# ✖ Last item does not match
|
628
|
+
expect(page.locator("ul > li")).to_have_text(["Text 1", "Text 2", "Text"])
|
629
|
+
|
630
|
+
# ✖ Locator points to the outer list element, not to the list items
|
631
|
+
expect(page.locator("ul")).to_have_text(["Text 1", "Text 2", "Text 3"])
|
632
|
+
|
633
|
+
```
|
634
|
+
|
635
|
+
## to_have_value
|
636
|
+
|
637
|
+
```
|
638
|
+
def to_have_value(value, timeout: nil)
|
639
|
+
```
|
640
|
+
|
641
|
+
|
642
|
+
Ensures the [Locator](./locator) points to an element with the given input value. You can use regular expressions for the value as well.
|
643
|
+
|
644
|
+
**Usage**
|
645
|
+
|
646
|
+
```python sync title=example_84f23ac0426bebae60693613034771d70a26808dff53d1d476c3f5856346521a.py
|
647
|
+
import re
|
648
|
+
from playwright.sync_api import expect
|
649
|
+
|
650
|
+
locator = page.locator("input[type=number]")
|
651
|
+
expect(locator).to_have_value(re.compile(r"[0-9]"))
|
652
|
+
|
653
|
+
```
|
654
|
+
|
655
|
+
## to_have_values
|
656
|
+
|
657
|
+
```
|
658
|
+
def to_have_values(values, timeout: nil)
|
659
|
+
```
|
660
|
+
|
661
|
+
|
662
|
+
Ensures the [Locator](./locator) points to multi-select/combobox (i.e. a `select` with the `multiple` attribute) and the specified values are selected.
|
663
|
+
|
664
|
+
**Usage**
|
665
|
+
|
666
|
+
For example, given the following element:
|
667
|
+
|
668
|
+
```html
|
669
|
+
<select id="favorite-colors" multiple>
|
670
|
+
<option value="R">Red</option>
|
671
|
+
<option value="G">Green</option>
|
672
|
+
<option value="B">Blue</option>
|
673
|
+
</select>
|
674
|
+
```
|
675
|
+
|
676
|
+
```python sync title=example_e5cce4bcdea914bbae14a3645b77f19c322038b0ef81d6ad2a1c9f5b0e21b1e9.py
|
677
|
+
import re
|
678
|
+
from playwright.sync_api import expect
|
679
|
+
|
680
|
+
locator = page.locator("id=favorite-colors")
|
681
|
+
locator.select_option(["R", "G"])
|
682
|
+
expect(locator).to_have_values([re.compile(r"R"), re.compile(r"G")])
|
683
|
+
|
684
|
+
```
|