From 031ceb3553c1f6a8d9b18017677629ec6be3bdce Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Tue, 9 Nov 2021 12:44:02 -0800 Subject: [PATCH] docs(java): assertion examples (#10194) --- docs/src/api/class-locatorassertions.md | 17 ++++++++++++++++- docs/src/api/class-pageassertions.md | 17 ++++++++++++++++- docs/src/api/class-playwrightassertions.md | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/docs/src/api/class-locatorassertions.md b/docs/src/api/class-locatorassertions.md index eda9a2f39f..1d0aad31bc 100644 --- a/docs/src/api/class-locatorassertions.md +++ b/docs/src/api/class-locatorassertions.md @@ -1,7 +1,22 @@ # class: LocatorAssertions * 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 diff --git a/docs/src/api/class-pageassertions.md b/docs/src/api/class-pageassertions.md index 6a56183034..5b4a6007af 100644 --- a/docs/src/api/class-pageassertions.md +++ b/docs/src/api/class-pageassertions.md @@ -1,7 +1,22 @@ # class: PageAssertions * 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 diff --git a/docs/src/api/class-playwrightassertions.md b/docs/src/api/class-playwrightassertions.md index 214bd42d94..6c6162d193 100644 --- a/docs/src/api/class-playwrightassertions.md +++ b/docs/src/api/class-playwrightassertions.md @@ -32,7 +32,7 @@ To use Playwright assertions add the following dependency into the `pom.xml` of com.microsoft.playwright assertions - 1.16.0 + 1.17.0 ```