CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

How do i switch tabs or windows?

Open ecampii opened this issue 10 years ago • 6 comments

Is there a way to detect tabs or windows and switch to it?

ecampii avatar Aug 11 '16 04:08 ecampii

You can write custom helpers for now. Below is e.g. for WebDriverIO

/**
    waitTabsLoading(ammountOfTabs, timeout) {
        timeout = timeout || 15;
        let client = this.helpers['Appium'].browser;
        return client
            .waitUntil(function () {
                return this.getTabIds().then(function (handles) {
                    return handles.length === ammountOfTabs
                });
            }, timeout * 1000, "The number of tabs hasn't changed to " + ammountOfTabs);
    }

    changeTab(num) {
        let client = this.helpers['Appium'].browser;
        return client
            .getTabIds().then(function (handles) {
                return this.switchTab(handles[num - 1]);
            });
    }

I'll add them to basic metods for WebdriverIO

APshenkin avatar Jun 01 '17 08:06 APshenkin

https://github.com/Codeception/CodeceptJS/pull/606

APshenkin avatar Jul 18 '17 11:07 APshenkin

@APshenkin - You said this example was for for webdriverio, but the code it using Appium. When I change your code to use webdriverio, I get this error: "Error: Session ID is null. Using WebDriver after calling quit()?"

patmeeker avatar Aug 30 '17 17:08 patmeeker

@patmeeker there is default methods in codeceptjs for this now. Please update codeceptJS to 1.0.2 and check documentation: http://codecept.io/helpers/WebDriverIO/#switchtonexttab

APshenkin avatar Aug 30 '17 19:08 APshenkin

Got it! Thanks!

patmeeker avatar Aug 31 '17 04:08 patmeeker

Dead link: check documentation: http://codecept.io/helpers/WebDriverIO/#switchtonexttab

BobRay avatar Jan 23 '20 16:01 BobRay