Introduction
There are scenarios where you might need to interact with multiple browser tabs in a test. Any modern testing tool should support testing in multiple browser tabs. And Endtest is no exception.Interact with an element that is in a different browser tab
When a new browser tab gets opened, the test will not switch the focus automatically. Since the element is in a separate browser tab, we have to tell the test to switch the focus to that browser tab before interacting with the element. In theMiscellaneous
action, you have the following methods:
Switch to next tab
Switch to previous tab
Switch to next tab
when you need to switch focus to the next tab.
When you’re done interacting with the elements from that browser tab, you can use Switch to previous tab
to switch the focus back to the original browser tab.
Opening a new tab
You may encounter scenarios where you need to open a new browser tab. For example, in a Sign Up test, you might need to fetch the activation code from the Endtest Mailbox in a different browser tab. You can use theOpen new tab
method from the Miscellaneous
action.
When using that action, the test will automatically switch focus to the new tab.
Or you can add an Execute JavaScript step, with the following JavaScript code:
Switch to next tab
step after that.
Closing a tab
Normally, you don’t have to close browser tabs in a test. The browser tabs get closed automatically when the test execution is finished. But if you have a scenario where you need to do that, you can use theClose tab
method from the Miscellaneous
action.
When using that action, the test will automatically switch focus to the previous tab.
The
Switch to next tab
and Switch to previous tab
actions are using the switch_to_window
method from Selenium WebDriver. You should never remove the target="_blank"
attribute from link elements during your test. That is a bad practice, since it modifies the web application that’s being tested. We strongly advise against using that method.