Skip to content

Commit 10e6914

Browse files
committed
Add nav wait after sign in to allow a screenshot
1 parent 60c733d commit 10e6914

2 files changed

Lines changed: 125 additions & 22 deletions

File tree

‎lib/scope.js‎

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,6 +3090,7 @@ module.exports = {
30903090
/** Allow the developer to log a user into their server using GitHub
30913091
* secrets to authenticate.
30923092
*/
3093+
await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp-1.jpg`});
30933094
// Don't take a picture of a failed login in case one of the inputs is correct
30943095
scope.disable_error_screenshot = true;
30953096

@@ -3101,24 +3102,30 @@ module.exports = {
31013102

31023103
// Go to the sign in page
31033104
let login_url = `${ session_vars.get_da_server_url() }/user/sign-in`;
3105+
await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp-2.jpg`});
31043106

31053107
// TODO: implement and use scope.handle_possible_timeout()
31063108
try {
31073109
// puppeteer will ensure proper timeout.
31083110
await scope.page.goto( login_url, { waitUntil: `domcontentloaded`, timeout: scope.timeout });
31093111
await scope.page.waitForSelector( `.dabody` );
31103112

3113+
await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp-3.jpg`});
3114+
31113115
} catch ( error ) {
31123116

31133117
let err_msg = `Error occurred when ALKiln tried to go to "${ login_url }".`
31143118
if ( error.name === `TimeoutError` ) {
3119+
console.log(`🖊️ 110`);
31153120
let non_reload_report_msg = `It took too long to load "${ login_url }"`;
31163121
await scope.handle_page_timeout_error( scope, { non_reload_report_data: {
31173122
code: `ALK0159`,
31183123
message: non_reload_report_msg,
31193124
}, error });
31203125
} else {
31213126
// Throw any non-timeout error
3127+
console.log(`🖊️ 111`);
3128+
await scope.take_a_screenshot(scope, {path:`./_alkiln_temp/Temp-4.jpg`});
31223129
reports.addToReport( scope, { type: `error`, code: `ALK0160`, value: err_msg });
31233130
throw error;
31243131
} // ends if error is timeout error
@@ -3159,6 +3166,8 @@ module.exports = {
31593166
scope.scenarios.get( scope.scenario_id ).api_keys.push( api_key );
31603167
}
31613168
}
3169+
console.log(`🖊️ 112`);
3170+
await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp-4.jpg`});
31623171

31633172
expect( email, email_msg ).to.not.equal( undefined );
31643173
expect( password, password_msg ).to.not.equal( undefined );
@@ -3168,9 +3177,14 @@ module.exports = {
31683177
await scope.page.type( `#password`, password );
31693178
let elem = await scope.page.$( `button[type="submit"]` );
31703179
await scope.guard_against_missing_tap_element(scope, { elem });
3180+
console.log(`🖊️ 113`);
3181+
await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp-5.jpg`});
31713182

31723183
// Submit and see what happens
3173-
let winner = await scope.steps.race_sign_in_navigation( scope, { elem });
3184+
let winner = await scope.steps.race_sign_in_navigation( scope, { elem, login_url });
3185+
console.log(`🖊️ 113.5 ${ winner }`);
3186+
// await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp-6.jpg`});
3187+
// console.log(`🖊️ 113.6 ${ winner }`);
31743188
// Add the result to the report and possibly throw errors
31753189
if ( winner[0] === `success` ) {
31763190
reports.addToReport( scope, {
@@ -3183,6 +3197,7 @@ module.exports = {
31833197
type: `error`, code: `ALK0209`,
31843198
value: `Failed to sign into ${ login_url }. Make sure you followed the instructions at https://assemblyline.suffolklitlab.org/docs/alkiln/writing/#sign-in.`
31853199
});
3200+
console.log(`🍉 ${ error_msg }`);
31863201
throw new Error( error_msg );
31873202
} else if ( winner[0] === `error` ) {
31883203
let error_msg = reports.addToReport( scope, {
@@ -3191,59 +3206,94 @@ module.exports = {
31913206
});
31923207
throw new Error( error_msg );
31933208
}
3209+
console.log(`🖊️ 114`);
3210+
await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp-7.jpg`});
3211+
if (error_msg) {
3212+
return [ error_msg ];
3213+
} else {
3214+
return [];
3215+
}
31943216
}, // Ends scope.steps.sign_in()
31953217

3196-
race_sign_in_navigation: async function ( scope, { elem }) {
3218+
race_sign_in_navigation: async function ( scope, { elem, login_url='unknown' }) {
31973219
/** Wait for sign in navigation success or failure, or system error. */
31983220

3221+
await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp2-0.jpg`});
3222+
31993223
// After everything, clean up incomplete promises
32003224
const controller = new AbortController;
3225+
console.log(`⏳ 200`);
32013226

32023227
// Redirect
3203-
let redirect_promise = scope.page.waitForResponse(function ( response ) {
3228+
let redirect_promise = scope.page.waitForResponse(async ( response ) => {
3229+
console.log(`⏳ 300`);
32043230
return response.status() === 302;
32053231
}, { signal: controller.signal })
3206-
.catch(( catch_info ) => {
3232+
.catch(async ( catch_info ) => {
3233+
console.log(`⏳ 201`);
3234+
// await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp2-1.jpg`});
32073235
log.debug({ code: `ALK0204`, context: `nav`, },
32083236
`302 sign-in wait catch error:`, catch_info.name, catch_info,
32093237
);
32103238
});
32113239

32123240
// Invalid credentials, no navigation, no sign in
3213-
let wrong_sign_in_promise = scope.page.waitForResponse(function ( response ) {
3241+
let wrong_sign_in_promise = scope.page.waitForResponse(async ( response ) => {
3242+
console.log(`⏳ 301`);
32143243
return response.status() >= 200 && response.status() < 300 && response.url().includes(`/sign-in`);
32153244
}, { signal: controller.signal })
3216-
.catch(( catch_info ) => {
3245+
.catch(async ( catch_info ) => {
3246+
// errors?
3247+
console.log(`⏳ 202`);
3248+
// await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp2-2.jpg`});
32173249
log.debug({ code: `ALK0205`, context: `nav`, },
32183250
`200s sign-in wait catch error:`, catch_info.name, catch_info,
32193251
);
32203252
});
32213253

32223254
// System error
3223-
let error_promise = scope.page.waitForResponse(function ( response ) {
3255+
let error_promise = scope.page.waitForResponse(async ( response ) => {
3256+
console.log(`⏳ 302`);
32243257
return response.status() >= 500 && response.status() < 600;
32253258
}, { signal: controller.signal })
3226-
.catch(( catch_info ) => {
3259+
.catch(async ( catch_info ) => {
3260+
console.log(`⏳ 203`);
3261+
await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp2-3.jpg`});
32273262
log.debug({ code: `ALK0206`, context: `nav`, },
32283263
`500s sign-in wait catch error:`, catch_info.name, catch_info,
32293264
);
32303265
});
32313266

3267+
// Duh, the other catches were triggered because those promises were aborted
3268+
32323269
let click_promise = elem.click(); // MUST complete
3270+
let nav_promise = scope.nav_race(scope, {}).result;
3271+
let pic_promise = true; // scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp2-10.jpg`});
3272+
console.log(`⏳ 204`);
32333273
const winner = await Promise.race([
3234-
Promise.all([ `success`, click_promise, redirect_promise ]),
3235-
Promise.all([ `failure`, click_promise, wrong_sign_in_promise ]),
3236-
Promise.all([ `error`, click_promise, error_promise ]),
3237-
]).catch(function ( error ) {
3274+
Promise.all([ `success`, click_promise, pic_promise, redirect_promise ]),
3275+
Promise.all([ `failure`, click_promise, pic_promise, wrong_sign_in_promise ]),
3276+
Promise.all([ `error`, click_promise, pic_promise, error_promise ]),
3277+
]).catch(async ( error ) => {
3278+
console.log(`⏳ 205`);
3279+
// await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp2-4.jpg`});
32383280
let error_msg = reports.addToReport( scope, {
32393281
type: `error`, code: `ALK0207`,
32403282
value: `Unknown error waiting for results during sign in at ${ login_url }.`
32413283
});
3242-
throw new Error( error );
3284+
console.log(`⏳ 205.1`, error);
3285+
throw error;
32433286
});
32443287

3288+
console.log(`⏳ 206`);
3289+
// // await waitForTimeout(500);
3290+
// await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp2-5.jpg`});
3291+
32453292
// Clean up unresolved promises
32463293
controller.abort();
3294+
console.log(`⏳ 207`);
3295+
await nav_promise;
3296+
await scope.take_a_screenshot(scope, {path:`${scope.paths.artifacts}/Temp3-1.jpg`});
32473297

32483298
log.debug({ code: `ALK0208`, context: `nav` },
32493299
`Sign-in winner:`, winner
@@ -3517,14 +3567,15 @@ module.exports = {
35173567
let scenario = scope.report.get( scope.scenario_id );
35183568
let report = reports.getPrintableScenario( scenario );
35193569
let all_are_included = true;
3570+
let missing = [];
35203571
for ( let one_expectation of expected ) {
35213572
if ( !report.includes( one_expectation )) {
35223573
all_are_included = false;
3523-
expect( report ).to.contain( one_expectation );
3574+
missing.push( one_expectation );
35243575
}
35253576
}
35263577

3527-
return all_are_included;
3578+
return { all_included: all_are_included, missing };
35283579
}, // Ends scope.reportIncludesAllExpected()
35293580

35303581
reportDoesNotInclude: async function ( scope, { not_expected=[] }) {

0 commit comments

Comments
 (0)