Skip to content

Commit f1c5875

Browse files
DavertMikclaude
andcommitted
test(webapi): cover grabAriaSnapshot across helpers; honor elementIndex in CDP snapshot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bc472ae commit f1c5875

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎lib/helper/CDPBrowser.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { assembleApng, isPng } from './extras/apngAssembler.js'
3939
* @prop {object} [headers={}] - headers sent when connecting to the endpoint, e.g. for authenticated remote browsers.
4040
* @prop {string} [input=auto] - how actions are dispatched: `cdp` (real mouse and keyboard events) or `synthetic` (DOM events). `auto` picks `cdp` when the browser renders layout.
4141
* @prop {string|boolean} [xpathPolyfill=auto] - inject an XPath polyfill for browsers with incomplete XPath support. `auto` detects when it is needed.
42-
* @prop {object} [capabilities={}] - browser capabilities (`layout`, `xpath`, `screenshot`, `video`, `innerText`) to use instead of detecting them at runtime.
42+
* @prop {object} [capabilities={}] - browser capabilities (`layout`, `xpath`, `screenshot`, `video`, `innerText`, `aria`) to use instead of detecting them at runtime.
4343
* @prop {number} [waitForTimeout=5] - default timeout for wait* actions, in seconds.
4444
* @prop {number} [waitForAction] - fixed delay after each action, in milliseconds. When unset, actions wait only for the navigation they trigger.
4545
* @prop {number} [pollInterval=25] - interval between checks while waiting, in milliseconds.
@@ -776,7 +776,7 @@ class CDPBrowser extends Helper {
776776
const { found } = await this._run(candidates, 'count')
777777
if (!found) throw new ElementNotFound(locator)
778778
const scope = this.withinCandidates ? [this.withinCandidates] : null
779-
const expression = `window.__codecept.run(${JSON.stringify(candidates)}, 'element', null, ${JSON.stringify(scope)}, null).result`
779+
const expression = `window.__codecept.run(${JSON.stringify(candidates)}, 'element', null, ${JSON.stringify(scope)}, ${JSON.stringify(this._selectionDescriptor())}).result`
780780
const { result } = await this.cdp.send('Runtime.evaluate', { expression }, this.sessionId)
781781
const { node } = await this.cdp.send('DOM.describeNode', { objectId: result.objectId }, this.sessionId)
782782
const { nodes } = await this.cdp.send('Accessibility.getFullAXTree', {}, this.sessionId)

‎test/helper/webapi.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,27 @@ export function tests() {
15501550
})
15511551
})
15521552

1553+
describe('#grabAriaSnapshot', () => {
1554+
beforeEach(function () {
1555+
if (!I.grabAriaSnapshot || I.capabilities?.aria === false) this.skip()
1556+
})
1557+
1558+
it('should grab the ARIA snapshot of the page', async () => {
1559+
await I.amOnPage('/form/field')
1560+
const snapshot = await I.grabAriaSnapshot()
1561+
assert.match(snapshot, /^- /m)
1562+
assert.ok(snapshot.includes('textbox'), snapshot)
1563+
assert.ok(snapshot.includes('button'), snapshot)
1564+
})
1565+
1566+
it('should grab the ARIA snapshot of an element', async () => {
1567+
await I.amOnPage('/info')
1568+
const snapshot = await I.grabAriaSnapshot('form')
1569+
assert.ok(snapshot.includes('textbox'), snapshot)
1570+
assert.ok(!snapshot.includes('Information'), snapshot)
1571+
})
1572+
})
1573+
15531574
describe('#saveScreenshot', () => {
15541575
beforeEach(function () {
15551576
if (I.capabilities?.screenshot === false) this.skip() // no rendering engine, screenshots are unsupported

0 commit comments

Comments
 (0)