A URL assertion can confirm that your test is on the right web page during test execution. Some examples of use cases for URL assertions include:
- After clicking on a link, asserting that the test has navigated to the new URL
- Asserting that a certain ID that shows up on a page matches the ID in the URL
- Asserting that the URL path matches a variable value
For example, if you expect to see the login page after logging out of an application, and the URL was {{@app.url}}/login, you could assert that the pathname equals /login.
URL attributes and properties
In the mabl Trainer, click on ✔︎ (Assert) > More > URL to add a URL assertion. The following table lists URL attributes and properties available for assertion:
| Property | Details |
| 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 | This attribute is 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. |
Attribute/property dropdown open showing what parts of a URL you can create assertions against.