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

fix: check for visibility of the last selected element only #241

Merged
merged 1 commit into from
Aug 3, 2022
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
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
18 changes: 18 additions & 0 deletions test/resources/invisible-parent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<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