docs(java): assertion examples (#10194)
This commit is contained in:
parent
cce359ea83
commit
031ceb3553
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue