-
Notifications
You must be signed in to change notification settings - Fork 402
/
Copy pathwait-for-simple.js
64 lines (51 loc) · 1.79 KB
/
wait-for-simple.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
var wd;
try {
wd = require('wd');
} catch( err ) {
wd = require('../../lib/main');
}
var asserters = wd.asserters; // commonly used asserters
// enables chai assertion chaining
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
// 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.promiseChainRemote();
browser
.init({browserName:'chrome'})
.get("http://admc.io/wd/test-pages/guinea-pig.html")
.title().should.become('WD Tests')
// generic waitFor, asserter compulsary
.execute(removeChildren)
.execute( appendChild, [500] )
.waitFor(asserters.textInclude('a waitFor child') , 2000)
.should.eventually.include('a waitFor child')
// waitForElement without asserter
.execute(removeChildren)
.execute( appendChild, [500] )
.waitForElementByCss("#i_am_an_id .child" , 2000)
.text().should.become('a waitFor child')
// waitForElement with element asserter
.execute(removeChildren)
.execute( appendChild, [500] )
.waitForElementByCss("#i_am_an_id .child", asserters.textNonEmpty , 2000)
.text().should.become('a waitFor child')
// isDisplayed asserter
.execute(removeChildren)
.execute( appendChild, [500] )
.waitForElementByCss("#i_am_an_id .child", asserters.isDisplayed , 2000)
.text().should.become('a waitFor child')
// jsCondition asserter
.waitFor(asserters.jsCondition('$("#i_am_an_id .child")? true: false') , 2000)
.should.eventually.be.ok
.fin(function() { return browser.quit(); })
.done();