Skip to content

chore: make count() work with _vue selectors #12899

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

Merged
merged 1 commit into from
Mar 19, 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
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class Selectors {
}

async _queryCount(frame: frames.Frame, info: SelectorInfo, scope?: dom.ElementHandle): Promise<number> {
const context = await frame._utilityContext();
const context = await frame._context(info.world);
const injectedScript = await context.injectedScript();
return await injectedScript.evaluate((injected, { parsed, scope }) => {
return injected.querySelectorAll(parsed, scope || document).length;
Expand Down
6 changes: 5 additions & 1 deletion tests/page/selectors-vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ for (const [name, url] of Object.entries(vues)) {

it('should work with single-root elements @smoke', async ({ page }) => {
expect(await page.$$eval(`_vue=book-list`, els => els.length)).toBe(1);
expect(await page.locator(`_vue=book-list`).count()).toBe(1);
await expect(page.locator(`_vue=book-list`)).toHaveCount(1);
expect(await page.$$eval(`_vue=book-item`, els => els.length)).toBe(3);
expect(await page.locator(`_vue=book-item`).count()).toBe(3);
await expect(page.locator(`_vue=book-item`)).toHaveCount(3);
expect(await page.$$eval(`_vue=book-list >> _vue=book-item`, els => els.length)).toBe(3);
expect(await page.locator(`_vue=book-list >> _vue=book-item`).count()).toBe(3);
expect(await page.$$eval(`_vue=book-item >> _vue=book-list`, els => els.length)).toBe(0);

});

it('should work with multi-root elements (fragments)', async ({ page }) => {
Expand Down