-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy pathopen-addon.js
217 lines (186 loc) · 6.17 KB
/
open-addon.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
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
export const openAddon = async (page) => {
await page.goto(process.env.SHEET_URL);
await page.waitForSelector('a[aria-label="Sign in"]');
// Create directory for screenshots if it doesn't exist
const fs = await import('fs');
const path = await import('path');
const screenshotDir = 'test/__image_snapshots__/__diff_output__';
if (!fs.existsSync(screenshotDir)) {
fs.mkdirSync(screenshotDir, { recursive: true });
}
// take screenshot
await page.screenshot({
path: path.join(
screenshotDir,
`1-main-spreadsheet-before-signin-${Date.now()}.png`
),
});
await page.click('a[aria-label="Sign in"]'); // click on signin button
// take screenshot
await page.screenshot({
path: path.join(screenshotDir, `2-signin-page-${Date.now()}.png`),
});
await page.waitForSelector('input[name="identifier"]', { visible: true });
await page.type('input[name="identifier"]', process.env.EMAIL); // type email
// take screenshot after entering email
await page.screenshot({
path: path.join(screenshotDir, `3-email-entered-${Date.now()}.png`),
});
await page.click('#identifierNext'); // click "next" button
await page.waitForSelector('input[name="Passwd"]', { visible: true });
await page.type('input[name="Passwd"]', process.env.PASSWORD); // type pass
// take screenshot after entering password
await page.screenshot({
path: path.join(screenshotDir, `4-password-entered-${Date.now()}.png`),
});
await page.waitForTimeout(500);
await page.click('#passwordNext'); // click "next" button
await page.waitForTimeout(3000);
// take screenshot after login attempt
await page.screenshot({
path: path.join(screenshotDir, `5-after-login-attempt-${Date.now()}.png`),
});
if (
await page.evaluate(
() =>
document.querySelector('h1#headingText') &&
document.querySelector('h1#headingText').innerText.includes('erify')
)
) {
// take screenshot of verification page
await page.screenshot({
path: path.join(screenshotDir, `6-verification-needed-${Date.now()}.png`),
});
try {
await page.click('li:nth-child(3)');
await page.waitForTimeout(6000);
// take screenshot after selecting verification method
await page.screenshot({
path: path.join(
screenshotDir,
`7-verification-method-selected-${Date.now()}.png`
),
});
} catch {
// eslint-disable-next-line no-console
console.log('The "choose account recovery method" page isn\'t shown');
}
await page.type(
'input[name="knowledgePreregisteredEmailResponse"]',
process.env.TEST_RECOVERY_EMAIL
); // type recovery email
// take screenshot after entering recovery email
await page.screenshot({
path: path.join(
screenshotDir,
`8-recovery-email-entered-${Date.now()}.png`
),
});
await page.waitForTimeout(6000);
await page.click('div[data-primary-action-label] button'); // click "next" button
await page.waitForTimeout(5000);
// take screenshot after verification completed
await page.screenshot({
path: path.join(
screenshotDir,
`9-verification-completed-${Date.now()}.png`
),
});
}
if (
await page.evaluate(
() =>
document.querySelector('h1#headingText') &&
document
.querySelector('h1#headingText')
.innerText.includes('implify your sign')
)
) {
// take screenshot of simplify sign-in page
await page.screenshot({
path: path.join(
screenshotDir,
`10-simplify-signin-page-${Date.now()}.png`
),
});
try {
await page.click(
'div[data-secondary-action-label] > div > div:nth-child(2) button'
);
await page.waitForTimeout(6000);
// take screenshot after dismissing simplify sign-in
await page.screenshot({
path: path.join(
screenshotDir,
`11-after-dismissing-simplify-signin-${Date.now()}.png`
),
});
} catch {
// eslint-disable-next-line no-console
console.log('The "Simplify your sign-in" page isn\'t shown');
}
}
await page.waitForSelector(
'div.menu-button.goog-control.goog-inline-block:nth-child(10)',
{ visible: true }
);
// take screenshot before opening addon menu
await page.screenshot({
path: path.join(
screenshotDir,
`12-before-opening-addon-menu-${Date.now()}.png`
),
});
// open new addon menubar item
await page.evaluate(() => {
const addOnMenuButton = document.querySelector(
'div.menu-button.goog-control.goog-inline-block:nth-child(10)'
);
addOnMenuButton.dispatchEvent(
new MouseEvent('mousedown', { bubbles: true })
);
addOnMenuButton.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
});
await page.waitForSelector(
'div.goog-menu.goog-menu-vertical.apps-menu-hide-mnemonics:last-child > div:nth-child(2) > div',
{ visible: true }
);
// take screenshot with addon menu opened
await page.screenshot({
path: path.join(screenshotDir, `13-addon-menu-opened-${Date.now()}.png`),
});
// open "bootstrap" menu item
await page.evaluate(() => {
const bootstrapMenuButton = document.querySelector(
'div.goog-menu.goog-menu-vertical.apps-menu-hide-mnemonics:last-child > div:nth-child(2) > div'
);
bootstrapMenuButton.dispatchEvent(
new MouseEvent('mousedown', { bubbles: true })
);
bootstrapMenuButton.dispatchEvent(
new MouseEvent('mouseup', { bubbles: true })
);
bootstrapMenuButton.dispatchEvent(
new MouseEvent('mousedown', { bubbles: true })
);
bootstrapMenuButton.dispatchEvent(
new MouseEvent('mouseup', { bubbles: true })
);
});
await page.waitForSelector('div[role="dialog"]', {
visible: true,
timeout: 10000,
});
// take screenshot after clicking bootstrap menu item
await page.screenshot({
path: path.join(
screenshotDir,
`14-bootstrap-dialog-opened-${Date.now()}.png`
),
});
await page.waitForTimeout(15000);
// take final screenshot after waiting period
await page.screenshot({
path: path.join(screenshotDir, `15-addon-fully-loaded-${Date.now()}.png`),
});
};