From e7b4c181c7dd964e190d6d608e3c50a67b924f34 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 21 Oct 2021 17:44:17 -0700 Subject: [PATCH] docs(api): add assertions API for java (#9660) --- docs/src/api/class-pageassertions.md | 49 ++++++++++++++++++++++ docs/src/api/class-playwrightassertions.md | 32 ++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 docs/src/api/class-pageassertions.md create mode 100644 docs/src/api/class-playwrightassertions.md diff --git a/docs/src/api/class-pageassertions.md b/docs/src/api/class-pageassertions.md new file mode 100644 index 0000000000..2fa418e366 --- /dev/null +++ b/docs/src/api/class-pageassertions.md @@ -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'); +``` diff --git a/docs/src/api/class-playwrightassertions.md b/docs/src/api/class-playwrightassertions.md new file mode 100644 index 0000000000..2f6b3af540 --- /dev/null +++ b/docs/src/api/class-playwrightassertions.md @@ -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. +