diff --git a/docs/commands.md b/docs/commands.md index 7d9de41b9..57bfd523e 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -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` ``` diff --git a/lib/command/dryRun.js b/lib/command/dryRun.js index e5add05c8..426d20e07 100644 --- a/lib/command/dryRun.js +++ b/lib/command/dryRun.js @@ -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'; } } diff --git a/test/data/sandbox/codecept.customLocator.js b/test/data/sandbox/codecept.customLocator.js new file mode 100644 index 000000000..9cdd1b3f7 --- /dev/null +++ b/test/data/sandbox/codecept.customLocator.js @@ -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', + }, + }, +}; diff --git a/test/data/sandbox/test.customLocator.js b/test/data/sandbox/test.customLocator.js new file mode 100644 index 000000000..608ba57f0 --- /dev/null +++ b/test/data/sandbox/test.customLocator.js @@ -0,0 +1,6 @@ +const I = actor(); +Feature('Custom Locator'); + +Scenario('no error with dry-mode', () => { + I.seeElement(locate('$COURSE').find('a')); +}); diff --git a/test/runner/dry_run_test.js b/test/runner/dry_run_test.js index 0bac5d353..1881f7706 100644 --- a/test/runner/dry_run_test.js +++ b/test/runner/dry_run_test.js @@ -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(); + }); + }); });