-
Notifications
You must be signed in to change notification settings - Fork 402
/
asserters.js
113 lines (106 loc) · 2.52 KB
/
asserters.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var _ = require('lodash');
var __slice = Array.prototype.slice;
var utils = require("./utils");
var deprecator = utils.deprecator;
function Asserter(_assert){
this.assert = _assert;
}
/**
* asserters.nonEmptyText
*
* @asserter
*/
var nonEmptyText = new Asserter(
function (target, cb) {
target.text(function(err, text) {
if(err) { return cb(err); }
var satisfied = text && _(text).trim().length > 0;
cb(null, satisfied, satisfied? text : undefined);
});
}
);
/**
* asserters.textInclude(content) -> Asserter
*
* @asserter
*/
function textInclude(content) {
return new Asserter(
function(target, cb) {
target.text(function(err, text) {
if(err) { return cb(err); }
var satisfied = text && _(text).includes(content);
cb(null, satisfied, satisfied? text : undefined);
});
}
);
}
/**
* asserters.isVisible
*
* @asserter
*/
var isDisplayed = new Asserter(
function(el,cb) {
el.isDisplayed(function(err, displayed) {
if(err) { return cb(err); }
cb(null, displayed);
});
}
);
var isVisible = new Asserter(
function() {
deprecator.warn('isVisible asserter', 'isVisible asserter has been deprecated, use isDisplayed asserter instead.');
var args = __slice.call(arguments, 0);
isDisplayed.assert.apply(this, args);
}
);
/**
* asserters.isHidden
*
* @asserter
*/
var isNotDisplayed = new Asserter(
function(el,cb) {
el.isDisplayed(function(err, displayed) {
if(err) { return cb(err); }
cb(null, !displayed);
});
}
);
var isHidden = new Asserter(
function() {
deprecator.warn('isHidden asserter', 'isHidden asserter has been deprecated, use isNotDisplayed asserter instead.');
var args = __slice.call(arguments, 0);
isNotDisplayed.assert.apply(this, args);
}
);
/**
* asserters.jsCondition(jsConditionExpr) -> Asserter
* jsConditionExpr: js script expression, should evaluate as boolean.
*
* @asserter
*/
function jsCondition(jsConditionExpr, safe) {
if(safe === undefined) { safe = false; }
return new Asserter(
function(browser, cb) {
var _eval = safe? browser.safeEval : browser.eval;
_eval.apply( browser , [jsConditionExpr, function(err, res) {
if(err) {return cb(err);}
cb(null, res, res);
}]);
}
);
}
module.exports = {
Asserter: Asserter,
nonEmptyText: nonEmptyText,
isDisplayed: isDisplayed,
isNotDisplayed: isNotDisplayed,
textInclude: textInclude,
jsCondition: jsCondition,
// deprecated
isVisible: isVisible,
isHidden: isHidden,
};