forked from fossasia/open-event-wsgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trackPage.js
178 lines (146 loc) · 5.56 KB
/
trackPage.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
var BasePage = require('./basePage.js');
var By = require('selenium-webdriver').By;
var until = require('selenium-webdriver').until;
var TrackPage = Object.create(BasePage);
// Get number of visible tracks on the page
TrackPage.getNumTracksVisible = function() {
var self = this;
var numPromise = new Promise(function(resolve) {
self.findAll(By.className('track-filter')).then(function(trackElems) {
var counter = 0;
var trackNameArr = [];
trackElems.forEach(function(trackElem) {
trackElem.isDisplayed().then(function(val) {
trackElem.findElement(By.className('text')).getText().then(function(name) {
if (val && trackNameArr.indexOf(name) === -1) {
trackNameArr.push(name);
}
counter += 1;
if (counter === trackElems.length) {
resolve(trackNameArr.length);
}
});
});
});
});
});
return numPromise;
};
TrackPage.checkIsolatedBookmark = function() {
// Sample sessions having ids of 3014 and 3015 being checked for the bookmark feature
var self = this;
var bookmarkSessionsIdsArr = ['3014', '3015', '2907'];
var visibleCheckSessionsIdsArr = ['3014', '3015', '2918', '2907'];
return self.bookmarkCheck(bookmarkSessionsIdsArr, visibleCheckSessionsIdsArr);
};
// Clicks on the Open Tech Track and then returns the number of visible tracks present on the page
TrackPage.checkIsolatedTrackFilter = function() {
var self = this;
return self.find(By.className('track-room-names')).findElements(By.className('track-name')).then(function(elems) {
// Clicking on the Open Tech Track
return elems[16].click().then(self.getNumTracksVisible.bind(self));
});
};
TrackPage.toggleSessionElem = function() {
var self = this;
// Checking the toggle behaviour of session having id 3014
var promise = new Promise(function(resolve) {
self.find(By.id('title-3014')).then(self.click).then(self.driver.sleep(1000)).then(function() {
var promiseArr = [];
promiseArr.push(self.find(By.id('desc-3014')).isDisplayed());
promiseArr.push(self.find(By.id('desc2-3014')).isDisplayed());
resolve(Promise.all(promiseArr));
});
});
return promise;
};
/* Below is the list of selected sessions which are to be tested for visiblity. Sessions having ids 3014, 3015, 3018, 2938 are
of Open Tech Track. The former two are in bookmarked state. Session id 2907 is of Track Hardware and Making and the last session
with id 2941 is of Database Track. */
var idArr = ['3014', '3015', '3018', '2938', '2907', '2941'];
// Get the visibility status of the selected sessions on enabling and disabling the track filter.
TrackPage.filterThenSessionStatus = function(choice) {
var self = this;
var promiseArr = idArr.map(function(elem) {
return self.find(By.id(elem));
});
var statusPromise = new Promise(function(resolve) {
if (choice === 'true') {
// Applying track filter
self.find(By.className('track-room-names')).findElements(By.className('track-name')).then(function(elems) {
// Clicking on the Open Tech Track
elems[16].click().then(self.getElemsDisplayStatus.bind(null, promiseArr)).then(function(ans) {
self.driver.sleep(1000).then(function() {
resolve(ans);
});
});
});
} else {
// Removing applied track filter
self.find(By.id('clearFilter')).click().then(self.getElemsDisplayStatus.bind(null, promiseArr)).then(function(ans) {
self.driver.sleep(1000).then(function() {
resolve(ans);
});
});
}
});
return statusPromise;
};
// Get the visibility status of the selected sessions after search
TrackPage.searchThenSessionStatus = function(text) {
var self = this;
var promiseArr = idArr.map(function(elem) {
return self.find(By.id(elem));
});
return self.resetSearchBar().then(self.search.bind(self, text)).then(self.getElemsDisplayStatus.bind(null, promiseArr));
};
// Get the visibility status of the selected sessions after toggling the bookmark button
TrackPage.starredThenSessionStatus = function() {
var self = this;
var promiseArr = idArr.map(function(elem) {
return self.find(By.id(elem));
});
return self.toggleStarredButton().then(self.getElemsDisplayStatus.bind(null, promiseArr));
};
// Takes in an array of filters, apply them sequentially and send visibility results of selected sessions on each filter
TrackPage.filterCombination = function(filtersArr) {
var self = this;
var filterObjectFunc = {
'trackselect': function() {
return self.filterThenSessionStatus('true');
},
'trackunselect': function() {
return self.filterThenSessionStatus('false');
},
'search': function() {
return self.searchThenSessionStatus('wel');
},
'unsearch': function() {
return self.searchThenSessionStatus('');
},
'starred': function() {
return self.starredThenSessionStatus();
},
'unstarred': function() {
return self.starredThenSessionStatus();
}
};
var serialPromise = function series(arrayOfPromises) {
var results = [];
return arrayOfPromises.reduce(function(seriesPromise, promise) {
return seriesPromise.then(function() {
return promise.then(function(result) {
results.push(result);
});
});
}, Promise.resolve()).then(function() {
return results;
});
};
var filtersArrProm = [];
filtersArrProm = filtersArr.map(function(filter) {
return filterObjectFunc[filter]();
});
return serialPromise(filtersArrProm);
};
module.exports = TrackPage;