Why Your UI Tests Break Every Sprint (And How to Fix It for Good)
You push a design update. The button still works. The user flow is unchanged. But your CI is red. Sound familiar? This is the daily reality for teams whose test suites are built on CSS selectors. S...

Source: DEV Community
You push a design update. The button still works. The user flow is unchanged. But your CI is red. Sound familiar? This is the daily reality for teams whose test suites are built on CSS selectors. Someone renames .btn-primary to .btn-primary-v2, restructures a form, or swaps a<div>for a <section> — and suddenly 60 tests fail. Not because anything is broken. Because the tests were looking for the wrong thing. The Root Cause: Tests That Know Too Much When you write a selector like this: document.querySelector('#checkout > div:nth-child(3) > input.form-control') you're not describing what the user experiences. You're describing how a developer happened to structure the DOM on a particular Tuesday. That's a snapshot, not a contract. The Fix: Test What the User Sees Modern testing best practice flips the model: target elements by ARIA role and visible text, not by class names or DOM position. // Fragile ❌ cy.get('.btn-primary-v2').click() // Resilient ✅ cy.findByRole('butto