Skip to content

Commit

Permalink
Allow a developer to wait as a first Step for v3. Address #387. Add t…
Browse files Browse the repository at this point in the history
…est. (#459)

This adds a temporary function for waiting in scope.js that will soon be replaced by a singular function in the utils folder. That said, that function is part of v4 changes, and this can improve v3 as well, so we might as well not wait.

Addresses #387, after a little confusion. Should add this to the testing docs as a 'first step' after this is merged.

[Also, generally adds safety measures for when page does not exist.]

------------------

* Allow a developer to wait as a first Step. Close #387. Add test.

* Offer proper fallback for wait options
  • Loading branch information
plocket committed Feb 7, 2022
1 parent 37f074c commit fdae93a
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 @@ -1662,4 +1662,9 @@ module.exports = {

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

waitFor: async function ( scope, options ) {
let { milliseconds } = options || { milliseconds: 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 @@ -366,7 +366,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 @@ -882,14 +889,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 @@ -934,7 +942,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 @@ -16,6 +16,10 @@ Scenario: I am able to set a custom wait time before an interview has been loade
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

@fast @e3 @urlargs
Scenario: Interview name includes url args
  Given I start the interview at "url_args.yml&from=theinternets&random=zoo"
Expand Down

0 comments on commit fdae93a

Please sign in to comment.