mabl now supports creating variables from a page's URL in browser tests! When creating a variable, you can select the page URL as the source and capture either the entire URL or a specific part of it. Use these variables to pull dynamic data straight from the address bar, such as an order ID, session token, or search query, and reference it later in your test.
You can capture the following parts of the URL:
- Full URL: the complete address.
- Hostname: the domain portion of the URL.
- Path segment: a segment of the URL path.
- Query parameter: the value of a named query parameter.
-
Hash: the fragment after the
#. - Regular expression: a pattern you provide.
When you choose Regular expression as the URL part, the pattern is matched against the full page URL. mabl returns the first capture group, or the whole match if your pattern has no capture group. The /pattern/flags syntax is supported.
Until now, capturing data from a URL meant writing a JavaScript snippet to read the page URL and extract the part you needed. With this addition, you can capture that data natively, so team members who aren't comfortable with code can pull dynamic values from the URL without touching a snippet.
Try it out
- Launch your web app in the mabl Trainer.
- Navigate to the page URL you want for the variable step.
- Create a new variable: {x} > Create variable.
- Set the variable using the page URL.
- Select which URL part you want to save to the variable, and add any additional details as needed.
- Give the variable a name.
- Save the variable and use it in later steps of your test.
Learn more
For more details, see creating variables in the mabl Trainer.