webdriverio
Version:
Next-gen browser and mobile automation test framework for Node.js
31 lines (23 loc) • 770 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = switchWindow;
async function switchWindow(urlOrTitleToMatch) {
if (typeof urlOrTitleToMatch !== 'string' && !(urlOrTitleToMatch instanceof RegExp)) {
throw new Error('Unsupported parameter for switchWindow, required is "string" or an RegExp');
}
const tabs = await this.getWindowHandles();
for (const tab of tabs) {
await this.switchToWindow(tab);
const url = await this.getUrl();
if (url.match(urlOrTitleToMatch)) {
return tab;
}
const title = await this.getTitle();
if (title.match(urlOrTitleToMatch)) {
return tab;
}
}
throw new Error(`No window found with title or url matching "${urlOrTitleToMatch}"`);
}