Path Steps

Path steps give you precise, structured assertions on the current URL: the exact pathname and the presence or value of individual query parameters. Where the navigation group's I should be on "..." is a forgiving substring check, this group parses the URL with the standard URL API, so the path should be "/dashboard" compares only the pathname - query strings and fragments never cause false failures, and never mask a wrong path either.

That precision makes these steps the right tool for marketing-link QA and analytics verification: confirm a campaign landing page keeps its ref parameter, that a language switcher writes lang=en, or that a debug flag is never present in production URLs. Each parameter assertion has a positive and a negative form, and value checks are exact string comparisons.

The group rounds out with two utilities that belong to URL-level workflows: re-opening the browser context with HTTP basic-auth credentials (for password-protected staging sites), and I go back, a one-step return through browser history.

Quick reference

StepWhat it does
Then the path should be "/dashboard"Assert the current URL pathname equals an expected string (no query/fragment).
Then the path should not be "/login"Assert the current URL pathname is NOT equal to an expected string.
Then current url should have the "lang" parameterAssert the current URL has the named query parameter (any value).
Then current url should have the "lang" parameter with the "en" valueAssert the current URL has the named query parameter with the exact value.
Then current url should not have the "missing" parameterAssert the current URL does NOT carry the named query parameter.
Then current url should not have the "lang" parameter with the "fr" valueAssert the current URL does NOT carry a parameter+value pair.
Given the basic authentication with the username "admin" and the password "secret"Re-open the browser context with HTTP basic-auth credentials.
When I go backNavigate one step back in the browser history.

Steps in detail

Then the path should be "..." / the path should not be "..."

Strict equality against URL.pathname only. On /path.html?lang=en&debug=1 the pathname is exactly /path.html, so the assertion ignores the query string entirely - but /path.html/ would fail, because trailing slashes are part of the pathname. Use "/" for the site root. The negative form guards against unwanted redirects, e.g. landing on /login or /maintenance.

Given I am on "/path.html?lang=en&debug=1"
Then the path should be "/path.html"
And the path should not be "/wrong"

Then current url should have the "..." parameter

Passes if the named query parameter is present with any value, including an empty one. The failure message prints the full current URL so you can see what the page actually carried. Parameter names are case-sensitive, matching URLSearchParams semantics.

Given I am on "/path.html?lang=en&page=2"
Then current url should have the "lang" parameter
And current url should have the "page" parameter

Then current url should have the "..." parameter with the "..." value

Exact string comparison against the parameter's (first) value. Numbers are still strings in a URL, so write with the "2" value, not 2. Ideal for checking sort orders, pagination, search terms, and campaign codes survive a click-through.

When I follow "English"
Then current url should have the "lang" parameter with the "en" value
And current url should have the "ref" parameter with the "newsletter" value

Then current url should not have the "..." parameter [with the "..." value]

The bare form asserts the parameter is entirely absent - the go-to check that debug, preview, or test flags never leak into real URLs. The with the value form is looser: it only asserts the parameter does not carry that particular value, so it passes when the parameter is missing or set to something else.

Given I am on "/path.html?lang=en"
Then current url should not have the "debug" parameter
And current url should not have the "lang" parameter with the "fr" value

Given the basic authentication with the username "..." and the password "..."

Closes the current browser context and opens a fresh one whose httpCredentials answer HTTP basic-auth challenges, reusing your project's playwright.config context options. Because the context is replaced, cookies, storage, and any open page state are discarded - put this step first and navigate afterwards. An empty password is allowed.

Given the basic authentication with the username "admin" and the password "secret"
And I am on "/protected/reports"
Then I should see "Quarterly report"

When I go back

Navigates one step back in history via page.goBack() - equivalent to the browser back button. If there is no history to return to, the step completes without error. we go back and bare And go back also match. Follow it with a path assertion (or a URL wait) to confirm where you landed.

Given I am on "/path.html"
When I go to "/element.html"
And I go back
Then the path should be "/path.html"

Complete example

From tests/features/path.feature, running against the bundled examples/path.html fixture page.

Feature: Path step definitions

  Scenario: Path and query parameter assertions
    Given I am on "/path.html?lang=en&debug=1"
     Then the path should be "/path.html"
      And the path should not be "/wrong"
      And current url should have the "lang" parameter
      And current url should have the "lang" parameter with the "en" value
      And current url should not have the "missing" parameter
      And current url should not have the "lang" parameter with the "fr" value

  Scenario: History navigation
    Given I am on "/path.html"
     When I go to "/element.html"
      And I go back
     Then the path should be "/path.html"

Tips

  • Need a looser "URL contains" check? Use Then I should be on "..." from the navigation steps; need a regex, use the url should match "..." from the same group.
  • Parameter values are compared as strings exactly as they appear (URL-decoded), so quote numbers: with the "2" value.
  • The basic-auth step rebuilds the browser context - any state from earlier steps in the scenario is lost, so make it the first step.

Back to all step groups