-
Notifications
You must be signed in to change notification settings - Fork 402
/
add-method-async.js
56 lines (49 loc) · 1.67 KB
/
add-method-async.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
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');
}
// enables chai assertion chaining
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
wd.addAsyncMethod(
'elementByCssSelectorWhenReady',
function(selector, timeout/*, cb*/) {
// 'wd.findCallback' is a small helper which looks for the callback in a safe way, and avoids
// hanging when the number of arguments passed is wrong.
// There is also a 'wd.varargs' for methods with variable argument number.
var cb = wd.findCallback(arguments);
var _this = this;
this.waitForElementByCssSelector(selector, timeout, function() {
_this.elementByCssSelector(selector, cb);
});
}
);
var browser = wd.promiseChainRemote();
// optional extra logging
browser.on('status', function(info) {
console.log(info.cyan);
});
browser.on('command', function(eventType, command, response) {
console.log(' > ' + eventType.cyan, command, (response || '').grey);
});
browser.on('http', function(meth, path, data) {
console.log(' > ' + meth.magenta, path, (data || '').grey);
});
browser
.init({browserName:'chrome'})
.get("http://admc.io/wd/test-pages/guinea-pig.html")
.title()
.should.become('WD Tests')
.elementByCssSelector('#comments').getTagName().should.become('textarea')
.elementByCssSelectorWhenReady('#comments', 2000)
// .should.eventually.exist
// .elementByCssSelectorWhenReady('#comments', 2000)
// .type('Bonjour!').getValue().should.become('Bonjour!')
.fin(function() { return browser.quit(); })
.done();