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 {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user