Skip to content

Commit

Permalink
Allow a developer to wait as a first Step. Close #387. Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
plocket committed Dec 28, 2021
1 parent 2403767 commit c9e879b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -1580,4 +1580,9 @@ module.exports = {

return all_are_included;
}, // Ends scope.reportIncludesAllExpected()

waitFor: async function ( scope, options ) {
let { milliseconds } = options || 0;
return new Promise(resolve => setTimeout(resolve, milliseconds));
},
};
21 changes: 15 additions & 6 deletions lib/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,14 @@ When(/I wait (\d*\.?\d+) seconds?/, async (seconds) => { // √
// Shoudl any observational things reset the 'navigated' flag?
// Maybe the 'navitaged' flag should only be reset just before trying to
// navigate (after pressing a button)
await scope.afterStep(scope, {waitForTimeout: (parseFloat(seconds) * 1000)});
let ms = parseFloat( seconds ) * 1000;

if ( scope.page ) {
await scope.afterStep(scope, { waitForTimeout: ms });
} else {
// TODO: Replace with util waiting function in another PR
await scope.waitFor( scope, { milliseconds: ms });
}
});

Then(/I take a screenshot ?(?:named "([^"]+)")?/, async ( name ) => {
Expand Down Expand Up @@ -821,14 +828,15 @@ After(async function(scenario) {
if ( env_vars.DEBUG ) {
// When debugging locally, pause to allow dev to examine the page
console.log( `Error occurred while running test` );
await scope.page.waitFor( 60 * 1000 );
if ( scope.page ) { await scope.page.waitFor( 60 * 1000 ); }
}

await scope.addToReport(scope, { type: `outcome`, value: `**-- Scenario Failed --**` });
// Save/download a picture of the screen during the error
let safe_filename = await scope.getSafeScenarioFilename( scope, { prefix: `error` });
await scope.page.screenshot({ path: `${ safe_filename }.jpg`, type: `jpeg`, fullPage: true });

if ( scope.page ) {
let safe_filename = await scope.getSafeScenarioFilename( scope, { prefix: `error` });
await scope.page.screenshot({ path: `${ safe_filename }.jpg`, type: `jpeg`, fullPage: true });
}
}

let original_scenario_status = scenario.result.status;
Expand Down Expand Up @@ -873,7 +881,8 @@ After(async function(scenario) {

await scope.page.close();
scope.page = null;
}
} // ends if scope.page

});

AfterAll(async function() {
Expand Down
4 changes: 4 additions & 0 deletions tests/features/establishing_steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ Scenario: I am able to set a custom wait time before an interview has been loade
Given the max seconds for each step in this scenario is 40
And I start the interview at "all_tests"
And I wait 35 seconds

@slow @e3 @wait_first
Scenario: I can wait as a first step in a test
Given I wait 1 second

0 comments on commit c9e879b

Please sign in to comment.