docs(api): add assertions API for java (#9660)

This commit is contained in:
Yury Semikhatsky 2021-10-21 17:44:17 -07:00 committed by GitHub
parent 6a3e08d1ac
commit e7b4c181c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 0 deletions

View 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');
```

View 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.