fix: ensure selector parser falls back to CSS (#12585)

This commit is contained in:
Alex Rudenko 2024-06-14 11:14:33 +02:00 committed by GitHub
parent 772e088f9c
commit 80783fef5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 8 deletions

View File

@ -52,17 +52,25 @@ export function getQueryHandlerAndSelector(selector: string): {
}
}
}
const [pSelector, isPureCSS, hasPseudoClasses] = parsePSelectors(selector);
if (isPureCSS) {
try {
const [pSelector, isPureCSS, hasPseudoClasses] = parsePSelectors(selector);
if (isPureCSS) {
return {
updatedSelector: selector,
selectorHasPseudoClasses: hasPseudoClasses,
QueryHandler: CSSQueryHandler,
};
}
return {
updatedSelector: JSON.stringify(pSelector),
selectorHasPseudoClasses: hasPseudoClasses,
QueryHandler: PQueryHandler,
};
} catch {
return {
updatedSelector: selector,
selectorHasPseudoClasses: hasPseudoClasses,
selectorHasPseudoClasses: false,
QueryHandler: CSSQueryHandler,
};
}
return {
updatedSelector: JSON.stringify(pSelector),
selectorHasPseudoClasses: hasPseudoClasses,
QueryHandler: PQueryHandler,
};
}

View File

@ -358,12 +358,22 @@ describe('Query handler tests', function () {
})
).toBeTruthy();
using root = await page.$('div');
using button = await root!.$('& > button');
assert(button, 'Could not find element');
expect(
await button.evaluate(element => {
return element.id === 'b';
})
).toBeTruthy();
// Should parse more complex CSS selectors. Listing a few problematic
// cases from bug reports.
for (const selector of [
'.user_row[data-user-id="\\38 "]:not(.deactivated_user)',
`input[value='Search']:not([class='hidden'])`,
`[data-test-id^="test-"]:not([data-test-id^="test-foo"])`,
`& > table`,
]) {
await page.$$(selector);
}