Skip to content

Commit 18be8a2

Browse files
authored
fix: customLocator draws error in dry-mode (#3940)
1 parent 300d519 commit 18be8a2

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

docs/commands.md

+12
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ If a plugin needs to be enabled in `dry-run` mode, pass its name in `-p` option:
152152
npx codeceptjs dry-run --steps -p allure
153153
```
154154

155+
If some plugins need to be enabled in `dry-run` mode, pass its name in `-p` option:
156+
157+
```
158+
npx codeceptjs dry-run --steps -p allure,customLocator
159+
```
160+
161+
If all plugins need to be enabled in `dry-run` mode, pass its name in `-p` option:
162+
163+
```
164+
npx codeceptjs dry-run --steps -p all
165+
```
166+
155167
To enable bootstrap script in dry-run mode, pass in `--bootstrap` option when running with `--steps` or `--debug`
156168

157169
```

lib/command/dryRun.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ module.exports = async function (test, options) {
2020
if (config.plugins) {
2121
// disable all plugins by default, they can be enabled with -p option
2222
for (const plugin in config.plugins) {
23-
config.plugins[plugin].enabled = false;
23+
// if `-p all` is passed, then enabling all plugins, otherwise plugins could be enabled by `-p customLocator,commentStep,tryTo`
24+
config.plugins[plugin].enabled = options.plugins === 'all';
2425
}
2526
}
2627

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
exports.config = {
2+
tests: './*.customLocator.js',
3+
timeout: 10000,
4+
output: './output',
5+
helpers: {
6+
Playwright: {
7+
url: 'http://localhost',
8+
show: true,
9+
browser: 'chromium',
10+
},
11+
},
12+
include: {},
13+
bootstrap: false,
14+
mocha: {},
15+
name: 'sandbox',
16+
plugins: {
17+
customLocator: {
18+
enabled: false,
19+
prefix: '$',
20+
attribute: 'data-testid',
21+
},
22+
},
23+
};
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const I = actor();
2+
Feature('Custom Locator');
3+
4+
Scenario('no error with dry-mode', () => {
5+
I.seeElement(locate('$COURSE').find('a'));
6+
});

test/runner/dry_run_test.js

+22
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,26 @@ describe('dry-run command', () => {
174174
done();
175175
});
176176
});
177+
178+
it('should enable all plugins in dry-mode when passing -p all', (done) => {
179+
exec(`${codecept_run_config('codecept.customLocator.js')} --verbose -p all`, (err, stdout) => {
180+
expect(stdout).toContain('Plugins: screenshotOnFail, customLocator');
181+
expect(stdout).toContain('I see element {xpath: .//*[@data-testid=\'COURSE\']//a}');
182+
expect(stdout).toContain('OK | 1 passed');
183+
expect(stdout).toContain('--- DRY MODE: No tests were executed ---');
184+
expect(err).toBeFalsy();
185+
done();
186+
});
187+
});
188+
189+
it('should enable a particular plugin in dry-mode when passing it to -p', (done) => {
190+
exec(`${codecept_run_config('codecept.customLocator.js')} --verbose -p customLocator`, (err, stdout) => {
191+
expect(stdout).toContain('Plugins: customLocator');
192+
expect(stdout).toContain('I see element {xpath: .//*[@data-testid=\'COURSE\']//a}');
193+
expect(stdout).toContain('OK | 1 passed');
194+
expect(stdout).toContain('--- DRY MODE: No tests were executed ---');
195+
expect(err).toBeFalsy();
196+
done();
197+
});
198+
});
177199
});

0 commit comments

Comments
 (0)