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:
@@ -207,16 +207,18 @@ function toAttributeMap(attributes?: string[]): Map<string, string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getStableRefFromAttributes(attributes: Map<string, string>): { value: string; attr: string } | null {
|
function getStableRefFromAttributes(attributes: Map<string, string>): { value: string; attr: string } | null {
|
||||||
const id = attributes.get('id')
|
// Test IDs first: they are explicitly placed by developers for automation
|
||||||
if (id) {
|
// and more stable than id which is often auto-generated by frameworks
|
||||||
return { value: id, attr: 'id' }
|
|
||||||
}
|
|
||||||
for (const attr of TEST_ID_ATTRS) {
|
for (const attr of TEST_ID_ATTRS) {
|
||||||
const value = attributes.get(attr)
|
const value = attributes.get(attr)
|
||||||
if (value) {
|
if (value) {
|
||||||
return { value, attr }
|
return { value, attr }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const id = attributes.get('id')
|
||||||
|
if (id) {
|
||||||
|
return { value: id, attr: 'id' }
|
||||||
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user