Navigate Between Multiple URLs Using Parameters
Learn how to handle multi-tab workflows in Harness AI Test Automation by storing URLs in parameters and navigating between them.
When working with Harness AI Test Automation (AIT), you can efficiently navigate between multiple URLs by storing them in parameters. This powerful workaround allows you to maintain context across different pages and create sophisticated multi-page test workflows.
This guide shows you how to use parameters and custom scripts to store and navigate between different URLs during your test execution, enabling seamless multi-page testing scenarios.
How It Works
AI Test Automation focuses on the currently active tab, making it streamlined and efficient. To navigate between different pages in your test workflow, you can leverage parameters to store URLs. This approach gives you:
Full control over navigation flow
Ability to return to any previously visited page
Clean, maintainable test scripts
Flexibility to build complex multi-page scenarios
The solution is simple: capture the current URL before navigating away, store it in a parameter, and use that parameter to navigate back when needed.
Step 1: Store the Current URL in a Parameter
Before navigating to a new URL, you need to capture the current page's URL and store it in a parameter.
Use a Custom Script Action
In your test workflow, add a Custom Script action
Use the following JavaScript code to capture the current URL:
Configure the action to store the result in a parameter (e.g.,
ORIGINAL_URL)
This captures the full URL of the current page and saves it for later use.
Example Configuration
Action Type: Custom Script
Script:
window.location.hrefResult Parameter:
ORIGINAL_URL
Step 2: Navigate to a New URL
After storing the original URL, you can now navigate to a different page. You have two options:
Option 1: Use the Navigate To action
Add a Navigate To user action
Enter the new URL you want to visit
For example:
Option 2: Use natural language test authoring
Simply describe the navigation in natural language, and AI Test Automation will handle it:
Whichever method you choose, once you're on the new page, the original page is no longer accessible. However, you have its URL stored in the ORIGINAL_URL parameter for later use.
Step 3: Navigate Back Using the Stored Parameter
When you need to return to the original URL, use the Navigate To action again, but this time reference the parameter you created earlier.
Add another Navigate To user action
Use the parameter syntax to reference the stored URL:
Harness AIT will automatically substitute the parameter value with the actual URL you stored earlier, taking you back to the original page.
Last updated
Was this helpful?