docs(java): assertion examples (#10194)

This commit is contained in:
Yury Semikhatsky 2021-11-09 12:44:02 -08:00 committed by GitHub
parent cce359ea83
commit 031ceb3553
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 3 deletions

View file

@ -1,7 +1,22 @@
# class: LocatorAssertions # class: LocatorAssertions
* langs: java * langs: java
The [LocatorAssertions] class provides assertion methods that can be used to make assertions about the [Locator] state in the tests. A new instance of [LocatorAssertions] is created by calling [`method: PlaywrightAssertions.assertThatLocator`]. The [LocatorAssertions] class provides assertion methods that can be used to make assertions about the [Locator] state in the tests. A new instance of [LocatorAssertions] is created by calling [`method: PlaywrightAssertions.assertThatLocator`]:
```java
...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class TestLocator {
...
@Test
void statusBecomesSubmitted() {
...
page.click("#submit-button");
assertThat(page.locator(".status")).hasText("Submitted");
}
}
```
## method: LocatorAssertions.containsText ## method: LocatorAssertions.containsText

View file

@ -1,7 +1,22 @@
# class: PageAssertions # class: PageAssertions
* langs: java * langs: java
The [PageAssertions] class provides assertion methods that can be used to make assertions about the [Page] state in the tests. A new instance of [LocatorAssertions] is created by calling [`method: PlaywrightAssertions.assertThatPage`]. The [PageAssertions] class provides assertion methods that can be used to make assertions about the [Page] state in the tests. A new instance of [LocatorAssertions] is created by calling [`method: PlaywrightAssertions.assertThatPage`]:
```java
...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class TestPage {
...
@Test
void navigatesToLoginPage() {
...
page.click("#login");
assertThat(page).hasURL(Pattern.compile(".*/login"));
}
}
```
## method: PageAssertions.hasTitle ## method: PageAssertions.hasTitle

View file

@ -32,7 +32,7 @@ To use Playwright assertions add the following dependency into the `pom.xml` of
<dependency> <dependency>
<groupId>com.microsoft.playwright</groupId> <groupId>com.microsoft.playwright</groupId>
<artifactId>assertions</artifactId> <artifactId>assertions</artifactId>
<version>1.16.0</version> <version>1.17.0</version>
</dependency> </dependency>
``` ```