Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved switch tab test - refs #350
- Loading branch information
1 parent
26a19e1
commit ddcff69
Showing
2 changed files
with
84 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
|
||
}); | ||
}); |