Beat social media to the issue

Build our browser test

15 minutes

A browser test drives a real Google Chrome browser through a journey we write, from the locations we choose, on the schedule we set. In the Introduction module we reviewed a browser test somebody else had built. Now we build our own, for the checkout journey on our store website.

Steps and Transactions build Browser Tests:

Everyone shares one shop

Because we are all sharing the same Astronomy Shop app in this workshop, each of us will use our initials in the test name and custom properties to identify our own tests.

Create the test

Exercise Create a new browser test
  • From the main menu, select Digital Experience, then Synthetic tests.

  • Select and choose Browser test.

  • Set the configuration slider at the top of the page to Advanced to see all test configuration options such as authentication and custom headers. We will not need all of these for this exercise.

  • In Name, enter:

    text
    [NAME OF WORKSHOP]-[YOUR INITIALS]-checkout
  • In Custom properties, add two key-value pairs by typing the following and hitting ENTER after each:

    • workshop:[NAME OF WORKSHOP]
    • owner:[YOUR INITIALS]

Browser test creation page with name and custom properties

Tip

Custom properties become dimensions on every metric the test produces, so later we can build one chart that covers every test tagged workshop:[NAME OF WORKSHOP] instead of editing the chart each time somebody adds a test.

Add the steps and transactions

Exercise Script the checkout journey
  • Click .
  • Change the name of the first synthetic transaction to Browse.
  • Add a second synthetic transaction and label it Checkout.
  • Add the below steps to each transaction.

For every step that uses a selector, set Selector type to CSS and paste the value from the table into the Selector path field. Make sure to update the Step name label on the left; naming steps and transactions gives us clearer, more readable results.

#TransactionStep nameStep typeSelector valueWait for navigation
1BrowseHomepage loadsGo to URLhttps://<YOUR SHOP URL>/—
2BrowseProducts loadAssert element visible[data-cy="product-card"]—
3BrowseSelect productClick element[data-cy="product-card"]Yes
4BrowseProduct detailsAssert element visible[data-cy="product-add-to-cart"]—
5CheckoutAdd to cartClick element[data-cy="product-add-to-cart"]Yes
6CheckoutPlace orderClick element[data-cy="checkout-place-order"]Yes
7CheckoutConfirm orderAssert text present, using containsconfirmation email—

Note

Assert element visible validates that the expected element is visible to the end user. If we only want to validate that an element or text is present in the DOM, we could use Assert element/text present.

Based on our tolerance for slowness, we can adjust the wait time for certain steps. For example, on steps 2 and 4, set Wait up to 500 ms.

Step editor with Browse and Checkout transactions

Tip

There are several ways to write this test. For example, here we are matching a part of a text string we expect to be present when an order is confirmed; but if there is another element visible to the end user, or a different URL, we could use that to validate the transaction has completed instead. Play with the steps if you have extra time.

Best practices we’re using

See more best practices on Splunk Lantern’s Running Synthetic browser tests article .

Tip

The Astronomy Shop home page shows several products, and step 3 clicks the first element that matches the selector. That is intentional here: it keeps every run comparable. When we need a specific product, we use a Go to URL step against that product’s URL instead.

Validate steps

Exercise Try it before we trust it
  • Click at the top of the page. The test runs immediately and shows us each step’s result.
  • Work through any step that reports an error. The usual cause is a selector typo, or a missing Wait for navigation on a step that changes the page. If we want to accept a slow app, increase the wait times.

Quick check

Your Try now run failed at step 7. Is your test broken?

Configure how and where the test runs

Exercise Set locations, frequency, and retries

Click at the top of the page. In the Details section:

  • Locations — choose one or two public locations, ideally near us. More locations means more data, but in a shared workshop org it also means more noise for everyone.
  • Device - leave as Default Desktop. If changing the device type, best practice is to re-capture the target elements with the appropriate viewport width as elements can change between screen sizes.
  • Frequency — 5 minutes. In real life, a critical journey like this would typically run every 1 to 5 minutes.
  • Auto retries — leave on. A test that retries once before reporting a failure will not page us because of a single dropped packet or anomaly that’s less likely to be affecting end users.
  • Round-robin scheduling — leave on, so the test alternates between locations. Turning this off will test from every location at the same time.

In the Security section:

  • Leave TLS/SSL validation at its default. If the instructor says the workshop shop uses a self-signed certificate, turn it off — otherwise every run fails on the certificate before it ever reaches the checkout.

Click at the bottom of the screen to create the Browser Test.

Try now vs. Run now

Try now runs are temporary: nothing is stored, no metrics are produced, and our uptime numbers are untouched. That is what makes it safe to use while we are still fixing selectors.

Run now, which we use in the next exercise, is permanent: results are stored, they count toward metrics and subscription usage, and they appear in the UI marked as Manual.

Learn more in Set up a browser test and Add synthetic transactions to your browser test .

Last Modified ·

Report an issue