fix: prioritize test IDs over id attribute in aria snapshot refs

getStableRefFromAttributes checked id before data-testid, opposite of
what getRefsForLocators does. Now both are consistent: test IDs first,
id second. Test IDs are developer-intentional and stable, id is often
auto-generated by frameworks.
This commit is contained in:
Tommy D. Rossi
2026-02-07 09:25:28 +01:00
parent e851adfcb6
commit 8ef3b21776
+6 -4
View File
@@ -207,16 +207,18 @@ function toAttributeMap(attributes?: string[]): Map<string, string> {
}
function getStableRefFromAttributes(attributes: Map<string, string>): { value: string; attr: string } | null {
const id = attributes.get('id')
if (id) {
return { value: id, attr: 'id' }
}
// Test IDs first: they are explicitly placed by developers for automation
// and more stable than id which is often auto-generated by frameworks
for (const attr of TEST_ID_ATTRS) {
const value = attributes.get(attr)
if (value) {
return { value, attr }
}
}
const id = attributes.get('id')
if (id) {
return { value: id, attr: 'id' }
}
return null
}