Skip to content

Commit

Permalink
improved switch tab test - refs #350
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Jan 7, 2015
1 parent 26a19e1 commit ddcff69
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 19 deletions.
2 changes: 2 additions & 0 deletions lib/commands/newWindow.js
Expand Up @@ -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.
*
* <example>
:newWindow.js
client
Expand Down
101 changes: 82 additions & 19 deletions 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);
});

});
});

0 comments on commit ddcff69

Please sign in to comment.