Skip to content

Commit

Permalink
fix: customLocator draws error in dry-mode (#3940)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Oct 21, 2023
1 parent 300d519 commit 18be8a2
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
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();
});
});
});

0 comments on commit 18be8a2

Please sign in to comment.