Skip to content

Commit b01f6ec

Browse files
authored
test: add a test for css selector being relative to the root handle (#5789)
1 parent 7706e5a commit b01f6ec

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

test/selectors-css.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,17 @@ it('should work with :scope', async ({page, server}) => {
374374
expect(await scope.$$eval(`css=* ~ :scope`, els => els.length)).toBe(0);
375375
}
376376
});
377+
378+
it('css on the handle should be relative', async ({ page }) => {
379+
await page.setContent(`
380+
<span class="find-me" id=target1>1</span>
381+
<div>
382+
<span class="find-me" id=target2>2</span>
383+
</div>
384+
`);
385+
expect(await page.$eval(`.find-me`, e => e.id)).toBe('target1');
386+
387+
const div = await page.$('div');
388+
expect(await div.$eval(`.find-me`, e => e.id)).toBe('target2');
389+
expect(await page.$eval(`div >> .find-me`, e => e.id)).toBe('target2');
390+
});

test/selectors-misc.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,17 @@ it('xpath should be relative', async ({ page }) => {
214214
expect(await page.$eval(`div >> //*[@class="find-me"]`, e => e.id)).toBe('target2');
215215
expect(await page.$eval(`div >> xpath=/*[@class="find-me"]`, e => e.id)).toBe('target2');
216216
});
217+
218+
it('data-testid on the handle should be relative', async ({ page }) => {
219+
await page.setContent(`
220+
<span data-testid="find-me" id=target1>1</span>
221+
<div>
222+
<span data-testid="find-me" id=target2>2</span>
223+
</div>
224+
`);
225+
expect(await page.$eval(`data-testid=find-me`, e => e.id)).toBe('target1');
226+
227+
const div = await page.$('div');
228+
expect(await div.$eval(`data-testid=find-me`, e => e.id)).toBe('target2');
229+
expect(await page.$eval(`div >> data-testid=find-me`, e => e.id)).toBe('target2');
230+
});

0 commit comments

Comments
 (0)