-
Notifications
You must be signed in to change notification settings - Fork 0
/
neo_helper.js
71 lines (59 loc) · 1.89 KB
/
neo_helper.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
const Helper = require('@codeceptjs/helper');
class Neo extends Helper {
// before/after hooks
/**
* @protected
*/
_before() {
// remove if not used
}
/**
* @protected
*/
_after() {
// remove if not used
}
// add custom methods here
// If you need to access other helpers
// use: this.helpers['helperName']
//I.waitTabsLoading(2, 30);
//I.changeTab(2);
//I.waitInUrl('http://lms-fatecna-nemoto.qa-os.dotgroup.com.br/avaliacao/', 10);
//I.executeScript('window.close()');
//changeTab(num) {
//let client = this.helpers['WebDriverIO'].browser;
//return client
//.getTabIds(function(err, handles) {
//this.switchTab(handles[num - 1]);
//return;
//})
//}
changeTab(num) {
let client = this.helpers['WebDriver'].browser;
return client
.getTabIds().then(function(handles) {
return this.switchTab(handles[num - 1]);
});
}
waitTabsLoading(ammountOfTabs, timeout) {
let client = this.helpers['WebDriver'].browser;
return client
.waitUntil(function() {
return this.getTabIds().then(function(handles) {
return handles.length === ammountOfTabs
});
}, timeout * 1000);
}
waitInUrl(urlPart, timeout) {
let client = this.helpers['WebDriver'].browser;
let currUrl;
return client
.waitUntil(function() {
return this.url().then(function(res) {
currUrl = res.value;
return (decodeURIComponent(decodeURIComponent(decodeURIComponent(res.value.replace(/\+/g, " "))).replace(/\+/g, " "))).indexOf(urlPart.replace(/\+/g, " ")) > -1;
});
}, timeout * 1000);
}
}
module.exports = Neo;