Skip to content

Commit dd82327

Browse files
philkasDavertMik
andauthored
Fix highlight element js handle context problem (#3779)
* fix catching unhandled promise rejection - evalute returns a promise and the try-catch does not handle rejected promise exception correctly. Not sure if it is realy necessary to print the exception via console.error * use _getContext instead of page - so the highlighting also works for elements in frames and shoulg prevent throwing promise rection exception when calling evaluate method of the passed context * fix getContext for playwright --------- Co-authored-by: Michael Bodnarchuk <[email protected]>
1 parent db43fb9 commit dd82327

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

lib/helper/Playwright.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ class Playwright extends Helper {
15561556

15571557
await el.clear();
15581558

1559-
highlightActiveElement.call(this, el, this.page);
1559+
highlightActiveElement.call(this, el, await this._getContext());
15601560

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

@@ -1601,7 +1601,7 @@ class Playwright extends Helper {
16011601
async appendField(field, value) {
16021602
const els = await findFields.call(this, field);
16031603
assertElementExists(els, field, 'Field');
1604-
highlightActiveElement.call(this, els[0], this.page);
1604+
highlightActiveElement.call(this, els[0], await this._getContext());
16051605
await els[0].press('End');
16061606
await els[0].type(value.toString(), { delay: this.options.pressKeyDelay });
16071607
return this._waitForAction();
@@ -1645,7 +1645,8 @@ class Playwright extends Helper {
16451645
assertElementExists(els, select, 'Selectable field');
16461646
const el = els[0];
16471647

1648-
highlightActiveElement.call(this, el, this.page);
1648+
highlightActiveElement.call(this, el, await this._getContext());
1649+
16491650
if (!Array.isArray(option)) option = [option];
16501651

16511652
await el.selectOption(option);
@@ -3197,7 +3198,7 @@ async function proceedClick(locator, context = null, options = {}) {
31973198
assertElementExists(els, locator, 'Clickable element');
31983199
}
31993200

3200-
highlightActiveElement.call(this, els[0], this.page);
3201+
highlightActiveElement.call(this, els[0], await this._getContext());
32013202

32023203
/*
32033204
using the force true options itself but instead dispatching a click

lib/helper/Puppeteer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ class Puppeteer extends Helper {
13221322
await this._evaluateHandeInContext(el => el.innerHTML = '', el);
13231323
}
13241324

1325-
highlightActiveElement.call(this, el, this.page);
1325+
highlightActiveElement.call(this, el, await this._getContext());
13261326
await el.type(value.toString(), { delay: this.options.pressKeyDelay });
13271327

13281328
return this._waitForAction();
@@ -1343,7 +1343,7 @@ class Puppeteer extends Helper {
13431343
async appendField(field, value) {
13441344
const els = await findVisibleFields.call(this, field);
13451345
assertElementExists(els, field, 'Field');
1346-
highlightActiveElement.call(this, els[0], this.page);
1346+
highlightActiveElement.call(this, els[0], await this._getContext());
13471347
await els[0].press('End');
13481348
await els[0].type(value.toString(), { delay: this.options.pressKeyDelay });
13491349
return this._waitForAction();
@@ -1390,7 +1390,7 @@ class Puppeteer extends Helper {
13901390
if (await el.getProperty('tagName').then(t => t.jsonValue()) !== 'SELECT') {
13911391
throw new Error('Element is not <select>');
13921392
}
1393-
highlightActiveElement.call(this, els[0], this.page);
1393+
highlightActiveElement.call(this, els[0], await this._getContext());
13941394
if (!Array.isArray(option)) option = [option];
13951395

13961396
for (const key in option) {
@@ -2363,7 +2363,7 @@ async function proceedClick(locator, context = null, options = {}) {
23632363
assertElementExists(els, locator, 'Clickable element');
23642364
}
23652365

2366-
highlightActiveElement.call(this, els[0], this.page);
2366+
highlightActiveElement.call(this, els[0], await this._getContext());
23672367

23682368
await els[0].click(options);
23692369
const promises = [];

lib/helper/scripts/highlightElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports.highlightElement = (element, context) => {
88

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

0 commit comments

Comments
 (0)