From 8ef3b2177637925af39dfb903a24cacd0349940e Mon Sep 17 00:00:00 2001 From: "Tommy D. Rossi" Date: Sat, 7 Feb 2026 09:25:28 +0100 Subject: [PATCH] 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. --- playwriter/src/aria-snapshot.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/playwriter/src/aria-snapshot.ts b/playwriter/src/aria-snapshot.ts index d043d0d..f22ece5 100644 --- a/playwriter/src/aria-snapshot.ts +++ b/playwriter/src/aria-snapshot.ts @@ -207,16 +207,18 @@ function toAttributeMap(attributes?: string[]): Map { } function getStableRefFromAttributes(attributes: Map): { 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 }