From 65650e6b0a90b1f0bd7a65bff770d07fe28c32be Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Thu, 28 Sep 2023 15:23:57 +0200 Subject: [PATCH] introduce debug mode global var --- docs/helpers/Playwright.md | 2 +- docs/helpers/Puppeteer.md | 2 +- docs/helpers/WebDriver.md | 2 +- lib/codecept.js | 3 +++ lib/command/run-workers.js | 1 + lib/command/run.js | 1 + lib/helper/Playwright.js | 4 ++-- lib/helper/Puppeteer.js | 8 ++++---- lib/helper/WebDriver.js | 8 ++++---- lib/pause.js | 2 -- lib/plugin/autoLogin.js | 5 ----- lib/plugin/retryTo.js | 2 -- lib/plugin/tryTo.js | 3 --- 13 files changed, 18 insertions(+), 25 deletions(-) diff --git a/docs/helpers/Playwright.md b/docs/helpers/Playwright.md index fc31a3ab4..b1f7ea5a1 100644 --- a/docs/helpers/Playwright.md +++ b/docs/helpers/Playwright.md @@ -74,7 +74,7 @@ Type: [object][5] - `ignoreLog` **[Array][9]<[string][8]>?** An array with console message types that are not logged to debug log. Default value is `['warning', 'log']`. E.g. you can set `[]` to log all messages. See all possible [values][44]. - `ignoreHTTPSErrors` **[boolean][32]?** Allows access to untrustworthy pages, e.g. to a page with an expired certificate. Default value is `false` - `bypassCSP` **[boolean][32]?** bypass Content Security Policy or CSP -- `highlightElement` **[boolean][32]?** highlight the interacting elements. Default: false +- `highlightElement` **[boolean][32]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose). diff --git a/docs/helpers/Puppeteer.md b/docs/helpers/Puppeteer.md index 067b6fede..0dcc642ae 100644 --- a/docs/helpers/Puppeteer.md +++ b/docs/helpers/Puppeteer.md @@ -56,7 +56,7 @@ Type: [object][4] - `manualStart` **[boolean][20]?** do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`. - `browser` **[string][6]?** can be changed to `firefox` when using [puppeteer-firefox][2]. - `chrome` **[object][4]?** pass additional [Puppeteer run options][25]. -- `highlightElement` **[boolean][20]?** highlight the interacting elements. Default: false +- `highlightElement` **[boolean][20]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose). diff --git a/docs/helpers/WebDriver.md b/docs/helpers/WebDriver.md index 5220bdca9..e36f9fa48 100644 --- a/docs/helpers/WebDriver.md +++ b/docs/helpers/WebDriver.md @@ -45,7 +45,7 @@ Type: [object][16] - `desiredCapabilities` **[object][16]?** Selenium's [desired capabilities][6]. - `manualStart` **[boolean][32]?** do not start browser before a test, start it manually inside a helper with `this.helpers["WebDriver"]._startBrowser()`. - `timeouts` **[object][16]?** [WebDriver timeouts][37] defined as hash. -- `highlightElement` **[boolean][32]?** highlight the interacting elements. Default: false +- `highlightElement` **[boolean][32]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose). diff --git a/lib/codecept.js b/lib/codecept.js index c72175385..fe749fd6e 100644 --- a/lib/codecept.js +++ b/lib/codecept.js @@ -89,6 +89,9 @@ class Codecept { global.When = stepDefinitions.When; global.Then = stepDefinitions.Then; global.DefineParameterType = stepDefinitions.defineParameterType; + + // debug mode + global.debugMode = false; } } diff --git a/lib/command/run-workers.js b/lib/command/run-workers.js index be1a3dc85..c83b102f8 100644 --- a/lib/command/run-workers.js +++ b/lib/command/run-workers.js @@ -40,6 +40,7 @@ module.exports = async function (workerCount, selectedRuns, options) { try { if (options.verbose) { + global.debugMode = true; const getInfo = require('./info'); await getInfo(); } diff --git a/lib/command/run.js b/lib/command/run.js index fba9b3a68..1c39a895b 100644 --- a/lib/command/run.js +++ b/lib/command/run.js @@ -30,6 +30,7 @@ module.exports = async function (test, options) { codecept.loadTests(test); if (options.verbose) { + global.debugMode = true; const getInfo = require('./info'); await getInfo(); } diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index c80442027..9b294e69c 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -93,7 +93,7 @@ const pathSeparator = path.sep; * @prop {string[]} [ignoreLog] - An array with console message types that are not logged to debug log. Default value is `['warning', 'log']`. E.g. you can set `[]` to log all messages. See all possible [values](https://playwright.dev/docs/api/class-consolemessage#console-message-type). * @prop {boolean} [ignoreHTTPSErrors] - Allows access to untrustworthy pages, e.g. to a page with an expired certificate. Default value is `false` * @prop {boolean} [bypassCSP] - bypass Content Security Policy or CSP - * @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false + * @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose). */ const config = {}; @@ -3716,7 +3716,7 @@ async function saveTraceForContext(context, name) { } async function highlightActiveElement(element) { - if (this.options.highlightElement && store.debugMode) { + if (this.options.highlightElement && global.debugMode) { await element.evaluate(el => { const prevStyle = el.style.boxShadow; el.style.boxShadow = '0px 0px 4px 3px rgba(255, 0, 0, 0.7)'; diff --git a/lib/helper/Puppeteer.js b/lib/helper/Puppeteer.js index 8ca9816f5..89ba6df16 100644 --- a/lib/helper/Puppeteer.js +++ b/lib/helper/Puppeteer.js @@ -69,7 +69,7 @@ const consoleLogStore = new Console(); * @prop {boolean} [manualStart=false] - do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`. * @prop {string} [browser=chrome] - can be changed to `firefox` when using [puppeteer-firefox](https://codecept.io/helpers/Puppeteer-firefox). * @prop {object} [chrome] - pass additional [Puppeteer run options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions). - * @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false + * @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose). */ const config = {}; @@ -2727,7 +2727,7 @@ function getNormalizedKey(key) { } function highlightActiveElement(element, context) { - if (!this.options.highlightElement && !store.debugMode) return; - - highlightElement(element, context); + if (this.options.highlightElement && global.debugMode) { + highlightElement(element, context); + } } diff --git a/lib/helper/WebDriver.js b/lib/helper/WebDriver.js index ca6dd95cb..a6f701a56 100644 --- a/lib/helper/WebDriver.js +++ b/lib/helper/WebDriver.js @@ -62,7 +62,7 @@ const webRoot = 'body'; * @prop {object} [desiredCapabilities] Selenium's [desired capabilities](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities). * @prop {boolean} [manualStart=false] - do not start browser before a test, start it manually inside a helper with `this.helpers["WebDriver"]._startBrowser()`. * @prop {object} [timeouts] [WebDriver timeouts](http://webdriver.io/docs/timeouts.html) defined as hash. - * @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false + * @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose). */ const config = {}; @@ -2918,9 +2918,9 @@ function isModifierKey(key) { } function highlightActiveElement(element) { - if (!this.options.highlightElement && !store.debugMode) return; - - highlightElement(element, this.browser); + if (this.options.highlightElement && global.debugMode) { + highlightElement(element, this.browser); + } } function prepareLocateFn(context) { diff --git a/lib/pause.js b/lib/pause.js index b979b1d54..6e74810f3 100644 --- a/lib/pause.js +++ b/lib/pause.js @@ -78,7 +78,6 @@ async function parseInput(cmd) { rl.pause(); next = false; recorder.session.start('pause'); - store.debugMode = false; if (cmd === '') next = true; if (!cmd || cmd === 'resume' || cmd === 'exit') { finish(); @@ -98,7 +97,6 @@ async function parseInput(cmd) { return cmd; }; - store.debugMode = true; let isCustomCommand = false; let lastError = null; let isAiCommand = false; diff --git a/lib/plugin/autoLogin.js b/lib/plugin/autoLogin.js index 0763c2918..1f1b8bde8 100644 --- a/lib/plugin/autoLogin.js +++ b/lib/plugin/autoLogin.js @@ -251,20 +251,16 @@ module.exports = function (config) { } else { userSession.login(I); } - store.debugMode = true; const cookies = await userSession.fetch(I); if (config.saveToFile) { debug(`Saved user session into file for ${name}`); fs.writeFileSync(path.join(global.output_dir, `${name}_session.json`), JSON.stringify(cookies)); } store[`${name}_session`] = cookies; - store.debugMode = false; }; if (!cookies) return loginAndSave(); - store.debugMode = true; - recorder.session.start('check login'); if (shouldAwait) { await userSession.restore(I, cookies); @@ -287,7 +283,6 @@ module.exports = function (config) { }); }); recorder.add(() => { - store.debugMode = false; recorder.session.restore('check login'); }); diff --git a/lib/plugin/retryTo.js b/lib/plugin/retryTo.js index f35237fcd..8d08dadfe 100644 --- a/lib/plugin/retryTo.js +++ b/lib/plugin/retryTo.js @@ -83,7 +83,6 @@ module.exports = function (config) { return retryTo; function retryTo(callback, maxTries, pollInterval = undefined) { - const mode = store.debugMode; let tries = 1; if (!pollInterval) pollInterval = config.pollInterval; @@ -113,7 +112,6 @@ module.exports = function (config) { }; recorder.add('retryTo', async () => { - store.debugMode = true; tryBlock(); }); }).then(() => { diff --git a/lib/plugin/tryTo.js b/lib/plugin/tryTo.js index 3b65e945c..784d54fb8 100644 --- a/lib/plugin/tryTo.js +++ b/lib/plugin/tryTo.js @@ -81,10 +81,8 @@ module.exports = function (config) { }; function tryTo(callback) { - const mode = store.debugMode; let result = false; return recorder.add('tryTo', () => { - store.debugMode = true; recorder.session.start('tryTo'); callback(); recorder.add(() => { @@ -100,7 +98,6 @@ function tryTo(callback) { return result; }); return recorder.add('result', () => { - store.debugMode = mode; return result; }, true, false); }, false, false);