-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added deprecated chain + waitFor example [ci skip]
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require('colors'); | ||
var chai = require("chai"); | ||
chai.should(); | ||
|
||
var wd; | ||
try { | ||
wd = require('wd'); | ||
} catch( err ) { | ||
wd = require('../../lib/main'); | ||
} | ||
|
||
var asserters = wd.asserters; // commonly used asserters | ||
|
||
// js to add and remove a child div | ||
var appendChild = | ||
'setTimeout(function() {\n' + | ||
' $("#i_am_an_id").append("<div class=\\"child\\">a waitFor child</div>");\n' + | ||
'}, arguments[0]);\n'; | ||
|
||
var removeChildren = | ||
' $("#i_am_an_id").empty();\n'; | ||
|
||
var browser = wd.remote(); | ||
|
||
// optional extra logging | ||
browser.on('status', function(info) { | ||
console.log(info.cyan); | ||
}); | ||
browser.on('command', function(meth, path, data) { | ||
console.log(' > ' + meth.yellow, path.grey, data || ''); | ||
}); | ||
|
||
browser | ||
.chain() | ||
.init({browserName:'chrome'}) | ||
.get("http://admc.io/wd/test-pages/guinea-pig.html") | ||
.title(function(err, title) { title.should.equal('WD Tests'); }) | ||
|
||
// generic waitFor, asserter compulsary | ||
.execute(removeChildren) | ||
.execute( appendChild, [500] ) | ||
// without callback | ||
.waitFor(asserters.textInclude('a waitFor child') , 2000) | ||
// with callback | ||
.waitFor(asserters.textInclude('a waitFor child') , 2000, function(err, text) { | ||
text.should.include('waitFor'); | ||
}) | ||
|
||
// waitForElement without asserter | ||
.execute(removeChildren) | ||
.execute( appendChild, [500] ) | ||
.waitForElementByCss("#i_am_an_id .child" , 2000, function(err, el) { | ||
el.text(function(err, text) { text.should.equal('a waitFor child'); }); | ||
}) | ||
|
||
// waitForElement with element asserter | ||
.execute(removeChildren) | ||
.execute( appendChild, [500] ) | ||
.waitForElementByCss("#i_am_an_id .child", asserters.textNonEmpty , 2000, function(err, el) { | ||
el.text(function(err, text) { text.should.equal('a waitFor child'); }); | ||
}) | ||
|
||
// isDisplayed asserter | ||
.execute(removeChildren) | ||
.execute( appendChild, [500] ) | ||
.waitForElementByCss("#i_am_an_id .child", asserters.isDisplayed , 2000, function(err, el) { | ||
el.text(function(err, text) { text.should.equal('a waitFor child'); }); | ||
}) | ||
|
||
// jsCondition asserter | ||
.waitFor(asserters.jsCondition('$("#i_am_an_id .child")? true: false') , 2000, function(err, status) { | ||
status.should.be.ok; | ||
}) | ||
|
||
.sleep(2000) | ||
.quit(); | ||
|