Skip to content

Commit d18f660

Browse files
chore: fix AUT discovery if frame name is not present (#32154)
* chore: fix issues with AUT discovery if for any reason the name is not present * Update packages/server/lib/browsers/cdp_automation.ts Co-authored-by: Jennifer Shehane <[email protected]> --------- Co-authored-by: Jennifer Shehane <[email protected]>
1 parent 5896795 commit d18f660

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

packages/server/lib/browsers/cdp_automation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,13 @@ export class CdpAutomation implements CDPClient, AutomationMiddleware {
492492
}
493493

494494
if (!frame) {
495-
throw new Error('Could not find AUT frame')
495+
// if for whatever reason we cannot identify the AUT frame by name, we will fall back to the first child frame that exists.
496+
// The first child frame should always be the AUT frame, followed by the spec frame
497+
if (frameTree?.childFrames?.[0]) {
498+
frame = frameTree.childFrames[0]
499+
} else {
500+
throw new Error('Could not find AUT frame')
501+
}
496502
}
497503

498504
return frame.frame

packages/server/test/unit/browsers/cdp_automation_spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,46 @@ context('lib/browsers/cdp_automation', () => {
802802
})
803803
})
804804

805+
it('does not throw if the AUT frame cannot be found by name', async function () {
806+
this.sendDebuggerCommand.withArgs('Page.getFrameTree').resolves({
807+
frameTree:
808+
{
809+
childFrames: [
810+
{
811+
frame: {
812+
id: '1',
813+
name: '123456789',
814+
url: 'http://localhost:3500/fixtures/dom.html',
815+
},
816+
},
817+
],
818+
},
819+
})
820+
821+
this.sendDebuggerCommand.withArgs('Runtime.evaluate').resolves({
822+
result: {
823+
type: 'string',
824+
value: 'mock title',
825+
},
826+
})
827+
828+
// @ts-expect-error
829+
cdpAutomation.executionContexts.set(123, {
830+
auxData: {
831+
frameId: '1',
832+
},
833+
})
834+
835+
const resp = await this.onRequest('get:aut:title')
836+
837+
expect(resp).to.equal('mock title')
838+
839+
expect(this.sendDebuggerCommand).to.be.calledWith('Runtime.evaluate', {
840+
expression: 'window.document.title',
841+
contextId: 123,
842+
})
843+
})
844+
805845
it('fails if the frame cannot be found', async function () {
806846
expect(this.onRequest('get:aut:title')).to.be.rejectedWith('Could not find AUT frame')
807847
})

0 commit comments

Comments
 (0)