-
Notifications
You must be signed in to change notification settings - Fork 0
/
puppeteer-test.js
222 lines (214 loc) · 7.32 KB
/
puppeteer-test.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
218
219
220
221
222
// Recording from Chrome Recording. See https://www.youtube.com/watch?v=LBgzmqzp7ew
// Exported by Doug Horner
const puppeteer = require('puppeteer'); // v23.0.0 or later
// get the passwor from the environment, abort if not set
const password = process.env.PUPPET_PASS;
if (!password) {
console.error('PUPPET_PASS environment not set');
process.exit(1);
}
const launchOptions = { };
//const launchOptions = { headless: false, slowMo: 10, args: ['--start-maximized'] };
(async () => {
console.log('Launching browser...');
const browser = await puppeteer.launch(launchOptions);
console.log('Browser launched.');
console.log('Opening new page...');
const page = await browser.newPage();
console.log('New page opened.');
const timeout = 5000;
page.setDefaultTimeout(timeout);
{
const targetPage = page;
console.log('Setting viewport...');
await targetPage.setViewport({
width: 645,
height: 736
});
console.log('Viewport set.');
}
{
const targetPage = page;
console.log('Navigating to http://localhost:8080/...');
await targetPage.goto('http://localhost:8080/');
console.log('Navigation complete.');
}
{
const targetPage = page;
console.log('Waiting for "Get Code" button and clicking it...');
const promises = [];
const startWaitingForEvents = () => {
promises.push(targetPage.waitForNavigation());
}
await puppeteer.Locator.race([
targetPage.locator('::-p-aria(Get Code)'),
targetPage.locator('a'),
targetPage.locator('::-p-xpath(/html/body/a)'),
targetPage.locator(':scope >>> a'),
targetPage.locator('::-p-text(Get Code)')
])
.setTimeout(timeout)
.on('action', () => startWaitingForEvents())
.click({
offset: {
x: 44,
y: 13,
},
});
await Promise.all(promises);
console.log('"Get Code" button clicked.');
}
{
const targetPage = page;
console.log('Filling in username...');
await puppeteer.Locator.race([
targetPage.locator('::-p-aria(Username)'),
targetPage.locator('#login_user'),
targetPage.locator('::-p-xpath(//*[@id=\\"login_user\\"])'),
targetPage.locator(':scope >>> #login_user')
])
.setTimeout(timeout)
.fill('whart123');
console.log('Username filled.');
}
{
const targetPage = page;
console.log('Clicking "Next" button...');
await puppeteer.Locator.race([
targetPage.locator('::-p-aria(Next)'),
targetPage.locator('#login_submit'),
targetPage.locator('::-p-xpath(//*[@id=\\"login_submit\\"])'),
targetPage.locator(':scope >>> #login_submit')
])
.setTimeout(timeout)
.click({
offset: {
x: 65.5,
y: 24.296875,
},
});
console.log('"Next" button clicked.');
}
{
const targetPage = page;
console.log('Clicking password field...');
await puppeteer.Locator.race([
targetPage.locator('::-p-aria(Password)'),
targetPage.locator('#login_passwd'),
targetPage.locator('::-p-xpath(//*[@id=\\"login_passwd\\"])'),
targetPage.locator(':scope >>> #login_passwd')
])
.setTimeout(timeout)
.click({
offset: {
x: 108.5,
y: 23.796875,
},
});
console.log('Password field clicked.');
}
{
const targetPage = page;
console.log('Filling in password...');
await puppeteer.Locator.race([
targetPage.locator('::-p-aria(Password)'),
targetPage.locator('#login_passwd'),
targetPage.locator('::-p-xpath(//*[@id=\\"login_passwd\\"])'),
targetPage.locator(':scope >>> #login_passwd')
])
.setTimeout(timeout)
.fill(password);
console.log('Password filled.');
}
{
const targetPage = page;
console.log('Clicking "Next" button...');
const promises = [];
const startWaitingForEvents = () => {
promises.push(targetPage.waitForNavigation());
}
await puppeteer.Locator.race([
targetPage.locator('::-p-aria(Next)'),
targetPage.locator('#login_submit'),
targetPage.locator('::-p-xpath(//*[@id=\\"login_submit\\"])'),
targetPage.locator(':scope >>> #login_submit')
])
.setTimeout(timeout)
.on('action', () => startWaitingForEvents())
.click({
offset: {
x: 50.5,
y: 19.296875,
},
});
await Promise.all(promises);
console.log('"Next" button clicked.');
}
{
const targetPage = page;
console.log('Clicking "Scope" radio button...');
await puppeteer.Locator.race([
targetPage.locator('::-p-aria([role=\\"row\\"]) >>>> ::-p-aria([role=\\"radio\\"])'),
targetPage.locator('#pat_scope'),
targetPage.locator('::-p-xpath(//*[@id=\\"pat_scope\\"])'),
targetPage.locator(':scope >>> #pat_scope')
])
.setTimeout(timeout)
.click({
offset: {
x: 6,
y: 5.7421875,
},
});
console.log('"Scope" radio button clicked.');
}
{
const targetPage = page;
console.log('Clicking "patient/CarePlan.read" option...');
await puppeteer.Locator.race([
targetPage.locator('li:nth-of-type(8)'),
targetPage.locator('::-p-xpath(//*[@id=\\"Rf1Vl4o\\"]/li[8])'),
targetPage.locator(':scope >>> li:nth-of-type(8)'),
targetPage.locator('::-p-text(patient/CarePlan.read)')
])
.setTimeout(timeout)
.click({
offset: {
x: 269,
y: 14.0859375,
},
});
console.log('"patient/CarePlan.read" option clicked.');
}
{
const targetPage = page;
console.log('Clicking "Allow" button...');
const promises = [];
const startWaitingForEvents = () => {
promises.push(targetPage.waitForNavigation());
}
await puppeteer.Locator.race([
targetPage.locator('::-p-aria(Allow)'),
targetPage.locator('input:nth-of-type(8)'),
targetPage.locator('::-p-xpath(//*[@id=\\"wc_main\\"]/div[2]/form/input[8])'),
targetPage.locator(':scope >>> input:nth-of-type(8)'),
targetPage.locator('::-p-text(Allow)')
])
.setTimeout(timeout)
.on('action', () => startWaitingForEvents())
.click({
offset: {
x: 26.8828125,
y: 12.9296875,
},
});
await Promise.all(promises);
console.log('"Allow" button clicked.');
}
console.log('Closing browser...');
await browser.close();
console.log('Browser closed.');
})().catch(err => {
console.error(err);
process.exit(1);
});