Skip to content

Commit 39d7acf

Browse files
DavertMikDavertMik
andauthored
better view for pause mode (#4718)
Co-authored-by: DavertMik <[email protected]>
1 parent d1c91c6 commit 39d7acf

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

lib/helper/Playwright.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,28 +1255,14 @@ class Playwright extends Helper {
12551255

12561256
if (store.debugMode) {
12571257
const previewElements = els.slice(0, 3)
1258-
let htmls = await Promise.all(
1259-
previewElements.map(async el => {
1260-
const html = await el.evaluate(node => node.outerHTML)
1261-
return (
1262-
html
1263-
.replace(/\n/g, '')
1264-
.replace(/\s+/g, ' ')
1265-
.substring(0, 100 / previewElements.length)
1266-
.trim() + '...'
1267-
)
1268-
}),
1269-
)
1270-
if (els.length > 3) {
1271-
htmls.push('...')
1272-
}
1273-
1258+
let htmls = await Promise.all(previewElements.map(el => elToString(el, previewElements.length)))
1259+
if (els.length > 3) htmls.push('...')
12741260
if (els.length > 1) {
12751261
this.debugSection(`Elements (${els.length})`, htmls.join('|').trim())
12761262
} else if (els.length === 1) {
12771263
this.debugSection('Element', htmls.join('|').trim())
12781264
} else {
1279-
this.debug('No elements found')
1265+
this.debug(`No elements found by ${JSON.stringify(locator).slice(0, 50)}....`)
12801266
}
12811267
}
12821268

@@ -1734,6 +1720,7 @@ class Playwright extends Helper {
17341720
const el = els[0]
17351721

17361722
await el.clear()
1723+
if (store.debugMode) this.debugSection('Focused', await elToString(el, 1))
17371724

17381725
await highlightActiveElement.call(this, el)
17391726

@@ -3447,6 +3434,7 @@ async function proceedClick(locator, context = null, options = {}) {
34473434
}
34483435

34493436
await highlightActiveElement.call(this, els[0])
3437+
if (store.debugMode) this.debugSection('Clicked', await elToString(els[0], 1))
34503438

34513439
/*
34523440
using the force true options itself but instead dispatching a click
@@ -3880,11 +3868,22 @@ async function saveTraceForContext(context, name) {
38803868
}
38813869

38823870
async function highlightActiveElement(element) {
3883-
if (this.options.highlightElement && global.debugMode) {
3871+
if ((this.options.highlightElement || store.onPause) && store.debugMode) {
38843872
await element.evaluate(el => {
38853873
const prevStyle = el.style.boxShadow
3886-
el.style.boxShadow = '0px 0px 4px 3px rgba(255, 0, 0, 0.7)'
3874+
el.style.boxShadow = '0px 0px 4px 3px rgba(147, 51, 234, 0.8)' // Bright purple that works on both dark/light modes
38873875
setTimeout(() => (el.style.boxShadow = prevStyle), 2000)
38883876
})
38893877
}
38903878
}
3879+
3880+
async function elToString(el, numberOfElements) {
3881+
const html = await el.evaluate(node => node.outerHTML)
3882+
return (
3883+
html
3884+
.replace(/\n/g, '')
3885+
.replace(/\s+/g, ' ')
3886+
.substring(0, 100 / numberOfElements)
3887+
.trim() + '...'
3888+
)
3889+
}

lib/pause.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ function pauseSession(passedObject = {}) {
6666
historySize: 50, // Adjust the history size as needed
6767
})
6868

69+
store.onPause = true
6970
rl.on('line', parseInput)
7071
rl.on('close', () => {
7172
if (!next) console.log('Exiting interactive shell....')
73+
store.onPause = false
7274
})
7375
return new Promise(resolve => {
7476
finish = resolve

lib/store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const store = {
99
timeouts: true,
1010
/** @type {boolean} */
1111
dryRun: false,
12-
12+
/** @type {boolean} */
13+
onPause: false,
1314
/** @type {CodeceptJS.Test | null} */
1415
currentTest: null,
1516
}

test/data/sandbox/features/step_definitions/my_steps.de.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Given('ich habe ein Produkt mit einem Preis von {int}$ in meinem Warenkorb', pri
44
I.addItem(parseInt(price, 10))
55
})
66

7-
Given('der Rabatt für Bestellungen über $\{int} beträgt {int} %', (maxPrice, discount) => {
7+
Given('der Rabatt für Bestellungen über ${int} beträgt {int} %', (maxPrice, discount) => {
88
I.haveDiscountForPrice(maxPrice, discount)
99
})
1010

test/data/sandbox/i18n/features/step_definitions/my_steps.de.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Given('ich habe ein Produkt mit einem Preis von {int}$ in meinem Warenkorb', pri
44
I.addItem(parseInt(price, 10))
55
})
66

7-
Given('der Rabatt für Bestellungen über $\{int} beträgt {int} %', (maxPrice, discount) => {
7+
Given('der Rabatt für Bestellungen über ${int} beträgt {int} %', (maxPrice, discount) => {
88
I.haveDiscountForPrice(maxPrice, discount)
99
})
1010

0 commit comments

Comments
 (0)