From 39d7acfc9fbbf42e31e8c7b8d88bf700485ca991 Mon Sep 17 00:00:00 2001 From: Michael Bodnarchuk Date: Tue, 7 Jan 2025 22:25:40 +0200 Subject: [PATCH] better view for pause mode (#4718) Co-authored-by: DavertMik --- lib/helper/Playwright.js | 37 +++++++++---------- lib/pause.js | 2 + lib/store.js | 3 +- .../features/step_definitions/my_steps.de.js | 2 +- .../features/step_definitions/my_steps.de.js | 2 +- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 29238c8f0..f074c710f 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -1255,28 +1255,14 @@ class Playwright extends Helper { if (store.debugMode) { const previewElements = els.slice(0, 3) - let htmls = await Promise.all( - previewElements.map(async el => { - const html = await el.evaluate(node => node.outerHTML) - return ( - html - .replace(/\n/g, '') - .replace(/\s+/g, ' ') - .substring(0, 100 / previewElements.length) - .trim() + '...' - ) - }), - ) - if (els.length > 3) { - htmls.push('...') - } - + let htmls = await Promise.all(previewElements.map(el => elToString(el, previewElements.length))) + if (els.length > 3) htmls.push('...') if (els.length > 1) { this.debugSection(`Elements (${els.length})`, htmls.join('|').trim()) } else if (els.length === 1) { this.debugSection('Element', htmls.join('|').trim()) } else { - this.debug('No elements found') + this.debug(`No elements found by ${JSON.stringify(locator).slice(0, 50)}....`) } } @@ -1734,6 +1720,7 @@ class Playwright extends Helper { const el = els[0] await el.clear() + if (store.debugMode) this.debugSection('Focused', await elToString(el, 1)) await highlightActiveElement.call(this, el) @@ -3447,6 +3434,7 @@ async function proceedClick(locator, context = null, options = {}) { } await highlightActiveElement.call(this, els[0]) + if (store.debugMode) this.debugSection('Clicked', await elToString(els[0], 1)) /* using the force true options itself but instead dispatching a click @@ -3880,11 +3868,22 @@ async function saveTraceForContext(context, name) { } async function highlightActiveElement(element) { - if (this.options.highlightElement && global.debugMode) { + if ((this.options.highlightElement || store.onPause) && store.debugMode) { await element.evaluate(el => { const prevStyle = el.style.boxShadow - el.style.boxShadow = '0px 0px 4px 3px rgba(255, 0, 0, 0.7)' + el.style.boxShadow = '0px 0px 4px 3px rgba(147, 51, 234, 0.8)' // Bright purple that works on both dark/light modes setTimeout(() => (el.style.boxShadow = prevStyle), 2000) }) } } + +async function elToString(el, numberOfElements) { + const html = await el.evaluate(node => node.outerHTML) + return ( + html + .replace(/\n/g, '') + .replace(/\s+/g, ' ') + .substring(0, 100 / numberOfElements) + .trim() + '...' + ) +} diff --git a/lib/pause.js b/lib/pause.js index 65733ecff..202f3ebd8 100644 --- a/lib/pause.js +++ b/lib/pause.js @@ -66,9 +66,11 @@ function pauseSession(passedObject = {}) { historySize: 50, // Adjust the history size as needed }) + store.onPause = true rl.on('line', parseInput) rl.on('close', () => { if (!next) console.log('Exiting interactive shell....') + store.onPause = false }) return new Promise(resolve => { finish = resolve diff --git a/lib/store.js b/lib/store.js index 7dfa03df8..9a29577d6 100644 --- a/lib/store.js +++ b/lib/store.js @@ -9,7 +9,8 @@ const store = { timeouts: true, /** @type {boolean} */ dryRun: false, - + /** @type {boolean} */ + onPause: false, /** @type {CodeceptJS.Test | null} */ currentTest: null, } diff --git a/test/data/sandbox/features/step_definitions/my_steps.de.js b/test/data/sandbox/features/step_definitions/my_steps.de.js index 98d1e549f..1d89c015f 100644 --- a/test/data/sandbox/features/step_definitions/my_steps.de.js +++ b/test/data/sandbox/features/step_definitions/my_steps.de.js @@ -4,7 +4,7 @@ Given('ich habe ein Produkt mit einem Preis von {int}$ in meinem Warenkorb', pri I.addItem(parseInt(price, 10)) }) -Given('der Rabatt für Bestellungen über $\{int} beträgt {int} %', (maxPrice, discount) => { +Given('der Rabatt für Bestellungen über ${int} beträgt {int} %', (maxPrice, discount) => { I.haveDiscountForPrice(maxPrice, discount) }) diff --git a/test/data/sandbox/i18n/features/step_definitions/my_steps.de.js b/test/data/sandbox/i18n/features/step_definitions/my_steps.de.js index 98d1e549f..1d89c015f 100644 --- a/test/data/sandbox/i18n/features/step_definitions/my_steps.de.js +++ b/test/data/sandbox/i18n/features/step_definitions/my_steps.de.js @@ -4,7 +4,7 @@ Given('ich habe ein Produkt mit einem Preis von {int}$ in meinem Warenkorb', pri I.addItem(parseInt(price, 10)) }) -Given('der Rabatt für Bestellungen über $\{int} beträgt {int} %', (maxPrice, discount) => { +Given('der Rabatt für Bestellungen über ${int} beträgt {int} %', (maxPrice, discount) => { I.haveDiscountForPrice(maxPrice, discount) })