Skip to content

fix: retryFailedStep is disabled for non tryTo steps #4069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ Run tests with plugin enabled:
- `factor` - The exponential factor to use. Default is 1.5.
- `minTimeout` - The number of milliseconds before starting the first retry. Default is 1000.
- `maxTimeout` - The maximum number of milliseconds between two retries. Default is Infinity.
- `randomize` - Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.
- `randomize` - Randomizes the timeouts by multiplying with a factor from 1 to 2. Default is false.
- `defaultIgnoredSteps` - an array of steps to be ignored for retry. Includes:
- `amOnPage`
- `wait*`
Expand Down Expand Up @@ -1085,7 +1085,7 @@ plugins: {

## tryTo

Adds global `tryTo` function inside of which all failed steps won't fail a test but will return true/false.
Adds global `tryTo` function in which all failed steps won't fail a test but will return true/false.

Enable this plugin in `codecept.conf.js` (enabled by default for new setups):

Expand Down Expand Up @@ -1124,7 +1124,7 @@ Add assert requires first:
const assert = require('assert');
````

Then use the assert:
Then use the assertion:
const result1 = await tryTo(() => I.see('Hello, user'));
const result2 = await tryTo(() => I.seeElement('.welcome'));
assert.ok(result1 && result2, 'Assertions were not succesful');
Expand Down
4 changes: 2 additions & 2 deletions lib/plugin/retryFailedStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const defaultConfig = {
* * `factor` - The exponential factor to use. Default is 1.5.
* * `minTimeout` - The number of milliseconds before starting the first retry. Default is 1000.
* * `maxTimeout` - The maximum number of milliseconds between two retries. Default is Infinity.
* * `randomize` - Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.
* * `randomize` - Randomizes the timeouts by multiplying with a factor from 1 to 2. Default is false.
* * `defaultIgnoredSteps` - an array of steps to be ignored for retry. Includes:
* * `amOnPage`
* * `wait*`
Expand Down Expand Up @@ -99,7 +99,7 @@ module.exports = (config) => {
config.when = when;

event.dispatcher.on(event.step.started, (step) => {
if (container.plugins('tryTo')) return;
if (process.env.TRY_TO) return;

// if a step is ignored - return
for (const ignored of config.ignoredSteps) {
Expand Down
9 changes: 5 additions & 4 deletions lib/plugin/tryTo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const recorder = require('../recorder');
const store = require('../store');
const { debug } = require('../output');

const defaultConfig = {
Expand All @@ -9,7 +8,7 @@ const defaultConfig = {
/**
*
*
* Adds global `tryTo` function inside of which all failed steps won't fail a test but will return true/false.
* Adds global `tryTo` function in which all failed steps won't fail a test but will return true/false.
*
* Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
*
Expand Down Expand Up @@ -47,7 +46,7 @@ const defaultConfig = {
* ```js
* const assert = require('assert');
* ```
* Then use the assert:
* Then use the assertion:
* const result1 = await tryTo(() => I.see('Hello, user'));
* const result2 = await tryTo(() => I.seeElement('.welcome'));
* assert.ok(result1 && result2, 'Assertions were not succesful');
Expand All @@ -70,7 +69,7 @@ const defaultConfig = {
* const tryTo = codeceptjs.container.plugins('tryTo');
* ```
*
*/
*/
module.exports = function (config) {
config = Object.assign(defaultConfig, config);

Expand All @@ -84,6 +83,7 @@ function tryTo(callback) {
let result = false;
return recorder.add('tryTo', () => {
recorder.session.start('tryTo');
process.env.TRY_TO = 'true';
callback();
recorder.add(() => {
result = true;
Expand All @@ -98,6 +98,7 @@ function tryTo(callback) {
return result;
});
return recorder.add('result', () => {
process.env.TRY_TO = undefined;
return result;
}, true, false);
}, false, false);
Expand Down