XCUITest Element Snapshot Fails Blinking Cursor

291 views Asked by At

We are using FBSnapshottestcase to take snapshots as part of our XCUITest cases. We have a ScrollView that has an UITextField. We type text into the text field and take a snapshot to verify the element behaves appropriately with text entered (a clear button appears). The problem we encounter is that when you type into the text field a blinking cursor appears. The tests will fail or pass depending on the state of the blinking cursor when the snapshot is taken. Is there a way to disable the blinking cursor for a XCUITest?

2

There are 2 answers

0
reutsey On BEST ANSWER

The devs added this to the AppDelegate file so that when we are running the test scheme it would do this:

#if LOCAL
     if CommandLine.arguments.contains("--UITests") {
        UITextField.appearance().tintColor = .clear
     }
#endif

This hide the cursor then for the tests.

You can then you app.launchArguments to pass "--UITests"

https://developer.apple.com/documentation/xctest/xcuiapplication/1500477-launcharguments

0
Roman Zakharov On

It is possible to set an optional parameter tolerance in FBSnapshotVerifyView call.

For example, if it is set to 0.01 and images are equal by 99% (counting in pixels) or more, then test will not fall.