Cursor tests fail after a code change: locator, regression or stale spec
By Sophie Adams Updated 11 min read
On this page (9 sections)
- The short version
- Why it happens: the three causes, most likely first
- Check 1: is the locator broken? Compare the selector to the new markup
- Check 2: is it a real regression? Test the app against the git diff
- Check 3: is the spec stale? Read the test file's own git history
- Why rerunning the Cursor prompt first usually hides the real defect
- When to hand-edit the test versus regenerate it
- How to stop it happening again
- Questions people still ask
In short: When Cursor AI test automation fails after code changes, check for a broken locator, an app regression, or a stale spec. Compare selectors with new markup, run the test locally and in CI, then inspect the last passing version before editing or regenerating anything.
Part of our guide on how to audit affiliate site seo without manual checks
Most post-change test failures are the test's fault, not the code's – and rerunning the prompt is how you lose the evidence.
| Failure classes | Three: locator, regression, stale spec |
|---|---|
| First check | Locator against new markup |
| Second check | App behaviour against git diff |
| Third check | Test file's git history |
| Worst habit | Rerunning the Cursor prompt first |
| Typical diagnosis time | 5-10 minutes with a fixed order |
The short version
- Classify first: locator, regression or stale spec – never rewrite the prompt before you know which one it is.
- A broken locator fails while the app works; a regression fails while the app is broken; a stale spec fails while both look fine.
- Check in order: locator against new markup, app against git diff, spec against its own git history.
- Rerunning the Cursor prompt first overwrites the failing test and destroys the evidence you need.
- Hand-edit locator and assertion fixes; regenerate only when the test no longer describes real behaviour.
Why it happens: the three causes, most likely first
When Cursor writes or maintains your test suite, a code change can break tests in three distinct ways. Most failures are not bugs in your app at all. They are the test's view of the app going out of date.
The most common cause is a broken locator. Cursor generated a selector – an ID, a class, a text match – and your change renamed, moved or restructured that element. The app works fine; the test can no longer find it.
Second most common is a genuine regression. Your change really did break behaviour, and the test is correctly reporting it. This is the outcome you want tests to catch, and it is the one people most often accidentally erase.
Third is the stale generated spec. Cursor rewrote or regenerated a test at some point, and the new version asserts something the app never promised – old copy, a removed field, a flow that changed on purpose. The test was already wrong; the change just exposed it. People in this spot often ask about sheets integration stops syncing after column changes as well.
The danger is that all three look identical in a red test run: an error, a stack trace, a timeout. Sorting them takes about five minutes if you check in the right order.
- Broken locator: element renamed, moved or restyled; app behaves correctly.
- Genuine regression: the change broke real behaviour; test is right to fail.
- Stale spec: a regenerated test asserts behaviour that no longer exists by design.
- All three produce the same red output, which is why order matters.
Check 1: is the locator broken? Compare the selector to the new markup
Start here because it is the fastest check and the most common answer. Open the failing test, find the selector or locator, then open the component or template your change touched and look for that same element.
If the class name changed, the ID disappeared, or the text was reworded, you have a broken locator. The app did nothing wrong – your test was pointing at a signpost that moved. Before you commit to anything, it is worth looking at testing wordpress api problems.
The clean way to confirm: run the app locally, perform the action the test covers by hand, and inspect the element in the browser. If the element is there and behaves correctly, the test's view of it is what broke.
The tell that this check worked: a one-line fix – update the selector to match the new markup – and the test goes green without touching any application code.
A related variant: Cursor sometimes targets generated or unstable class names. If the locator matches today but breaks every few changes, that is a locator design problem, not a one-off. Prefer stable attributes – roles, labels, data-test attributes – over styling classes. People in this spot often ask about choosing prompt stores with branching as well.
- Open the failing test and copy the exact locator text.
- Search the changed files for that class, ID or label.
- Run the app by hand and inspect the element in the browser.
- If the element exists and works, update the locator to the new markup.
- Rerun the single test – green means done.
Check 2: is it a real regression? Test the app against the git diff
If the locator still matches the markup, suspect your code before your test. Run git diff against the last commit where the suite passed, and read what actually changed in application behaviour.
Then reproduce the failing step manually. Click the flow the test automates: submit the form, load the page, follow the journey. If it genuinely misbehaves – the button does nothing, the value is wrong, the state never updates – the test is doing its job and you have a regression.
This is the one outcome where the correct fix lives in your application code, not in the test. Fix the app, rerun the test, and it should pass unchanged. A test you had to weaken to make green is a regression you just hid. If that sounds like your situation, read up on understanding update timing next.
Watch for a subtle version of this: the app works, but the change altered behaviour the test legitimately pinned down – a new validation rule, a redirect, a price format. That is a deliberate behaviour change, and the assertion is allowed to be updated once, consciously, to match the new agreed behaviour.
The tell that this check worked: the manual reproduction fails the same way the test does, and fixing the app turns the test green with no edits to the test file.
Check 3: is the spec stale? Read the test file's own git history
If the locator matches and the app behaves, look at the test itself. Run git log on the failing test file. If Cursor regenerated it recently – a rewrite with changed assertions, reworded expectations or a different flow – you may be looking at a spec that no longer describes real behaviour. If that sounds like your situation, read up on cron job logs on cPanel next.
Compare the current version against the last version that passed. Look for assertions about copy, layout or fields that were removed on purpose. AI-regenerated tests drift like this because the model reconstructs what the test 'probably' checked rather than preserving each assertion exactly.
A stale spec has a signature: the app is fine, the locator is fine, but the expectation is about something the product no longer has. Old button text, a deprecated endpoint, a step order that was redesigned weeks ago.
The tell that this check worked: restoring or hand-editing the assertion to match agreed current behaviour turns the test green, and you can name the product decision that made the old expectation wrong.
If you cannot name that decision, stop. The stale spec may be the only record of intended behaviour, and silently updating it is how suites rot.
| Check | What you compare | Failure class if it explains the red |
|---|---|---|
| 1. Locator vs markup | Test selector against current component markup | Broken locator |
| 2. App vs git diff | Manual behaviour against recent code changes | Genuine regression |
| 3. Spec vs its history | Current test assertions against the last passing version | Stale generated spec |
Why rerunning the Cursor prompt first usually hides the real defect
The tempting move after a red run is to paste the failure back into Cursor and let it fix the test. That feels productive. It is usually the most expensive thing you can do.
When you rerun a prompt, the model regenerates the test from the current failure message. It cannot see why the test originally existed, so it optimises for one thing: making this run pass. A broken locator gets patched to whatever element happens to be on the page now. A genuine regression gets an assertion quietly deleted or loosened.
The result is a suite that is green and says nothing. Every regression the old test would have caught is now invisible, and you find out from users instead of CI.
There is a second cost: evidence. The failing test, before regeneration, is your record of intended behaviour. Once it is overwritten, you cannot diff it, cannot see what the assertion used to be, and cannot tell a deliberate change from an accidental one.
The order exists for exactly this reason. Classify first, fix second, regenerate last – and only when the test no longer describes real behaviour at all.
When to hand-edit the test versus regenerate it
The rule is simple: small, mechanical fixes get hand-edited; tests that no longer describe reality get regenerated. Most failures are the first kind.
Hand-edit when the fix is a locator update, a text change, a wait adjustment or a deliberate assertion update you can justify in one sentence. These edits are two lines. Regenerating for them risks losing the other assertions in the test, which is the drift problem from check 3.
Regenerate only when the test's whole premise is gone: the flow was redesigned, the feature was rebuilt, or the test grew into an unmaintainable script nobody understands. Then regenerate deliberately – review the new test line by line before you accept it, the way you would review a pull request from a new colleague.
After any regeneration, diff the new test against the old one and confirm every original assertion either survives or has a named reason for its removal. That single habit is what keeps an AI-maintained suite honest.
- Hand-edit: locator, text, wait, one justified assertion change.
- Regenerate: flow redesigned, feature rebuilt, test unreadable.
- Always: review regenerated tests assertion by assertion.
- Always: git commit the old failing test before replacing it.
How to stop it happening again
The fixes above work once. Three small habits make the whole cycle rare.
First, ask Cursor to generate locators from stable attributes only: roles, accessible labels, or explicit data-test attributes you add to components. Styling classes and auto-generated IDs change constantly; semantic attributes survive refactors.
Second, keep test changes in their own commits, separate from application changes. When a run goes red after a change, git log tells you in seconds whether the test was touched at the same time – which is usually the stale-spec signature.
Third, when a behaviour change is deliberate, update the test in the same commit and say why in the message. Future you, staring at a red run, should never have to guess whether the old assertion was right.
With that in place, a post-change failure usually resolves in one of two ways: a thirty-second locator fix, or a genuine bug you caught before shipping. Both are the suite working.
- Add stable data-test or role attributes to components you change often.
- Instruct Cursor to prefer those attributes when generating tests.
- Commit test edits separately from feature code.
- Document deliberate behaviour changes in the commit that updates assertions.
- Review any regenerated test assertion by assertion before merging.
Questions people still ask
How do I tell a broken locator from a real regression in under a minute?
Open the app and do the step the test covers by hand. If the app behaves correctly but the test cannot find the element, it is a locator. If the app misbehaves the same way the test reports, it is a regression.
What order should I check the three failure classes in?
Locator against the new markup first, because it is the most common and fastest to confirm. Then app behaviour against your git diff. Last, the test file's own git history for signs Cursor regenerated it. Checking in this order means you never rewrite a test that was right.
Why shouldn't I just rerun the Cursor prompt on a failing test?
Regeneration optimises for a green run, not for correct assertions, so it can silently delete or weaken checks that were catching a real bug. It also overwrites the failing test, destroying the evidence you need to classify the failure. Diagnose first, regenerate only as a last resort.
When is regenerating a test the right call?
When the underlying flow or feature was redesigned and the test no longer describes real behaviour at all. For small fixes – a locator, a label, a deliberate assertion change – hand-edit instead, and review any regenerated test line by line before accepting it.
The test passes locally but fails in CI after the change. Which class is it?
Usually environment or timing rather than a stale spec: missing test data, a slower page load, or a different browser build. Fix flakiness with explicit waits on visible elements rather than fixed sleeps, and only then classify it against the three checks above.