Skip to content

Commit

Permalink
docs: improve toHaveClass paramter description
Browse files Browse the repository at this point in the history
  • Loading branch information
YusukeIwaki committed Feb 2, 2025
1 parent 7fd83f6 commit 155287d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 40 deletions.
10 changes: 5 additions & 5 deletions development/generate_api/example_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1308,10 +1308,10 @@ def example_709faaa456b4775109b1fbaca74a86ac5107af5e4801ea07cb690942f1d37f88(pag
end

# LocatorAssertions#to_have_class
def example_c16c6c567ee66b6d60de634c8a8a7c7c2b26f0e9ea8556e50a47d0c151935aa1(page:)
def example_7778d4f89215025560ecd192d60831f898331a0f339607a657c038207951e473(page:)
locator = page.locator("#component")
expect(locator).to have_class(/selected/)
expect(locator).to have_class("selected row")
expect(locator).to have_class(/(^|\s)selected(\s|$)/)
expect(locator).to have_class("middle selected row")
end

# LocatorAssertions#to_have_class
Expand Down Expand Up @@ -1380,9 +1380,9 @@ def example_e5cce4bcdea914bbae14a3645b77f19c322038b0ef81d6ad2a1c9f5b0e21b1e9(pag
end

# LocatorAssertions#to_match_aria_snapshot
def example_e0bf8d0d0ca6181f89d6e14269d53e0bd13b4e5fb1d4457c443588c887ef417e(page:)
def example_7e42f38bd7c5b69b7f22390f6afa0f53aa155d74ad6a72b080fa2910013dc22c(page:)
page.goto('https://demo.playwright.dev/todomvc/')
expect(page.locator('body')).to_match_aria_snapshot(<<~YAML)
expect(page.locator('body')).to match_aria_snapshot(<<~YAML)
- heading "todos"
- textbox "What needs to be done?"
YAML
Expand Down
22 changes: 0 additions & 22 deletions development/unimplemented_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,3 @@ Excample codes in API documentation is replaces with the methods defined in deve

The examples listed below is not yet implemented, and documentation shows Python code.


### example_7778d4f89215025560ecd192d60831f898331a0f339607a657c038207951e473 (LocatorAssertions#to_have_class)

```
from playwright.sync_api import expect
locator = page.locator("#component")
expect(locator).to_have_class(re.compile(r"(^|\\s)selected(\\s|$)"))
expect(locator).to_have_class("middle selected row")
```

### example_7e42f38bd7c5b69b7f22390f6afa0f53aa155d74ad6a72b080fa2910013dc22c (LocatorAssertions#to_match_aria_snapshot)

```
page.goto("https://demo.playwright.dev/todomvc/")
expect(page.locator('body')).to_match_aria_snapshot('''
- heading "todos"
- textbox "What needs to be done?"
''')
```
22 changes: 9 additions & 13 deletions documentation/docs/api/locator_assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,10 @@ Ensures the [Locator](./locator) points to an element with given CSS classes. Wh
<div class='middle selected row' id='component'></div>
```

```python title="example_7778d4f89215025560ecd192d60831f898331a0f339607a657c038207951e473.py"
from playwright.sync_api import expect

```ruby
locator = page.locator("#component")
expect(locator).to_have_class(re.compile(r"(^|\\s)selected(\\s|$)"))
expect(locator).to_have_class("middle selected row")

expect(locator).to have_class(/(^|\s)selected(\s|$)/)
expect(locator).to have_class("middle selected row")
```

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:
Expand Down Expand Up @@ -775,11 +772,10 @@ Asserts that the target element matches the given [accessibility snapshot](https

**Usage**

```python title="example_7e42f38bd7c5b69b7f22390f6afa0f53aa155d74ad6a72b080fa2910013dc22c.py"
page.goto("https://demo.playwright.dev/todomvc/")
expect(page.locator('body')).to_match_aria_snapshot('''
- heading "todos"
- textbox "What needs to be done?"
''')

```ruby
page.goto('https://demo.playwright.dev/todomvc/')
expect(page.locator('body')).to match_aria_snapshot(<<~YAML)
- heading "todos"
- textbox "What needs to be done?"
YAML
```
13 changes: 13 additions & 0 deletions spec/integration/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,19 @@
example_781b6f44dd462fc3753b3e48d6888f2ef4d0794253bf6ffb4c42c76f5ec3b454(page: page)
end
end

it 'should work with #to_have_class' do
with_page do |page|
page.content = "<div class='middle selected row' id='component'></div>"
example_7778d4f89215025560ecd192d60831f898331a0f339607a657c038207951e473(page: page)
end
end

it 'should work with #match_aria_snapshot' do
with_page do |page|
example_7e42f38bd7c5b69b7f22390f6afa0f53aa155d74ad6a72b080fa2910013dc22c(page: page)
end
end
end

it 'should work with Page#dispatch_event' do
Expand Down

0 comments on commit 155287d

Please sign in to comment.