mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 13:45:36 +03:00
docs(api): add assertions API for java (#9660)
This commit is contained in:
parent
6a3e08d1ac
commit
e7b4c181c7
49
docs/src/api/class-pageassertions.md
Normal file
49
docs/src/api/class-pageassertions.md
Normal file
@ -0,0 +1,49 @@
|
||||
# class: PageAssertions
|
||||
* langs: java
|
||||
|
||||
The [PageAssertions] class provides assertion methods that can be used to make assertions about the [Page] state in the tests.
|
||||
|
||||
## method: PageAssertions.hasTitle
|
||||
|
||||
Ensures the page has a given title.
|
||||
|
||||
```java
|
||||
assertThat(page).hasTitle("Playwright");
|
||||
```
|
||||
|
||||
### param: PageAssertions.hasTitle.titleOrRegExp
|
||||
- `titleOrRegExp` <[string]|[RegExp]>
|
||||
|
||||
Expected title or RegExp.
|
||||
|
||||
### option: PageAssertions.hasTitle.timeout
|
||||
- `timeout` <[float]>
|
||||
|
||||
Time to retry assertion for.
|
||||
|
||||
## method: PageAssertions.hasURL
|
||||
|
||||
Ensures the page is navigated to the given URL.
|
||||
|
||||
```java
|
||||
assertThat(page).hasURL('.com');
|
||||
```
|
||||
|
||||
### param: PageAssertions.hasURL.urlOrRegExp
|
||||
- `urlOrRegExp` <[string]|[RegExp]>
|
||||
|
||||
Expected substring or RegExp.
|
||||
|
||||
### option: PageAssertions.hasURL.timeout
|
||||
- `timeout` <[float]>
|
||||
|
||||
Time to retry the assertion for.
|
||||
|
||||
## method: PageAssertions.not
|
||||
- returns: <[PageAssertions]>
|
||||
|
||||
Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't contain `"error"`:
|
||||
|
||||
```java
|
||||
assertThat(page).not().hasURL('error');
|
||||
```
|
32
docs/src/api/class-playwrightassertions.md
Normal file
32
docs/src/api/class-playwrightassertions.md
Normal file
@ -0,0 +1,32 @@
|
||||
# class: PlaywrightAssertions
|
||||
* langs: java
|
||||
|
||||
The [PlaywrightAssertions] class provides convenience methods for creating assertions that will wait until the expected condition is met.
|
||||
|
||||
Consider the following example:
|
||||
|
||||
```java
|
||||
assertThat(page.locator('.status')).hasText('Submitted');
|
||||
```
|
||||
|
||||
Playwright will be re-testing the node with the selector `.status` until fetched Node has the `"Submitted"`
|
||||
text. It will be re-fetching the node and checking it over and over, until the condition is met or until the timeout is
|
||||
reached. You can pass this timeout as an option.
|
||||
|
||||
By default, the timeout for assertions is set to 5 seconds.
|
||||
|
||||
## method: PlaywrightAssertions.assertThat
|
||||
* langs: java
|
||||
- returns: <[PageAssertions]>
|
||||
|
||||
Creates a [PageAssertions] object for the given [Page].
|
||||
|
||||
```java
|
||||
PlaywrightAssertions.assertThat(page).hasTitle("News");
|
||||
```
|
||||
|
||||
### param: PlaywrightAssertions.assertThat.page
|
||||
- `page` <[Page]>
|
||||
|
||||
[Page] object to use for assertions.
|
||||
|
Loading…
Reference in New Issue
Block a user