Tabs & iframes
Every step runs in a context: one browser tab, and in that tab either the page itself (Top) or one iframe. A test starts in the first tab, on the page itself. To run steps in another tab or inside an iframe, the test needs a Switch context step. When you record, BugBug adds it for you.
Switch context step
Tab number
The tab to switch to. The first tab of the test is 0, the next one opened is 1, and so on.
Context
Top for the page itself, or Iframe.
Frame element
Only for Iframe: the selector of the iframe. For an iframe inside another iframe, one selector for each level, from the outermost to the innermost.
When the step runs, BugBug activates the tab, starts at the top of the page and then goes into each iframe in the path, waiting for each one to be ready. The test starts in tab 0, Top, so you don't need a Switch context step at the beginning.
Steps that change the context on their own
Go to URL
The same tab, Top, once the page has loaded.
New tab
The new tab, Top.
Open inbox
The new tab with the testing inbox, Top.
Close tab
The tab with the next higher number, or the next lower one if the closed tab had the highest number. Top.
Reload page
The same tab, Top.
Go back
The same tab, Top.
Other steps don't change the context. That includes a click that opens a link in a new tab.
Tabs
Open and use a new tab
When a click opens a link in a new tab (for example target="_blank"), the test keeps running in the old tab. To continue in the new one:
Add a Switch context step with the new tab's number (the second tab of the test is 1) and context Top.
Add the steps for the new tab, for example an assertion on the page URL.
To go back, switch context to tab 0, or close the new tab with Close tab.
When you record, BugBug adds the Switch context steps for you.
Tab numbers
Tabs get numbers in the order the test opens them, starting at 0.
A tab keeps its number for the whole run. Closing a tab doesn't renumber the others.
Only tabs opened during the test count. Tabs you had open before don't.
Iframes
Work inside an iframe
Add a Switch context step with context Iframe and the iframe's selector, for example
//IFRAME[@id="payment"].Add the steps for the elements inside the iframe. Their selectors are searched only inside that iframe.
When you're done, add a Switch context step with context Top to get back to the page.
Go to URL always brings you back to Top once the page has loaded, so after it you don't need to switch context back from an iframe.
JavaScript inside an iframe
An Execute JavaScript step always runs on the page itself (Top) of the current tab, even after you switch into an iframe. To reach an element inside a same-origin iframe from there, go through the iframe, for example
document.querySelector('iframe#payment').contentDocument. A cross-origin iframe can't be reached this way.A Custom JavaScript assertion runs in the current context, so after switching into an iframe,
elementis the element found inside that iframe.
See Custom JavaScript actions.
Choose a stable iframe selector
The iframe is found by its selector each time the Switch context step runs. Prefer attributes that don't change between runs, such as id, name or title. Avoid selectors based on src if the URL contains tokens or session IDs.
Nested iframes
For an iframe inside another iframe, the Switch context step has one selector per level. BugBug enters the outer iframe first, waits for it, then finds the inner one inside it. Each selector is searched inside the previous iframe's document. Recording sets this up for you.
Iframes from other domains
Cross-origin iframes, such as payment forms or embedded widgets from another domain, work the same way as iframes from your own domain.
Waiting conditions and timeout
A Switch context step uses the Document readyState is complete and Page network requests are finished waiting conditions by default. It waits until each iframe in the path is ready. If an iframe doesn't get ready before the step's timeout, the step fails with FRAME_LOADS_TOO_LONG. Like on other steps, you can turn these conditions off for one Switch context step.
Common errors
WINDOW_OR_TAB_DOES_NOT_EXIST
The tab number doesn't exist: the tab wasn't opened, was closed, or the number is off by one (numbering starts at 0).
FRAME_LOADS_TOO_LONG
The iframe didn't load before the timeout, or its selector matches nothing. Check the selector and the console and network logs.
ELEMENT_REMOVED
The iframe was removed or replaced while BugBug was switching into it.
FRAME_DOES_NOT_EXIST
The iframe the steps should run in is no longer there, for example because the iframe was removed or replaced. Switch context again.
ELEMENT_DOES_NOT_EXIST
The element is in an iframe, but the test is still in the Top context (or the other way round). Check the Switch context step before it.
See Error codes for all codes.
In YAML and the API
In YAML, a switchContext step has value (topFrame or iframe), tab_no, and for an iframe a selector:
For nested iframes, join the selectors of each level with >>, from the outermost iframe to the innermost:
Exported files can also contain window_no, frame_no and frame_src. They are recorded details of the frame. The iframe is found by selector.
Steps don't have a frame field of their own. Which frame a step runs in comes from the last Switch context step before it, so add the Switch context step first, also when you create steps through the Public API or MCP.
FAQ
Last updated
Was this helpful?
