Skip to content

Commit

Permalink
fix: check for visibility of the last selected element only
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Aug 3, 2022
1 parent 87f1b08 commit 34ecf5d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/PuppeteerRunnerExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,11 @@ async function waitForSelector(
if (!selector.length) {
throw new Error('Empty selector provided to `waitForSelector`');
}
let handle = await frame.waitForSelector(selector[0]!, options);
let isLastPart = selector.length === 1;
let handle = await frame.waitForSelector(selector[0]!, {
...options,
visible: isLastPart && options.visible
});
for (const part of selector.slice(1, selector.length)) {
if (!handle) {
throw new Error('Could not find element: ' + selector.join('>>'));
Expand All @@ -566,7 +570,11 @@ async function waitForSelector(
el.shadowRoot ? el.shadowRoot : el
);
handle.dispose();
handle = await innerHandle.waitForSelector(part, options);
isLastPart = selector[selector.length - 1] === part;
handle = await innerHandle.waitForSelector(part, {
...options,
visible: isLastPart && options.visible
});
innerHandle.dispose();
}
if (!handle) {
Expand Down
20 changes: 20 additions & 0 deletions test/resources/invisible-parent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<style>
.parent {
width: 0;
height: 0;
top: 0;
left: 0;
position: absolute;
}
.child {
position: absolute;
width: 50px;
height: 50px;
}
</style>

<div class="parent">
<button class="child">
test
</button>
</div>
22 changes: 22 additions & 0 deletions test/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ describe('Runner', () => {
await runner.run();
});

it('should be able to click elements inside invisible parents', async () => {
const runner = await createRunner(
{
title: 'test',
steps: [
{
type: 'navigate',
url: `${HTTP_PREFIX}/invisible-parent.html`,
},
{
type: 'click',
selectors: [['.parent', '.child']],
offsetX: 1,
offsetY: 1,
},
],
},
new PuppeteerRunnerExtension(browser, page)
);
await runner.run();
});

it('should be able to replay click steps on checkboxes', async () => {
const runner = await createRunner(
{
Expand Down

0 comments on commit 34ecf5d

Please sign in to comment.