Is there a way to resize the browser window or switch to a different window or tab?
Loadster’s Browser Bots start with a single window with a 1280x720 viewport by default.
This works fine for most sites, but you might need to change it if your responsive site shows and hides key functionality, or displays altogether different elements, for certain screen sizes.
Also, some sites open links in a new tab, or create popup windows in response to a user action. Creating automated tests for such sites requires switching between windows or tabs.
Resizing the browser viewport
Responsive websites adapt to the browser’s size so that they look good and work properly on a variety of devices. The viewport is what we call the section of a browser window where the actual web page content is displayed. Most responsive sites respond to the viewport size rather than the total window or screen size, so the viewport is what we adjust when we need the responsive site to look a certain way.
You can change the size of the Browser Bot’s viewport in a code block by
Once you’ve set the browser’s viewport size, it will remain the same for the remainder of that script iteration, unless you change it again.
Setting the viewport size is only relevant for Browser Bots, and won’t have any effect on Protocol Bots since they don’t have a real browser.
Switching to a different browser window or tab
Your site might open a link in a new browser tab, or it might open a popup window in response to some user action.
If you need to interact with this new window or tab, you’ll need to tell the bot to switch focus to it.
Here’s how to list the windows, get the index of the active window, focus a different window, or close a window in a code block.
// List all of the bot's browser windows/tabs browser.listWindows(); // Get the bot's currently active browser window/tab browser.getActiveWindow(); // 0, 1, 2... // Focus a different browser window/tab browser.setActiveWindow(0); // the bot's original tab browser.setActiveWindow(1); // the first opened tab browser.setActiveWindow(2); // and so on... // Close a browser window/tab browser.closeWindow(1);
We use “window” and “tab” synonymously – it doesn’t really matter from the script’s perspective whether it’s a window or a tab.