Snapshot Tests + Blinking Cursors
It was Friday morning and I was already annoyed. One of our snapshot tests was failing. Randomly. Totally fine one minute, failure city the next.
The snapshot was for a fairly benign login form. Present the view controller, call
becomeFirstResponder on the first text field. What could possibly go wrong?
Nothing in the test class seemed amiss. The build server was functioning normally. The test passed on my machine. Ready to give up, hours later, it finally dawned on me.
The cursor. The damn blinking cursor.
For those not familiar, calling
becomeFirstResponder on a UITextField immediately opens the keyboard and places a blinking cursor inside the text field. As it turns out, our snapshot test had been recorded when the cursor was visible. Well, maybe the build server was running a bit slower than usual, but that day the test ran when the cursor had blinked off. It was sheer luck we hadn’t run into it before.
Head, meet desk.