Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better view for pause mode #4718

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}....`)
}
}

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() + '...'
)
}
2 changes: 2 additions & 0 deletions lib/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const store = {
timeouts: true,
/** @type {boolean} */
dryRun: false,

/** @type {boolean} */
onPause: false,
/** @type {CodeceptJS.Test | null} */
currentTest: null,
}
Expand Down
2 changes: 1 addition & 1 deletion test/data/sandbox/features/step_definitions/my_steps.de.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
Loading