Skip to content

Commit

Permalink
introduce debug mode global var
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Sep 28, 2023
1 parent 5ace08f commit 65650e6
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/helpers/Playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).



Expand Down
2 changes: 1 addition & 1 deletion docs/helpers/Puppeteer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).



Expand Down
2 changes: 1 addition & 1 deletion docs/helpers/WebDriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).



Expand Down
3 changes: 3 additions & 0 deletions lib/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class Codecept {
global.When = stepDefinitions.When;
global.Then = stepDefinitions.Then;
global.DefineParameterType = stepDefinitions.defineParameterType;

// debug mode
global.debugMode = false;
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/command/run-workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = async function (workerCount, selectedRuns, options) {

try {
if (options.verbose) {
global.debugMode = true;
const getInfo = require('./info');
await getInfo();
}
Expand Down
1 change: 1 addition & 0 deletions lib/command/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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)';
Expand Down
8 changes: 4 additions & 4 deletions lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions lib/helper/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions lib/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -98,7 +97,6 @@ async function parseInput(cmd) {
return cmd;
};

store.debugMode = true;
let isCustomCommand = false;
let lastError = null;
let isAiCommand = false;
Expand Down
5 changes: 0 additions & 5 deletions lib/plugin/autoLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -287,7 +283,6 @@ module.exports = function (config) {
});
});
recorder.add(() => {
store.debugMode = false;
recorder.session.restore('check login');
});

Expand Down
2 changes: 0 additions & 2 deletions lib/plugin/retryTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -113,7 +112,6 @@ module.exports = function (config) {
};

recorder.add('retryTo', async () => {
store.debugMode = true;
tryBlock();
});
}).then(() => {
Expand Down
3 changes: 0 additions & 3 deletions lib/plugin/tryTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -100,7 +98,6 @@ function tryTo(callback) {
return result;
});
return recorder.add('result', () => {
store.debugMode = mode;
return result;
}, true, false);
}, false, false);
Expand Down

0 comments on commit 65650e6

Please sign in to comment.