Skip to content

fix: customLocator draws error in dry-mode #3940

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
12 changes: 12 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ If a plugin needs to be enabled in `dry-run` mode, pass its name in `-p` option:
npx codeceptjs dry-run --steps -p allure
```

If some plugins need to be enabled in `dry-run` mode, pass its name in `-p` option:

```
npx codeceptjs dry-run --steps -p allure,customLocator
```

If all plugins need to be enabled in `dry-run` mode, pass its name in `-p` option:

```
npx codeceptjs dry-run --steps -p all
```

To enable bootstrap script in dry-run mode, pass in `--bootstrap` option when running with `--steps` or `--debug`

```
Expand Down
3 changes: 2 additions & 1 deletion lib/command/dryRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ module.exports = async function (test, options) {
if (config.plugins) {
// disable all plugins by default, they can be enabled with -p option
for (const plugin in config.plugins) {
config.plugins[plugin].enabled = false;
// if `-p all` is passed, then enabling all plugins, otherwise plugins could be enabled by `-p customLocator,commentStep,tryTo`
config.plugins[plugin].enabled = options.plugins === 'all';
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/data/sandbox/codecept.customLocator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
exports.config = {
tests: './*.customLocator.js',
timeout: 10000,
output: './output',
helpers: {
Playwright: {
url: 'http://localhost',
show: true,
browser: 'chromium',
},
},
include: {},
bootstrap: false,
mocha: {},
name: 'sandbox',
plugins: {
customLocator: {
enabled: false,
prefix: '$',
attribute: 'data-testid',
},
},
};
6 changes: 6 additions & 0 deletions test/data/sandbox/test.customLocator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const I = actor();
Feature('Custom Locator');

Scenario('no error with dry-mode', () => {
I.seeElement(locate('$COURSE').find('a'));
});
22 changes: 22 additions & 0 deletions test/runner/dry_run_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,26 @@ describe('dry-run command', () => {
done();
});
});

it('should enable all plugins in dry-mode when passing -p all', (done) => {
exec(`${codecept_run_config('codecept.customLocator.js')} --verbose -p all`, (err, stdout) => {
expect(stdout).toContain('Plugins: screenshotOnFail, customLocator');
expect(stdout).toContain('I see element {xpath: .//*[@data-testid=\'COURSE\']//a}');
expect(stdout).toContain('OK | 1 passed');
expect(stdout).toContain('--- DRY MODE: No tests were executed ---');
expect(err).toBeFalsy();
done();
});
});

it('should enable a particular plugin in dry-mode when passing it to -p', (done) => {
exec(`${codecept_run_config('codecept.customLocator.js')} --verbose -p customLocator`, (err, stdout) => {
expect(stdout).toContain('Plugins: customLocator');
expect(stdout).toContain('I see element {xpath: .//*[@data-testid=\'COURSE\']//a}');
expect(stdout).toContain('OK | 1 passed');
expect(stdout).toContain('--- DRY MODE: No tests were executed ---');
expect(err).toBeFalsy();
done();
});
});
});