Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiply tabs are not switching and closing wrong one #350

Closed
ghost opened this issue Nov 17, 2014 · 3 comments
Closed

multiply tabs are not switching and closing wrong one #350

ghost opened this issue Nov 17, 2014 · 3 comments

Comments

@ghost
Copy link

ghost commented Nov 17, 2014

Hello!
I have a page with 4 links, which I'm opening one by one. The links are really heavy and it takes a lot of time to load them fully. After opening links I look for there ids

.getTabIds(function(err,response){ gtabIDs=response; console.log(gtabIDs);})

and try to switch to another tab

.switchTab(gtabIDs[1])

but it's impossible to switch to them, i'm always on my current tab, I checked with something like (is it dependant on a tab is loaded or not?)

.getCurrentTabId(function(err,response){console.log(response);})

The other problem is I can't close tab with .close(gtabIDs[1]) , because the only closing tab is current one

So the questions are:

  1. Am I switching tabs wrong?
  2. Am I closing tabs in a wrong way?

PS I'm using mocha & chrome

@ghost ghost changed the title tab issue multiply tabs are not switching and closing wrong one Nov 17, 2014
@ghost
Copy link
Author

ghost commented Dec 19, 2014

Just updated to 2.4.0 and nothing changed, switchTab is not working :( PS tab is a global var and I have 4 tabs opened in test before, latest Chrome.

            client
                .getTabIds(function(err,response) {
                    tabs = response.slice(0);
                    console.log('All tabs: ' + tabs);
                })
                .getCurrentTabId(function(err,response) {
                    console.log('My tab: ' + response);
                })
                .switchTab(tabs[1])
                .getCurrentTabId(function(err,response) {
                    console.log('My tab: ' + response);
                    console.log('All tabs: ' + tabs);
                })

I get:

All tabs: CDwindow-5E7FE6C3-BC8F-4D7C-8F46-29DB9A2FCB01,CDwindow-55D008EE-A26B-494B-A923-96E39EB63472,CDwindow-3B02516B-AB48-47B8-BB7E-2780295E3EE2,CDwindow-107A2784-74E1-4950-994A-AB7C99512F1C,CDwindow-37D1E112-5717-44DB-A37C-11621030BA40

My tab: CDwindow-5E7FE6C3-BC8F-4D7C-8F46-29DB9A2FCB01

My tab: CDwindow-5E7FE6C3-BC8F-4D7C-8F46-29DB9A2FCB01

All tabs: CDwindow-5E7FE6C3-BC8F-4D7C-8F46-29DB9A2FCB01,CDwindow-55D008EE-A26B-494B-A923-96E39EB63472,CDwindow-3B02516B-AB48-47B8-BB7E-2780295E3EE2,CDwindow-107A2784-74E1-4950-994A-AB7C99512F1C,CDwindow-37D1E112-5717-44DB-A37C-11621030BA40

So it's not really related to close(), because it's behaving correctly, but to switchTab() which is not working.

@christian-bromann
Copy link
Member

Haha. I now see the problem, make that mistake also every time. switchTab doesn't work because the variable tabs[1] is undefined in that moment you call that command. The variable tabs gets changed in the callback that gets executed after WebdriverIO put switchTab in its command queue. That's the burden of asynchronicity ;-)

@ghost
Copy link
Author

ghost commented Jan 7, 2015

Oh, now I got it, it's was not so obvious and I forgetting it every time. So the goal should be in switchTab() inside the callback of getCurrentTabId or getTabIds() ? Or is there any more elegant way to do it?

UPDATED
ok in fact I did something like that, thx 👍

   client.getTabIds(function(err,response) {
      var allTabs = response.slice(0);
      // Assert we have {number of opened tabs} + 1 (current) tabs
      assert.equal(allTabs.length, elements_cnt + 1, 'should be four new opened tabs');
      //Close newly opened tabs except new one
      for(var idx=1; idx<allTabs.length; idx++) {
         this.switchTab(allTabs[idx]).close();
      }
      });
   })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant