Skip to content

Commit

Permalink
[synthetics] Update docs to reflect the changes to expect (#3297) (#…
Browse files Browse the repository at this point in the history
…3301)

* first draft switch to playwright expect

* adjust based on release notes

* clarify what's not supported

(cherry picked from commit a3e45c0)

Co-authored-by: Colleen McGinnis <[email protected]>
  • Loading branch information
mergify[bot] and colleenmcginnis authored Oct 19, 2023
1 parent ee29634 commit 3011a08
Showing 1 changed file with 8 additions and 38 deletions.
46 changes: 8 additions & 38 deletions docs/en/observability/synthetics-create-test.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -155,42 +155,44 @@ For more details on getting started with the Synthetics Recorder, refer to <<syn
== Playwright syntax

Inside the callback for each step, you'll likely use a lot of Playwright syntax.
Many Playwright classes are supported in the Elastic Synthetics library to simulate
user workflows including tasks like:
Use Playwright to simulate and validate user workflows including:

* Interacting with the https://playwright.dev/docs/api/class-browser[browser]
or the current https://playwright.dev/docs/api/class-page[page] (like in the example above).
* Finding elements on a web page using https://playwright.dev/docs/api/class-locator[locators].
* Simulating https://playwright.dev/docs/api/class-mouse[mouse],
https://playwright.dev/docs/api/class-touchscreen[touch], or
https://playwright.dev/docs/api/class-keyboard[keyboard] events.
* Making assertions using https://playwright.dev/docs/test-assertions[`@playwright/test`'s `expect` function]. Read more in <<synthetics-make-assertions>>.

Visit the https://playwright.dev/docs[Playwright documentation] for information.

However, not all Playwright functionality should be used with Elastic Synthetics.

In some cases, there are alternatives to Playwright functionality built into the
Elastic Synthetics library. These alternatives are designed to work better for
synthetic monitoring. Do _not_ use Playwright syntax to:

* *Make assertions*. Use Elastic Synthetics's `expect` methods instead.
Read more in <<synthetics-make-assertions>>.
* *Make API requests.* Use Elastic Synthetic's `request`
parameter instead. Read more in <<synthetics-request-param>>.

There is also some Playwright functionality that is not supported out-of-the-box
in Elastic Synthetics including:

* https://playwright.dev/docs/api/class-video[Videos]
* The https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-screenshot-1[`toHaveScreenshot`] and https://playwright.dev/docs/api/class-snapshotassertions[`toMatchSnapshot`] assertions

[discrete]
[[synthetics-make-assertions]]
= Make assertions

Check that a value meets a specific condition.
A more complex `step` might wait for a page element to be selected
and then make sure that it matches an expected value.

Elastic Synthetics uses `@playwright/test`'s `expect` function to make assertions
and supports most https://playwright.dev/docs/test-assertions[Playwright assertions].
Elastic Synthetics does _not_ support https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-screenshot-1[`toHaveScreenshot`]
or any https://playwright.dev/docs/api/class-snapshotassertions[Snapshot Assertions].

For example, on a page using the following HTML:

[source,html]
Expand Down Expand Up @@ -219,38 +221,6 @@ step('Assert placeholder text', async () => {
<2> Use the assertion library provided by the Synthetics agent to check that
the value of the `placeholder` attribute matches a specific string.

[discrete]
[[synthetics-assertions-methods]]
== Supported `expect` methods

:jest: https://jestjs.io/docs

* {jest}/expect#not[`not ()`]
* {jest}/expect#resolves[`resolves ()`]
* {jest}/expect#rejects[`rejects ()`]
* {jest}/expect#tobevalue[`toBe (expected)`]
* {jest}/expect#tobeclosetonumber-numdigits[`toBeCloseTo (expected, numDigits?)`]
* {jest}/expect#tobedefined[`toBeDefined ()`]
* {jest}/expect#tobefalsy[`toBeFalsy ()`]
* {jest}/expect#tobegreaterthannumber\--bigint[`toBeGreaterThan (expected)`]
* {jest}/expect#tobegreaterthanorequalnumber\--bigint[`toBeGreaterThanOrEqual (expected)`]
* {jest}/expect#tobeinstanceofclass[`toBeInstanceOf (expected)`]
* {jest}/expect#tobelessthannumber\--bigint[`toBeLessThan (expected)`]
* {jest}/expect#tobelessthanorequalnumber\--bigint[`toBeLessThanOrEqual (expected)`]
* {jest}/expect#tobenull[`toBeNull ()`]
* {jest}/expect#tobetruthy[`toBeTruthy ()`]
* {jest}/expect#tobeundefined[`toBeUndefined ()`]
* {jest}/expect#tobenan[`toBeNaN ()`]
* {jest}/expect#tocontainitem[`toContain (expected)`]
* {jest}/expect#tocontainequalitem[`toContainEqual (expected)`]
* {jest}/expect#toequalvalue[`toEqual (expected)`]
* {jest}/expect#tohavelengthnumber[`toHaveLength (expected)`]
* {jest}/expect#tohavepropertykeypath-value[`toHaveProperty (keyPath, value?)`]
* {jest}/expect#tomatchregexp\--string[`toMatch (expected)`]
* {jest}/expect#tomatchobjectobject[`toMatchObject (expected)`]
* {jest}/expect#tostrictequalvalue[`toStrictEqual (expected)`]


[discrete]
[[synthetics-request-param]]
= Make API requests
Expand Down

0 comments on commit 3011a08

Please sign in to comment.