Creating a test that interacts with different browser tabs? Read on to learn what to expect when testing in different tabs and how to troubleshoot if you run into issues.
Testing in new tabs
To train a test that interacts with different tabs, make sure the Trainer record button is on. When you click on a link that opens a page in a new tab, the mabl Trainer automatically records a “Wait for tab” step. To start testing in the new tab, create an assertion or click on an element. The Trainer automatically detects that you switched to the new tab and adds a “Switch Context” step before the recorded steps.
Tabs with dynamic titles or URLs
If your application opens new tabs with dynamically generated titles or URLs, adjust Configure Find settings for the “Wait for tab” step to match the dynamically generated title or URL of the new tab.
Returning to the initial tab
If you record steps on the initial tab again, the Trainer adds another step to switch context back to the initial tab before your recorded steps.
Troubleshooting
If your test failed with a message indicating that the tab wasn’t found, such as “No new page/tab detected”, use the following guidelines to troubleshoot:
Check for dynamic page attributes
If the new tab has a dynamic title or URL, you may need to adjust Configure Find values.
Configure Find is available on the “Wait for tab” step, not the “Switch context to tab” step.
Depending on how the dynamic page attributes are created, you can take one of the following approaches with Configure Find settings:
- If you don’t know the dynamic values prior to opening the tab, add a Configure Find value with contains. For example: “Its title contains ‘Customer invoice no.’”
- If you know the dynamic values prior to opening the tab, you can store them in variables and adjust Configure Find to match the dynamically generated variable value. For example “Its url is ‘https://example.com/users/{{@user_id}}’”.
Investigate the prior step
Confirm that the click step that is opening the new tab is either clicking on a link with a target=“_blank" attribute or clicking on buttons that use window.open() to open the new tab.
Limitation
mabl does not support the following methods for opening a new tab:
- CTRL + T or ⌘+T keypress steps
- CTRL + click or ⌘+ click
With these unsupported methods, the Trainer records the “Wait for tab” and “Switch context” steps, but it does not capture the keypress actions that open the new tab.
Verify the expected steps
When a mabl test opens a new tab, it should record these two steps: “Wait for tab” and “Switch context to tab”. If one or both of these steps are missing, try re-recording the steps.
If the new tab loads slowly, the “Wait for tab” step may time out before the tab is detected. Try adding a wait step before the “Wait for tab” step to give the page more time to load.
Use a JavaScript snippet
If re-recording the steps doesn’t resolve the issue, consider using a JavaScript snippet to open the new tab. See the mabl JavaScript snippet repo for an example.