2021-10-21 17:44:17 -07:00
|
|
|
# class: PlaywrightAssertions
|
2021-11-18 00:46:30 +01:00
|
|
|
* langs: java, python
|
2021-10-21 17:44:17 -07:00
|
|
|
|
|
|
|
The [PlaywrightAssertions] class provides convenience methods for creating assertions that will wait until the expected condition is met.
|
|
|
|
|
|
|
|
Consider the following example:
|
|
|
|
|
|
|
|
```java
|
2021-10-29 08:33:07 -07:00
|
|
|
...
|
|
|
|
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
|
|
|
|
|
|
|
public class TestExample {
|
|
|
|
...
|
|
|
|
@Test
|
|
|
|
void statusBecomesSubmitted() {
|
|
|
|
...
|
|
|
|
page.click("#submit-button");
|
|
|
|
assertThat(page.locator(".status")).hasText("Submitted");
|
|
|
|
}
|
|
|
|
}
|
2021-10-21 17:44:17 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2021-10-29 08:33:07 -07:00
|
|
|
To use Playwright assertions add the following dependency into the `pom.xml` of your Maven project:
|
|
|
|
|
|
|
|
```xml
|
|
|
|
<dependency>
|
|
|
|
<groupId>com.microsoft.playwright</groupId>
|
|
|
|
<artifactId>assertions</artifactId>
|
2021-11-09 12:44:02 -08:00
|
|
|
<version>1.17.0</version>
|
2021-10-29 08:33:07 -07:00
|
|
|
</dependency>
|
|
|
|
```
|
|
|
|
|
2021-10-22 16:56:58 -07:00
|
|
|
## method: PlaywrightAssertions.assertThatLocator
|
2021-11-18 00:46:30 +01:00
|
|
|
* langs: java, python
|
2021-10-25 12:03:24 -07:00
|
|
|
- alias-java: assertThat
|
2021-11-18 00:46:30 +01:00
|
|
|
- alias-python: expect
|
2021-10-22 16:56:58 -07:00
|
|
|
- returns: <[LocatorAssertions]>
|
|
|
|
|
|
|
|
Creates a [LocatorAssertions] object for the given [Locator].
|
|
|
|
|
|
|
|
```java
|
|
|
|
PlaywrightAssertions.assertThat(locator).isVisible();
|
|
|
|
```
|
|
|
|
|
|
|
|
### param: PlaywrightAssertions.assertThatLocator.locator
|
|
|
|
- `locator` <[Locator]>
|
|
|
|
|
|
|
|
[Locator] object to use for assertions.
|
|
|
|
|
|
|
|
## method: PlaywrightAssertions.assertThatPage
|
2021-11-18 00:46:30 +01:00
|
|
|
* langs: java, python
|
2021-10-25 12:03:24 -07:00
|
|
|
- alias-java: assertThat
|
2021-11-18 00:46:30 +01:00
|
|
|
- alias-python: expect
|
2021-10-21 17:44:17 -07:00
|
|
|
- returns: <[PageAssertions]>
|
|
|
|
|
|
|
|
Creates a [PageAssertions] object for the given [Page].
|
|
|
|
|
|
|
|
```java
|
|
|
|
PlaywrightAssertions.assertThat(page).hasTitle("News");
|
|
|
|
```
|
|
|
|
|
2021-10-22 16:56:58 -07:00
|
|
|
### param: PlaywrightAssertions.assertThatPage.page
|
2021-10-21 17:44:17 -07:00
|
|
|
- `page` <[Page]>
|
|
|
|
|
|
|
|
[Page] object to use for assertions.
|