newWindow
Overview
Use the newWindow
command to open a new window in the browser.
This command is equivalent to the window.open() function.
Note that this command will automatically switch you to the new window upon execution.
warning
The newWindow command does not work in mobile environments (!)
warning
The command might not work with devtools protocol. It also does not wait untill page load. In order to fix these problems, it is recommended to overwrite the command (on the Testplane side it would be done in version 9.0.0):
browser.overwriteCommand("newWindow", async function(pageUrl, windowName, windowFeatures) {
if (browser.isDevTools) {
const puppeteer = await browser.getPuppeteer();
await puppeteer.newPage();
} else {
await browser.newWindow("about:blank", windowName, windowFeatures);
}
await browser.url(pageUrl);
});
Usage
await browser.newWindow(url, { windowName, windowFeatures });
Command Parameters
Name | Type | Description |
url | String | The URL of the website to open. |
windowName | String | The name of the new window. |
windowFeatures | String | Settings for the new window, such as size, position, scrollbars, etc. |
Usage Examples
it("should open a new tab", async ({ browser }) => {
await browser.url("http://google.com");
console.log(await browser.getTitle());
// outputs: "Google"
await browser.newWindow(
"https://webdriver.io",
"WebdriverIO window",
"width=420,height=230,resizable,scrollbars=yes,status=1",
);
console.log(await browser.getTitle());
// outputs: "WebdriverIO · Next-gen browser and mobile automation test framework for Node.js"
await browser.closeWindow();
console.log(await browser.getTitle());
// outputs: "Google"
});
References
We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.