testaro 30.0.4 → 30.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/procs/nav.js +9 -13
- package/run.js +28 -17
- package/watch.js +8 -7
package/package.json
CHANGED
package/procs/nav.js
CHANGED
|
@@ -119,7 +119,6 @@ const goTo = async (report, page, url, timeout, waitUntil) => {
|
|
|
119
119
|
// Closes the current browser.
|
|
120
120
|
const browserClose = async () => {
|
|
121
121
|
if (browser) {
|
|
122
|
-
const browserType = browser.browserType().name();
|
|
123
122
|
let contexts = browser.contexts();
|
|
124
123
|
for (const context of contexts) {
|
|
125
124
|
await context.close();
|
|
@@ -129,7 +128,7 @@ const browserClose = async () => {
|
|
|
129
128
|
browser = null;
|
|
130
129
|
}
|
|
131
130
|
};
|
|
132
|
-
// Launches a browser, navigates to a URL, and returns
|
|
131
|
+
// Launches a browser, navigates to a URL, and returns browser data.
|
|
133
132
|
const launch = async (report, typeName, url, debug, waits, isLowMotion = false) => {
|
|
134
133
|
// If the specified browser type exists:
|
|
135
134
|
const browserType = playwright[typeName];
|
|
@@ -152,7 +151,6 @@ const launch = async (report, typeName, url, debug, waits, isLowMotion = false)
|
|
|
152
151
|
browser = await browserType.launch(browserOptions)
|
|
153
152
|
// If the launch failed:
|
|
154
153
|
.catch(async error => {
|
|
155
|
-
healthy = false;
|
|
156
154
|
console.log(`ERROR launching browser (${error.message.slice(0, 200)})`);
|
|
157
155
|
// Return this.
|
|
158
156
|
return {
|
|
@@ -162,11 +160,9 @@ const launch = async (report, typeName, url, debug, waits, isLowMotion = false)
|
|
|
162
160
|
});
|
|
163
161
|
// Open a context (i.e. browser tab), with reduced motion if specified.
|
|
164
162
|
const options = {reduceMotion: isLowMotion ? 'reduce' : 'no-preference'};
|
|
165
|
-
browserContext = await browser.newContext(options);
|
|
163
|
+
const browserContext = await browser.newContext(options);
|
|
166
164
|
// When a page (i.e. browser tab) is added to the browser context (i.e. browser window):
|
|
167
165
|
browserContext.on('page', async page => {
|
|
168
|
-
// Make the page current.
|
|
169
|
-
currentPage = page;
|
|
170
166
|
// If it emits a message:
|
|
171
167
|
page.on('console', msg => {
|
|
172
168
|
const msgText = msg.text();
|
|
@@ -210,22 +206,22 @@ const launch = async (report, typeName, url, debug, waits, isLowMotion = false)
|
|
|
210
206
|
});
|
|
211
207
|
});
|
|
212
208
|
// Open the first page of the context.
|
|
213
|
-
|
|
209
|
+
const page = await browserContext.newPage();
|
|
214
210
|
try {
|
|
215
211
|
// Wait until it is stable.
|
|
216
|
-
await
|
|
212
|
+
await page.waitForLoadState('domcontentloaded', {timeout: 5000});
|
|
217
213
|
// Navigate to the specified URL.
|
|
218
|
-
const navResult = await goTo(report,
|
|
214
|
+
const navResult = await goTo(report, page, url, 15000, 'domcontentloaded');
|
|
219
215
|
// If the navigation succeeded:
|
|
220
216
|
if (navResult.success) {
|
|
221
217
|
// Update the name of the current browser type and store it in the page.
|
|
222
|
-
|
|
223
|
-
// Return the response, the browser context, and the page.
|
|
218
|
+
page.browserTypeName = typeName;
|
|
219
|
+
// Return the response of the target server, the browser context, and the page.
|
|
224
220
|
return {
|
|
225
221
|
success: true,
|
|
226
222
|
response: navResult.response,
|
|
227
223
|
browserContext,
|
|
228
|
-
|
|
224
|
+
page
|
|
229
225
|
};
|
|
230
226
|
}
|
|
231
227
|
// If the navigation failed:
|
|
@@ -237,7 +233,7 @@ const launch = async (report, typeName, url, debug, waits, isLowMotion = false)
|
|
|
237
233
|
};
|
|
238
234
|
}
|
|
239
235
|
}
|
|
240
|
-
// If it fails to become stable
|
|
236
|
+
// If it fails to become stable after load:
|
|
241
237
|
catch(error) {
|
|
242
238
|
// Return this.
|
|
243
239
|
console.log(`ERROR: Blank page load in new tab timed out (${error.message})`);
|
package/run.js
CHANGED
|
@@ -422,7 +422,10 @@ const wait = ms => {
|
|
|
422
422
|
});
|
|
423
423
|
};
|
|
424
424
|
// Adds an error result to an act.
|
|
425
|
-
const addError = (act, error, message) => {
|
|
425
|
+
const addError = (alsoLog, act, error, message) => {
|
|
426
|
+
if (alsoLog) {
|
|
427
|
+
console.log(`${message} (${error})`);
|
|
428
|
+
}
|
|
426
429
|
if (! act.result) {
|
|
427
430
|
act.result = {};
|
|
428
431
|
}
|
|
@@ -516,12 +519,13 @@ const doActs = async (report, actIndex, page) => {
|
|
|
516
519
|
);
|
|
517
520
|
// If the launch and navigation succeeded:
|
|
518
521
|
if (launchResult && launchResult.success) {
|
|
519
|
-
//
|
|
520
|
-
const {response
|
|
521
|
-
|
|
522
|
+
// Get the response of the target server.
|
|
523
|
+
const {response} = launchResult;
|
|
524
|
+
// Get the target page.
|
|
525
|
+
page = launchResult.page;
|
|
522
526
|
// Add the actual URL to the act.
|
|
523
527
|
act.actualURL = page.url();
|
|
524
|
-
// Add
|
|
528
|
+
// Add the script nonce, if any, to the act.
|
|
525
529
|
const scriptNonce = await getNonce(response);
|
|
526
530
|
if (scriptNonce) {
|
|
527
531
|
report.jobData.lastScriptNonce = scriptNonce;
|
|
@@ -529,6 +533,8 @@ const doActs = async (report, actIndex, page) => {
|
|
|
529
533
|
}
|
|
530
534
|
// Otherwise, i.e. if the launch or navigation failed:
|
|
531
535
|
else {
|
|
536
|
+
// Add an error result to the act.
|
|
537
|
+
addError(true, act, 'badLaunch', `ERROR: Launch failed (${launchResult.error})`);
|
|
532
538
|
// Abort the job.
|
|
533
539
|
await abortActs();
|
|
534
540
|
}
|
|
@@ -558,13 +564,13 @@ const doActs = async (report, actIndex, page) => {
|
|
|
558
564
|
// If a prohibited redirection occurred:
|
|
559
565
|
if (response.exception === 'badRedirection') {
|
|
560
566
|
// Report this and quit.
|
|
561
|
-
addError(act, 'badRedirection', 'ERROR: Navigation illicitly redirected');
|
|
567
|
+
addError(true, act, 'badRedirection', 'ERROR: Navigation illicitly redirected');
|
|
562
568
|
await abortActs();
|
|
563
569
|
}
|
|
564
570
|
// Otherwise, i.e. if the visit failed:
|
|
565
571
|
else {
|
|
566
572
|
// Report this and quit.
|
|
567
|
-
addError(act, 'failure', 'ERROR: Visit failed');
|
|
573
|
+
addError(true, act, 'failure', 'ERROR: Visit failed');
|
|
568
574
|
await abortActs();
|
|
569
575
|
}
|
|
570
576
|
}
|
|
@@ -648,7 +654,7 @@ const doActs = async (report, actIndex, page) => {
|
|
|
648
654
|
.catch(async error => {
|
|
649
655
|
// Quit.
|
|
650
656
|
console.log(`ERROR waiting for page to be ${act.which} (${error.message})`);
|
|
651
|
-
addError(act, 'timeout', `ERROR waiting for page to be ${act.which}`);
|
|
657
|
+
addError(true, act, 'timeout', `ERROR waiting for page to be ${act.which}`);
|
|
652
658
|
await abortActs();
|
|
653
659
|
});
|
|
654
660
|
// If the wait succeeded:
|
|
@@ -865,11 +871,9 @@ const doActs = async (report, actIndex, page) => {
|
|
|
865
871
|
}
|
|
866
872
|
// If the move fails:
|
|
867
873
|
catch(error) {
|
|
868
|
-
//
|
|
869
|
-
act
|
|
870
|
-
|
|
871
|
-
act.result.message = `ERROR: ${move} failed`;
|
|
872
|
-
console.log(`ERROR: ${move} failed (${errorStart(error)})`);
|
|
874
|
+
// Add the error result to the act.
|
|
875
|
+
addError(true, act, 'moveFailure', `ERROR: ${move} failed`);
|
|
876
|
+
// Abort.
|
|
873
877
|
await abortActs();
|
|
874
878
|
}
|
|
875
879
|
if (act.result.success) {
|
|
@@ -1207,19 +1211,25 @@ const doActs = async (report, actIndex, page) => {
|
|
|
1207
1211
|
// Otherwise, i.e. if the act type is unknown:
|
|
1208
1212
|
else {
|
|
1209
1213
|
// Add the error result to the act.
|
|
1210
|
-
addError(act, 'badType', 'ERROR: Invalid act type');
|
|
1214
|
+
addError(true, act, 'badType', 'ERROR: Invalid act type');
|
|
1215
|
+
// Abort.
|
|
1216
|
+
await abortActs();
|
|
1211
1217
|
}
|
|
1212
1218
|
}
|
|
1213
1219
|
// Otherwise, a page URL is required but does not exist, so:
|
|
1214
1220
|
else {
|
|
1215
1221
|
// Add an error result to the act.
|
|
1216
|
-
addError(act, 'noURL', 'ERROR: Page has no URL');
|
|
1222
|
+
addError(true, act, 'noURL', 'ERROR: Page has no URL');
|
|
1223
|
+
// Abort.
|
|
1224
|
+
await abortActs();
|
|
1217
1225
|
}
|
|
1218
1226
|
}
|
|
1219
1227
|
// Otherwise, i.e. if no page exists:
|
|
1220
1228
|
else {
|
|
1221
1229
|
// Add an error result to the act.
|
|
1222
|
-
addError(act, 'noPage', 'ERROR: No page identified');
|
|
1230
|
+
addError(true, act, 'noPage', 'ERROR: No page identified');
|
|
1231
|
+
// Abort.
|
|
1232
|
+
await abortActs();
|
|
1223
1233
|
}
|
|
1224
1234
|
act.endTime = Date.now();
|
|
1225
1235
|
}
|
|
@@ -1228,7 +1238,8 @@ const doActs = async (report, actIndex, page) => {
|
|
|
1228
1238
|
// Quit and add error data to the report.
|
|
1229
1239
|
const errorMsg = `ERROR: Invalid act of type ${act.type}`;
|
|
1230
1240
|
console.log(errorMsg);
|
|
1231
|
-
addError(act, 'badAct', errorMsg);
|
|
1241
|
+
addError(true, act, 'badAct', errorMsg);
|
|
1242
|
+
// Abort.
|
|
1232
1243
|
await abortActs();
|
|
1233
1244
|
}
|
|
1234
1245
|
// Perform any remaining acts if not aborted.
|
package/watch.js
CHANGED
|
@@ -158,8 +158,8 @@ const checkNetJob = async (servers, serverIndex, isForever, interval, noJobCount
|
|
|
158
158
|
// When the response arrives:
|
|
159
159
|
.on('end', async () => {
|
|
160
160
|
const content = chunks.join('');
|
|
161
|
-
// If there was no job to do:
|
|
162
161
|
try {
|
|
162
|
+
// If there was no job to do:
|
|
163
163
|
let contentObj = JSON.parse(content);
|
|
164
164
|
if (! Object.keys(contentObj).length) {
|
|
165
165
|
// Report this.
|
|
@@ -178,14 +178,17 @@ const checkNetJob = async (servers, serverIndex, isForever, interval, noJobCount
|
|
|
178
178
|
await checkNetJob(servers, serverIndex + 1, isForever, interval, noJobCount + 1);
|
|
179
179
|
}
|
|
180
180
|
// Otherwise, if the server sent a valid job:
|
|
181
|
-
else if (id && sources) {
|
|
181
|
+
else if (id && sources && sources.target && sources.target.which) {
|
|
182
182
|
// Add the agent to it.
|
|
183
183
|
sources.agent = agent;
|
|
184
184
|
// If the job specifies a report destination:
|
|
185
185
|
const {sendReportTo} = sources;
|
|
186
186
|
if (sendReportTo) {
|
|
187
187
|
// Perform the job, adding result data to it.
|
|
188
|
-
|
|
188
|
+
const testee = sources.target.which;
|
|
189
|
+
console.log(
|
|
190
|
+
`${logStart}job ${id} (${nowString()})\n>> It will test ${testee}\n>> It will send report to ${sendReportTo}`
|
|
191
|
+
);
|
|
189
192
|
await doJob(contentObj);
|
|
190
193
|
let reportJSON = JSON.stringify(contentObj, null, 2);
|
|
191
194
|
console.log(`Job ${id} finished (${nowString()})`);
|
|
@@ -279,12 +282,10 @@ const checkNetJob = async (servers, serverIndex, isForever, interval, noJobCount
|
|
|
279
282
|
}
|
|
280
283
|
}
|
|
281
284
|
}
|
|
282
|
-
// If
|
|
285
|
+
// If an error is thrown:
|
|
283
286
|
catch(error) {
|
|
284
287
|
// Report this.
|
|
285
|
-
console.log(
|
|
286
|
-
`ERROR: ${logStart}status ${response.statusCode}, error message ${error.message}, and response ${content.slice(0, 1000)}`
|
|
287
|
-
);
|
|
288
|
+
console.log(`ERROR: ${error.message} (response ${content.slice(0, 1000)})`);
|
|
288
289
|
// Check the next server.
|
|
289
290
|
await checkNetJob(servers, serverIndex + 1, isForever, interval, noJobCount + 1);
|
|
290
291
|
}
|