-
Notifications
You must be signed in to change notification settings - Fork 356
Expand file tree
/
Copy pathfaq.browser.js
More file actions
272 lines (216 loc) · 7.63 KB
/
faq.browser.js
File metadata and controls
272 lines (216 loc) · 7.63 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
import { $, $$, driver } from '@wdio/globals';
import PageBrowser from './page.browser';
class FaqBrowser extends PageBrowser {
constructor () {
super().title = 'FAQ - WeVote';
}
async load () {
await super.open('/more/faq');
}
get getFAQPageTitleElement () {
return $('.kkIyuQ');
}
get getTwitterIconElement () {
return $('#weVoteTwitter');
}
get getFacebookIconElement () {
return $('#weVoteFacebook');
}
get getInstagramIconElement () {
return $('#weVoteInstagram');
}
get getWeVoteElementFromInstagram () {
return $('//h2[contains(text(), "wevote")]');
}
get getEmailIconElement () {
return $('#eepurl');
}
get getAllPdfLinks () {
return $$('a[href*="pdf"]'); // a[contains(@href, ".pdf")]
}
get getGitHubIconElement () {
return $$('//a[@href = "https://github.com/WeVote"]');
}
get getBlogIconElement () {
return $('#weVoteBlog');
}
get getValueLinkElement () {
return $$('//a[@id = "helpSiteValues"]');
}
async clickValueLink () {
const selectorToGetValueElements = '//a[@id = "helpSiteValues"]';
const arrOfElements = [];
for (let i = 1; i <= selectorToGetValueElements.length; i++) {
$(`(${selectorToGetValueElements})[${i}]`).click();
const windowHandles = driver.getWindowHandles();
await driver.switchToWindow(windowHandles[1]);
const textFromElement = driver.getTitle();
arrOfElements.push(textFromElement);
// await driver.switchWindow('https://quality.wevote.us/more/faq');
}
return arrOfElements;
}
get getWeVoteEducationWebsiteElement () {
return $('#weVoteEducationWebsite');
}
get getWeVoteUSAWebsiteElement () {
return $('#weVoteUSAWebsite');
}
get getWeVoteVolunteerElements () {
return $$('a[href*="applytojob"]');
}
async clickVolunteerOpeningsLinks () {
// const selectorToGetElements = '//a[@href = "https://wevote.applytojob.com/apply"]';
const selectorToGetElements = await this.getWeVoteVolunteerElements;
const arrOfElements = [];
for (let i = 0; i < selectorToGetElements.length; i++) {
const element = selectorToGetElements[i];
await element.click(); // <-- await is important
await driver.waitUntil(
async () => (await driver.getWindowHandles()).length > 1,
{ timeout: 30000 },
);
// const handles = await driver.getWindowHandles();
// await driver.switchWindow(handles[handles.length - 1]); // Switch to the most recently opened window
await driver.switchWindow('https://wevote.applytojob.com/apply');
await driver.waitUntil(
async () => (await driver.getTitle()).length > 0,
{ timeout: 30000, timeoutMsg: 'Title not loaded' },
);
const textFromElement = await driver.getTitle();
arrOfElements.push(textFromElement);
await driver.switchWindow('https://quality.wevote.us/more/faq');
}
return arrOfElements;
}
get getAboutPageElement () {
return $('//span[text()="volunteer board members"]');
}
get clickTitokIconElement () {
return $('button[aria-label="TikTok"]');
}
get clickTwitterIconElement () {
return $('#weVoteTwitter');
}
get getWeVoteContactUsFormElement () {
return $('#weVoteContactUsPage');
}
get getWeVoteIPhoneLinkElement () {
return $('#weVoteIPhone');
}
get getWeVoteAndroidLinkElement () {
return $('#weVoteAndroid');
}
get getPleaseDonateElement () {
return $('[href="/donate"]');
}
get getVolunteerElement () {
return $('#idealistOpenPositions');
}
get getLetsGetStartedElement () {
return $('//span[normalize-space()="Let\'s get started!"]');
}
get allFAQLinks () {
return $$('a[href^="https"]');
}
get weVoteText () {
return $('//div[@data-testid="UserName"]//span[text()="WeVote"]');
}
async waitForURL (expectedURL) {
// wait for title
await driver.waitUntil(
async () => (await driver.getTitle()).length > 0,
{ timeout: 20000, timeoutMsg: 'Title not loaded' },
);
// wait for new window
await driver.waitUntil(
async () => (await driver.getWindowHandles()).length > 1,
{ timeout: 30000, timeoutMsg: 'New window did not open' },
);
// 2️⃣ switch to new window
// const handles = await driver.getWindowHandles();
await driver.switchWindow(expectedURL);
// 3️⃣ wait for URL (partial match)
await driver.waitUntil(
async () => (await driver.getUrl()).includes(expectedURL),
{ timeout: 40000, timeoutMsg: 'Expected URL not found' },
);
// await driver.waitUntil(async () => {
// (await driver.getWindowHandles()).length > 1,
// await driver.switchWindow(expectedURL);
// (await driver.getTitle()).length > 0;
// const currenturl = await driver.getUrl();
// return currenturl === expectedURL;
// }, {
// timeout: 40000,
// timeoutMsg: 'Expected URL not found',
// });
}
async clickGitHubIconAndLinks () {
const selectorToGetElements = await this.getGitHubIconElement;
const arrOfElements = [];
console.log(`Github length is ${selectorToGetElements.length}`);
for (let i = 0; i < selectorToGetElements.length; i++) {
const element = selectorToGetElements[i];
await element.click(); // <-- await is important
// ✅ wait for title to be available
// await driver.waitUntil(async () => (await driver.getUrl()).includes('github'), { timeout: 10000, timeoutMsg: 'URL did not change to GitHub' });
await driver.waitUntil(
async () => (await driver.getWindowHandles()).length > 1,
{ timeout: 30000 },
);
// const handles = await driver.getWindowHandles();
// await driver.switchWindow(handles[handles.length - 1]); // Switch to the most recently opened window
await driver.switchWindow('https://github.com/WeVote');
console.log(`Current URL after clicking GitHub icon: ${await driver.getUrl()}`);
await driver.waitUntil(
async () => (await driver.getTitle()).length > 0,
{ timeout: 50000, timeoutMsg: 'Url not found' },
);
const title = await driver.getTitle();
arrOfElements.push(title);
await driver.switchWindow('https://quality.wevote.us/more/faq');
}
console.log(arrOfElements);
return arrOfElements;
}
// async getAllFaqPageLinks () {
// // Use the WDIO-specific .map() directly on the selector
// // This handles the 'iterability' internally and is much faster
// const allLinks = await this.allFAQLinks.map(async (link) => {
// try {
// const href = await link.getAttribute('href');
// return (href && href.startsWith('http')) ? href : null;
// } catch (e) {
// throw new Error(`Error retrieving link: ${e.message}`);
// // Handle stale elements or missing attributes
// }
// });
// // filter(Boolean) removes nulls; New Set removes duplicates
// return [...new Set(allLinks.filter(Boolean))];
// }
async getAllFaqPageLinks () {
await driver.waitUntil(
// @ts-ignore
async () => (await this.allFAQLinks).length > 0,
{
timeout: 10000,
timeoutMsg: 'FAQ links did not load',
},
);
const links = await this.allFAQLinks;
const results = [];
for (const link of links) {
const href = await link.getAttribute('href');
if (href.startsWith('https')) {
results.push(href);
}
}
console.log(`Faq links length is ${results.length}`);
console.log(`All Faq links are ${results}`);
return [...new Set(results)];
}
}
export default new FaqBrowser();