-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
55 lines (43 loc) · 1.12 KB
/
index.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
module.exports = function(browser){
function simpleSelectorMethodFactory(context, method){
return function(){
return context.get()
.then(function(elem){
return elem[method]();
});
};
}
var wdMethods = ['click', 'isVisible', 'isDisplayed', 'submit', 'text', 'tap'];
var wdQuery = function( selector ){
if( !(this instanceof wdQuery) ){
return new wdQuery(selector);
}
var self = this;
wdMethods.forEach(function(method){
self[method] = simpleSelectorMethodFactory(self, method);
});
this.selector = selector;
return this;
};
wdQuery.fn = wdQuery.prototype = {
get: function(selector){
selector = selector || this.selector;
return browser.elementByCssSelector(selector);
},
val: function(value){
return this.get()
.then(function(elem){
if (value) {
elem.clear();
return elem.type(value);
}
else {
return elem.getValue();
}
});
}
};
return function(selector, context){
return new wdQuery(selector, context);
};
};