From ddcff69d2933d5cc41a0aa9cfb8aa56f9485896d Mon Sep 17 00:00:00 2001 From: christian-bromann Date: Wed, 7 Jan 2015 03:36:09 +0100 Subject: [PATCH] improved switch tab test - refs #350 --- lib/commands/newWindow.js | 2 + test/spec/desktop/switchTab.js | 101 ++++++++++++++++++++++++++------- 2 files changed, 84 insertions(+), 19 deletions(-) diff --git a/lib/commands/newWindow.js b/lib/commands/newWindow.js index 6520f369fd8..d438ae02581 100644 --- a/lib/commands/newWindow.js +++ b/lib/commands/newWindow.js @@ -3,6 +3,8 @@ * Open new window in browser. This command is the equivalent function to `window.open()`. This command does not * work in mobile environments. * + * __Note:__ When calling this command you automatically switch to the new window. + * * :newWindow.js client diff --git a/test/spec/desktop/switchTab.js b/test/spec/desktop/switchTab.js index 79b32049077..0fe782db24b 100644 --- a/test/spec/desktop/switchTab.js +++ b/test/spec/desktop/switchTab.js @@ -1,31 +1,94 @@ describe('switchTab', function() { before(h.setup()); - it('should switch to an other tab', function(done) { + describe('should switch tabs', function() { - var openedTabs = []; + var openedTabs = [], + myTab, newTab; - this.client + it('by getting the current tab id first', function(done) { - // get current tab id - .getTabIds(function(err, tabs) { - assert.ifError(err); - openedTabs = tabs; - }) + this.client + // get current tab id + .getCurrentTabId(function(err, tab) { + myTab = tab; + }) + .call(done); - // open new tab and switch window - .newWindow(conf.testPage.subPage) + }); - // ensure that there are two tabs open - .switchTab(openedTabs[0]) + it('then by creating new windows', function(done) { - // fetch the current window handle - .windowHandle(function(err, res) { - assert.ifError(err); - openedTabs[0].should.be.exactly(res.value); - }) - .close() - .call(done); + this.client + // create a bunch of tabs/windows + .newWindow(conf.testPage.subPage) + .newWindow(conf.testPage.subPage) + .newWindow(conf.testPage.subPage) + .call(done); + + }); + + it('then should have a new tab id', function(done) { + + this.client + // check new tab id + .getCurrentTabId(function(err, res) { + assert.ifError(err); + res.should.not.be.exactly(myTab); + newTab = res; + }) + .call(done); + + }); + + it('then by changing to one of the new created window handles', function(done) { + + var self = this; + this.client + // check if tab id has changed + .getTabIds(function(err, res) { + openedTabs = res; + + assert.ifError(err); + newTab.should.be.exactly(openedTabs[openedTabs.length - 1]); + + // switch tab to another tab + // IMPORTANT this always needs to be done in a callback + self.client.switchTab(openedTabs[2]) + }) + .call(done); + + }); + + it('it then should have the desired new tab id', function(done) { + + var self = this; + this.client + .getCurrentTabId(function(err, res) { + assert.ifError(err); + openedTabs[2].should.be.exactly(res); + + // get back to old tab + self.client.switchTab(myTab); + }) + .call(done); + + }); + + /** + * clean up that tab mess ^^ + */ + after(function(done) { + var self = this; + this.client + .call(function() { + self.client + .close(openedTabs[1]) + .close(openedTabs[2]) + .close(openedTabs[3]); + }) + .call(done); + }); }); }); \ No newline at end of file