Skip to content

Commit 128274f

Browse files
authored
fix: highlight issue (#3896)
* fix: highlight issue * introduce debug mode global var
1 parent feb0e64 commit 128274f

14 files changed

+31
-35
lines changed

docs/helpers/Playwright.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Type: [object][5]
7474
- `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].
7575
- `ignoreHTTPSErrors` **[boolean][32]?** Allows access to untrustworthy pages, e.g. to a page with an expired certificate. Default value is `false`
7676
- `bypassCSP` **[boolean][32]?** bypass Content Security Policy or CSP
77-
- `highlightElement` **[boolean][32]?** highlight the interacting elements. Default: false
77+
- `highlightElement` **[boolean][32]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
7878

7979

8080

docs/helpers/Puppeteer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Type: [object][4]
5656
- `manualStart` **[boolean][20]?** do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`.
5757
- `browser` **[string][6]?** can be changed to `firefox` when using [puppeteer-firefox][2].
5858
- `chrome` **[object][4]?** pass additional [Puppeteer run options][25].
59-
- `highlightElement` **[boolean][20]?** highlight the interacting elements. Default: false
59+
- `highlightElement` **[boolean][20]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
6060

6161

6262

docs/helpers/WebDriver.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Type: [object][16]
4545
- `desiredCapabilities` **[object][16]?** Selenium's [desired capabilities][6].
4646
- `manualStart` **[boolean][32]?** do not start browser before a test, start it manually inside a helper with `this.helpers["WebDriver"]._startBrowser()`.
4747
- `timeouts` **[object][16]?** [WebDriver timeouts][37] defined as hash.
48-
- `highlightElement` **[boolean][32]?** highlight the interacting elements. Default: false
48+
- `highlightElement` **[boolean][32]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
4949

5050

5151

lib/codecept.js

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class Codecept {
8989
global.When = stepDefinitions.When;
9090
global.Then = stepDefinitions.Then;
9191
global.DefineParameterType = stepDefinitions.defineParameterType;
92+
93+
// debug mode
94+
global.debugMode = false;
9295
}
9396
}
9497

lib/command/run-workers.js

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module.exports = async function (workerCount, selectedRuns, options) {
4040

4141
try {
4242
if (options.verbose) {
43+
global.debugMode = true;
4344
const { getMachineInfo } = require('./info');
4445
await getMachineInfo();
4546
}

lib/command/run.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = async function (test, options) {
3030
codecept.loadTests(test);
3131

3232
if (options.verbose) {
33+
global.debugMode = true;
3334
const { getMachineInfo } = require('./info');
3435
await getMachineInfo();
3536
}

lib/helper/Playwright.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const {
4747
setRestartStrategy, restartsSession, restartsContext, restartsBrowser,
4848
} = require('./extras/PlaywrightRestartOpts');
4949
const { createValueEngine, createDisabledEngine } = require('./extras/PlaywrightPropEngine');
50-
const { highlightElement } = require('./scripts/highlightElement');
5150

5251
const pathSeparator = path.sep;
5352

@@ -94,7 +93,7 @@ const pathSeparator = path.sep;
9493
* @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).
9594
* @prop {boolean} [ignoreHTTPSErrors] - Allows access to untrustworthy pages, e.g. to a page with an expired certificate. Default value is `false`
9695
* @prop {boolean} [bypassCSP] - bypass Content Security Policy or CSP
97-
* @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false
96+
* @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
9897
*/
9998
const config = {};
10099

@@ -1579,7 +1578,7 @@ class Playwright extends Helper {
15791578

15801579
await el.clear();
15811580

1582-
highlightActiveElement.call(this, el, await this._getContext());
1581+
await highlightActiveElement.call(this, el);
15831582

15841583
await el.type(value.toString(), { delay: this.options.pressKeyDelay });
15851584

@@ -1609,7 +1608,7 @@ class Playwright extends Helper {
16091608

16101609
const el = els[0];
16111610

1612-
highlightActiveElement.call(this, el, this.page);
1611+
await highlightActiveElement.call(this, el);
16131612

16141613
await el.clear();
16151614

@@ -1624,7 +1623,7 @@ class Playwright extends Helper {
16241623
async appendField(field, value) {
16251624
const els = await findFields.call(this, field);
16261625
assertElementExists(els, field, 'Field');
1627-
highlightActiveElement.call(this, els[0], await this._getContext());
1626+
await highlightActiveElement.call(this, els[0]);
16281627
await els[0].press('End');
16291628
await els[0].type(value.toString(), { delay: this.options.pressKeyDelay });
16301629
return this._waitForAction();
@@ -1670,7 +1669,7 @@ class Playwright extends Helper {
16701669
assertElementExists(els, select, 'Selectable field');
16711670
const el = els[0];
16721671

1673-
highlightActiveElement.call(this, el, await this._getContext());
1672+
await highlightActiveElement.call(this, el);
16741673

16751674
if (!Array.isArray(option)) option = [option];
16761675

@@ -3290,7 +3289,7 @@ async function proceedClick(locator, context = null, options = {}) {
32903289
assertElementExists(els, locator, 'Clickable element');
32913290
}
32923291

3293-
highlightActiveElement.call(this, els[0], await this._getContext());
3292+
await highlightActiveElement.call(this, els[0]);
32943293

32953294
/*
32963295
using the force true options itself but instead dispatching a click
@@ -3716,10 +3715,14 @@ async function saveTraceForContext(context, name) {
37163715
return fileName;
37173716
}
37183717

3719-
function highlightActiveElement(element, context) {
3720-
if (!this.options.highlightElement && !store.debugMode) return;
3721-
3722-
highlightElement(element, context);
3718+
async function highlightActiveElement(element) {
3719+
if (this.options.highlightElement && global.debugMode) {
3720+
await element.evaluate(el => {
3721+
const prevStyle = el.style.boxShadow;
3722+
el.style.boxShadow = '0px 0px 4px 3px rgba(255, 0, 0, 0.7)';
3723+
setTimeout(() => el.style.boxShadow = prevStyle, 2000);
3724+
});
3725+
}
37233726
}
37243727

37253728
const createAdvancedTestResults = (url, dataToCheck, requests) => {

lib/helper/Puppeteer.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const consoleLogStore = new Console();
6969
* @prop {boolean} [manualStart=false] - do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`.
7070
* @prop {string} [browser=chrome] - can be changed to `firefox` when using [puppeteer-firefox](https://codecept.io/helpers/Puppeteer-firefox).
7171
* @prop {object} [chrome] - pass additional [Puppeteer run options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions).
72-
* @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false
72+
* @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
7373
*/
7474
const config = {};
7575

@@ -2727,7 +2727,7 @@ function getNormalizedKey(key) {
27272727
}
27282728

27292729
function highlightActiveElement(element, context) {
2730-
if (!this.options.highlightElement && !store.debugMode) return;
2731-
2732-
highlightElement(element, context);
2730+
if (this.options.highlightElement && global.debugMode) {
2731+
highlightElement(element, context);
2732+
}
27332733
}

lib/helper/WebDriver.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const webRoot = 'body';
6262
* @prop {object} [desiredCapabilities] Selenium's [desired capabilities](https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities).
6363
* @prop {boolean} [manualStart=false] - do not start browser before a test, start it manually inside a helper with `this.helpers["WebDriver"]._startBrowser()`.
6464
* @prop {object} [timeouts] [WebDriver timeouts](http://webdriver.io/docs/timeouts.html) defined as hash.
65-
* @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false
65+
* @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
6666
*/
6767
const config = {};
6868

@@ -2918,9 +2918,9 @@ function isModifierKey(key) {
29182918
}
29192919

29202920
function highlightActiveElement(element) {
2921-
if (!this.options.highlightElement && !store.debugMode) return;
2922-
2923-
highlightElement(element, this.browser);
2921+
if (this.options.highlightElement && global.debugMode) {
2922+
highlightElement(element, this.browser);
2923+
}
29242924
}
29252925

29262926
function prepareLocateFn(context) {

lib/helper/scripts/highlightElement.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports.highlightElement = (element, context) => {
77
};
88

99
try {
10-
// Playwright, Puppeteer
10+
// Puppeteer
1111
context.evaluate(clientSideHighlightFn, element).catch(err => console.error(err));
1212
} catch (e) {
1313
// WebDriver

lib/pause.js

-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ async function parseInput(cmd) {
7878
rl.pause();
7979
next = false;
8080
recorder.session.start('pause');
81-
store.debugMode = false;
8281
if (cmd === '') next = true;
8382
if (!cmd || cmd === 'resume' || cmd === 'exit') {
8483
finish();
@@ -98,7 +97,6 @@ async function parseInput(cmd) {
9897
return cmd;
9998
};
10099

101-
store.debugMode = true;
102100
let isCustomCommand = false;
103101
let lastError = null;
104102
let isAiCommand = false;

lib/plugin/autoLogin.js

-5
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,16 @@ module.exports = function (config) {
251251
} else {
252252
userSession.login(I);
253253
}
254-
store.debugMode = true;
255254
const cookies = await userSession.fetch(I);
256255
if (config.saveToFile) {
257256
debug(`Saved user session into file for ${name}`);
258257
fs.writeFileSync(path.join(global.output_dir, `${name}_session.json`), JSON.stringify(cookies));
259258
}
260259
store[`${name}_session`] = cookies;
261-
store.debugMode = false;
262260
};
263261

264262
if (!cookies) return loginAndSave();
265263

266-
store.debugMode = true;
267-
268264
recorder.session.start('check login');
269265
if (shouldAwait) {
270266
await userSession.restore(I, cookies);
@@ -287,7 +283,6 @@ module.exports = function (config) {
287283
});
288284
});
289285
recorder.add(() => {
290-
store.debugMode = false;
291286
recorder.session.restore('check login');
292287
});
293288

lib/plugin/retryTo.js

-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ module.exports = function (config) {
8383
return retryTo;
8484

8585
function retryTo(callback, maxTries, pollInterval = undefined) {
86-
const mode = store.debugMode;
8786
let tries = 1;
8887
if (!pollInterval) pollInterval = config.pollInterval;
8988

@@ -113,7 +112,6 @@ module.exports = function (config) {
113112
};
114113

115114
recorder.add('retryTo', async () => {
116-
store.debugMode = true;
117115
tryBlock();
118116
});
119117
}).then(() => {

lib/plugin/tryTo.js

-3
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ module.exports = function (config) {
8181
};
8282

8383
function tryTo(callback) {
84-
const mode = store.debugMode;
8584
let result = false;
8685
return recorder.add('tryTo', () => {
87-
store.debugMode = true;
8886
recorder.session.start('tryTo');
8987
callback();
9088
recorder.add(() => {
@@ -100,7 +98,6 @@ function tryTo(callback) {
10098
return result;
10199
});
102100
return recorder.add('result', () => {
103-
store.debugMode = mode;
104101
return result;
105102
}, true, false);
106103
}, false, false);

0 commit comments

Comments
 (0)