With Xcode 13 and iOS 15, the standard typeText method became incredibly slow. So slow that I created an alternative using the pasteboard. This proved flaky and needed support code in order to succeed reliably (and it did):

It was marginally faster, but when I’m doing the same thing hundreds or thousands of times seconds add up.

Having read a recent StackOverflow answer to something somewhat related that suggested tapping the software keyboard one key at a time, I came up with the idea “Maybe if I type a single key at a time it’ll work around the bug with typing it all quickly?” Today I decided to do some benchmarking with the three methods (standard/bugged, paste/flaky/slow if not flaky, one key at a time/new). Note: The answer on that question linked is bad – the function suggested does not exist and the only thing close, typeKey is for modifying key presses with special keys (CTRL, FN, Shift, etc.).

To my surprise, Apple fixed the bug (it was in iOS, not Xcode)! If you’re ever questioning the most efficient way to type text in XCUITest, go with the standard method as of this date. Also a surprise was how much not slower typing a single key at a time was – my machine was definitely doing more work (as evidenced by debug output, but that difference is likely within margin of error). ?

Results from running a sample test with two text fields twenty times:

Method Measurement
typeText() baseline
typeText() one key at a time 3% slower
Kluge paste method 43% slower