From 93f1f16d540744b3b74c170e2fd4f05e8989b754 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 16 Feb 2023 18:44:46 +0100 Subject: [PATCH] fix: find the svg owner element --- src/PuppeteerRunnerExtension.ts | 8 +++++++- test/runner.test.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/PuppeteerRunnerExtension.ts b/src/PuppeteerRunnerExtension.ts index 27aa9724..917271fe 100644 --- a/src/PuppeteerRunnerExtension.ts +++ b/src/PuppeteerRunnerExtension.ts @@ -545,14 +545,20 @@ async function scrollIntoViewIfNeeded( if (intersectionTarget) { await waitForInViewport(intersectionTarget, timeout); } + await intersectionTarget.dispose(); + if (intersectionTarget !== element) { + await element.dispose(); + } } async function getOwnerSVGElement( handle: ElementHandle ): Promise> { + // If there is no ownerSVGElement, the element must be the top-level SVG + // element itself. return await handle.evaluateHandle((element) => { /* c8 ignore start */ - return element.ownerSVGElement!; + return element.ownerSVGElement ?? (element as SVGSVGElement); /* c8 ignore stop */ }); } diff --git a/test/runner.test.ts b/test/runner.test.ts index b827e3ca..19334593 100644 --- a/test/runner.test.ts +++ b/test/runner.test.ts @@ -182,7 +182,7 @@ describe('Runner', () => { ); }); - it('should be able to replay click steps on SVG path elements', async () => { + it('should be able to replay click steps on SVG elements', async () => { const runner = await createRunner( { title: 'test', @@ -197,6 +197,12 @@ describe('Runner', () => { offsetX: 1, offsetY: 1, }, + { + type: StepType.Click, + selectors: ['svg'], + offsetX: 1, + offsetY: 1, + }, ], }, new PuppeteerRunnerExtension(browser, page)