Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

docs: fix example codes of toContainClass to work (#35903)

Yusuke Iwakid476f1d3b497
diff --git a/docs/src/api/class-locatorassertions.md b/docs/src/api/class-locatorassertions.md
index 78ed036c0f..c2edbf7533 100644
--- a/docs/src/api/class-locatorassertions.md
+++ b/docs/src/api/class-locatorassertions.md
@@ -1087,7 +1087,7 @@ await Expect(locator).ToContainClassAsync("row middle");
When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class lists. Each element's class attribute is matched against the corresponding class in the array:
```html
-<div class='list'></div>
+<div class='list'>
<div class='component inactive'></div>
<div class='component active'></div>
<div class='component inactive'></div>
@@ -1095,30 +1095,30 @@ When an array is passed, the method asserts that the list of elements located ma
```
```js
-const locator = page.locator('list > .component');
+const locator = page.locator('.list > .component');
await expect(locator).toContainClass(['inactive', 'active', 'inactive']);
```
```java
-assertThat(page.locator("list > .component")).containsClass(new String[] {"inactive", "active", "inactive"});
+assertThat(page.locator(".list > .component")).containsClass(new String[] {"inactive", "active", "inactive"});
```
```python async
from playwright.async_api import expect
-locator = page.locator("list > .component")
+locator = page.locator(".list > .component")
await expect(locator).to_contain_class(["inactive", "active", "inactive"])
```
```python sync
from playwright.sync_api import expect
-locator = page.locator("list > .component")
+locator = page.locator(".list > .component")
await expect(locator).to_contain_class(["inactive", "active", "inactive"])
```
```csharp
-var locator = Page.Locator("list > .component");
+var locator = Page.Locator(".list > .component");
await Expect(locator).ToContainClassAsync(new string[]{"inactive", "active", "inactive"});
```
@@ -1591,30 +1591,30 @@ await Expect(locator).ToHaveClassAsync(new Regex("(^|\\s)selected(\\s|$)"));
When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class values. Each element's class attribute is matched against the corresponding string or regular expression in the array:
```js
-const locator = page.locator('list > .component');
+const locator = page.locator('.list > .component');
await expect(locator).toHaveClass(['component', 'component selected', 'component']);
```
```java
-assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
+assertThat(page.locator(".list > .component")).hasClass(new String[] {"component", "component selected", "component"});
```
```python async
from playwright.async_api import expect
-locator = page.locator("list > .component")
+locator = page.locator(".list > .component")
await expect(locator).to_have_class(["component", "component selected", "component"])
```
```python sync
from playwright.sync_api import expect
-locator = page.locator("list > .component")
+locator = page.locator(".list > .component")
expect(locator).to_have_class(["component", "component selected", "component"])
```
```csharp
-var locator = Page.Locator("list > .component");
+var locator = Page.Locator(".list > .component");
await Expect(locator).ToHaveClassAsync(new string[]{"component", "component selected", "component"});
```
diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts
index f0b72d8640..1aa216f182 100644
--- a/packages/playwright/types/test.d.ts
+++ b/packages/playwright/types/test.d.ts
@@ -8746,7 +8746,7 @@ interface LocatorAssertions {
* expected class lists. Each element's class attribute is matched against the corresponding class in the array:
*
* ```html
- * <div class='list'></div>
+ * <div class='list'>
* <div class='component inactive'></div>
* <div class='component active'></div>
* <div class='component inactive'></div>
@@ -8754,7 +8754,7 @@ interface LocatorAssertions {
* ```
*
* ```js
- * const locator = page.locator('list > .component');
+ * const locator = page.locator('.list > .component');
* await expect(locator).toContainClass(['inactive', 'active', 'inactive']);
* ```
*
@@ -8996,7 +8996,7 @@ interface LocatorAssertions {
* expression in the array:
*
* ```js
- * const locator = page.locator('list > .component');
+ * const locator = page.locator('.list > .component');
* await expect(locator).toHaveClass(['component', 'component selected', 'component']);
* ```
*