-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
91 lines (67 loc) · 1.99 KB
/
utils.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
module.exports.CONSTS = {
dummyAccount: {
login: 'VRTB2155',
password: 'mRX1E3Mi00oS8LG'
}
}
module.exports.randomStr = function (length, initChars) {
var chars = initChars || 'abcdefghijklmnopqrstuvwxyz123456789',
str = '';
for (var i = length; i > 0; --i) {
str += chars[Math.round(Math.random() * (chars.length - 1))];
}
return str;
};
module.exports.randomEmail = function (length, initChars) {
var chars = initChars || 'abcdefghijklmnopqrstuvwxyz123456789',
str = '';
for (var i = length; i > 0; --i) {
str += chars[Math.round(Math.random() * (chars.length - 1))];
}
var email = 'binarytest-' + str + '@mailinator.com';
return email;
};
module.exports.getSign = function(str) {
return /^\+?(0|[1-9]\d*)$/.test(str);
}
function urlExists(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
callback(xhr.status < 400);
}
};
xhr.open('HEAD', url);
xhr.send();
};
module.exports.openUrlsOld = function (browser, urls) {
urls.forEach(function (url) {
var visitUrl = browser.launch_url + url;
browser
.url(visitUrl, function () {
console.log("Opening ", visitUrl);
})
.waitForElementVisible('body', 5000)
.pause(2000);
});
browser.end();
};
module.exports.smokeTestUrls = function (urls, domain) {
var testSteps = {};
urls.forEach(function (url) {
var testName = 'Smoke test: "' + url.page + '"';
testSteps[testName] = function (browser) {
var visitUrl = (domain || browser.launch_url) + url.path;
browser
.url(visitUrl)
.waitForElementVisible('body', 5000)
.pause(5000)
.verify.noJsErrors()
.end();
};
});
testSteps.end = function (browser) {
browser.end();
};
return testSteps;
};