URL assertions

URL assertions make it easy to confirm that your test is on the right web page during test execution. Sometimes, clicking on a link redirects the page and you might want to make sure you are where you should be, instead of a 404 page. These assertions might help catch errors sooner rather than later!

We allow you to create URL assertions against a number of attributes and properties of the URL. These include the hash, host, hostname, href, password, pathname, port, protocol, search, and username. URL assertions select the "pathname" component by default. More information about these can be found here, or summarized below.

Brief overview of URL attributes & properties:

Hash: The hash property sets or returns the anchor part of a URL, which includes the hash sign (#). For example, "#sailingboat" is the anchor part of the "https://www.example.org/index.html#sailingboat" URL.

Host/Hostname: The host property sets or returns the hostname and port of a URL. "Host" includes the port number if specified. If there's no port number specified in the URL, then it returns the same as the hostname. For example, "hostname" might provide "example.org" but host returns "example.org:7777".

Href: The href is an attribute of the anchor tag, and specifies the URL of the page that a link goes to. If there's no href attribute, then the link is not a hyperlink.

Password: A URL setting can sometimes include settings for user and password.

Pathname (selected by default): The pathname property sets or returns the pathname of the URL.

Port: The port property sets or returns the port number that the server uses for a particular URL.

Protocol: The protocol property sets or returns the protocol of the URL, which includes the colon (:)

Search: The search property sets or returns the query-string section of a URL, which includes the question mark (?).

Username: The username property sets or returns the username section of the href attribute value. The username is entered by the user, and is specified after the protocol but before the password.

The types of assertions remain consistent, and these include: equals, does not equal, contains, does not contain, starts with, does not start with, greater than, less than, greater than or equals, and less than or equals.

How to assert against a URL:

  1. Navigate to a test in which you'd like to add the assertion, and ensure that the browser is in the desired state.

  2. Click on the "Add assertion" button.

  3. Click on the "Page URL" button to make an assertion against the current URL.

Options for creating assertions on including Page URL, Cookie, Variable, and EmailOptions for creating assertions on including Page URL, Cookie, Variable, and Email

Options for creating assertions on including Page URL, Cookie, Variable, and Email

  1. Select the type and attribute/property of the URL you'd like to assert on.
Attribute/property dropdown open showing what parts of a URL you can create assertions against.Attribute/property dropdown open showing what parts of a URL you can create assertions against.

Attribute/property dropdown open showing what parts of a URL you can create assertions against.

  1. Click "Save". Depending on the type of assertion, you'll see the corresponding newly added step in your test. The following example contains a Protocol assertion.
Step in a mabl test with the text 'Assert "protocol" of current URL equals "https"'Step in a mabl test with the text 'Assert "protocol" of current URL equals "https"'

Step in a mabl test with the text 'Assert "protocol" of current URL equals "https"'


Did this page help you?