-
Notifications
You must be signed in to change notification settings - Fork 356
Expand file tree
/
Copy pathballot.browser.js
More file actions
133 lines (112 loc) · 3.97 KB
/
ballot.browser.js
File metadata and controls
133 lines (112 loc) · 3.97 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
import { $, $$ } from '@wdio/globals';
import PageBrowser from './page.browser';
class BallotBrowser extends PageBrowser {
constructor () {
super();
this.title = 'Ballot - WeVote';
}
get getViewBallotElement () {
return $('(//button[contains(@id, "viewUpcomingBallot")])[1]');
}
get getBallotAddressLocation () {
return $$('.pac-item > span:last-child');
}
get getBallotTopElement () {
return $('#ballotTabHeaderBar');
}
get getBallotAddressElement () {
return $(' #ballotTitleBallotAddress span');
}
get getBallotModalTitleElement () {
return $('#SelectBallotModalTitleId');
}
get getBallotModalCloseElement () {
return $('#profileCloseSelectBallotModal');
}
get getBallotModalInputElement () {
return $('#entryBox');
}
get getBallotModalSaveElement () {
return $('#addressBoxModalSaveButton');
}
get getBallotModalCancelElement () {
return $('#addressBoxModalCancelButton');
}
get getBallotTitleAddress () {
return $('#ballotTitleBallotAddress span');
}
get getAutoCompleteAddressElements () {
return $$('(//div[contains(@class,"pac-item")])');
// const visibleContainer = await this.getVisibleContainer();
// if (!visibleContainer) {
// return []; // No visible container found
// }
// return await visibleContainer.$$('(//div[contains(@class,"pac-item")])');
}
get getHighlightedAutoCompleteAddressElement () {
return $('(//div[contains(@class,"pac-item") and contains(@class,"pac-item-selected")])');
}
// Find only the visible pac-container
async getVisibleContainer () {
const containers = await $$('(//div[contains(@class,"pac-container")])');
for (const container of containers) {
const isDisplayed = await container.isDisplayed();
if (isDisplayed) {
return container;
}
}
return null;
}
//Added page object for tests in product demo
async getCandidateByText(name) {
const candidateText = await $(`//button[text() = "${name}"]`);
return candidateText
}
//Added page object for tests in product demo
async clickAnyCandidate() {
await browser.pause(2000);
await browser.execute(() => {
const wrappers = Array.from(
document.querySelectorAll(`div[class*="BallotScrollingOuterWrapper"]`)
);
const allCandidates = wrappers.flatMap(wrapper =>
Array.from(wrapper.querySelectorAll(`div [class*="CandidateContainer"]`))
);
if (allCandidates.length === 0) {
console.log('No candidates found on the ballot.');
return;
}
const candidateNames = allCandidates.map(c =>
c.innerText.trim().split('\n')[0]
);
console.log('Candidates currently visible:', candidateNames);
// Pick the first (or random) candidate dynamically
const chosenIndex = Math.floor(Math.random() * allCandidates.length);
const chosenCandidate = allCandidates[chosenIndex];
chosenCandidate.scrollIntoView({ behavior: 'smooth', block: 'center' });
chosenCandidate.click();
console.log(`✅ Clicked candidate dynamically: "${candidateNames[chosenIndex]}"`);
});
}
//Added page object for tests in product demo
get candidateModalClose() {
return $('button#closeOrganizationModal');
}
//Added page object for tests in product demo
async getCandidateCardHeart () {
return $(`div [id*='cardForListBodyWrapper'] [class*='HeartFavoriteToggleContainer'] button[class*='LikeContainer']`);
}
//Added page object for tests in product demo
async getCandidateChoose() {
return $(`//div[contains(@id, 'ballotItemScrollingArea')]//button[contains(@id, 'itemActionBarSupportButton')]`);
}
//Added page object for tests in product demo
async getCandidateCardUnheart () {
return $(`div [id*='cardForListBodyWrapper'] [class*='HeartFavoriteToggleContainer'] button[class*='DislikeContainer']`);
}
//Added page object for tests in product demo
get endorsementText() {
return $('div[id^="candidateEndorsementText"]');
}
}
export default new BallotBrowser();