pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.68k stars 556 forks source link

ClearButton from UITextField is not recorded with iOS 17 #804

Open GHMarcus opened 8 months ago

GHMarcus commented 8 months ago

Describe the bug

Snapshotting a filled UITextField with an iOS 17 Simulator didn't record the ClearButton at the end of the text field anymore.

To Reproduce

  1. Methode:

    • Simply create a single ViewController with an UITextField in it.
    • Set the clearButtonMode from the text field to .always.
    • Write a test for this controller where you first set a value to the text field befor snapshotting it.
    • iOS 16 test devices will capture the filled text field with clear button
    • iOS 17 test devices will capture the filled text field without clear button
  2. Methode:

    • Use the attached sample project where I prepared the test scenario. In this test project there are 4 recorded snapshots. Empty and Filled states for iOS 16 and 17. They are recorded with an iPhone 14 and when you use an iOS 16 iPhone 14 and run all test both will succeed. When you run the tests with an iOS 17 iPhone 14 the second one (FilledAppearance) will fail.
    • TextInputBug.zip

Expected behavior

Environment

Additional context

Some strange behaviour I ran into when debugging this bug:

mat1th commented 5 months ago

Hi @GHMarcus, I'm facing the same issue. Did you find a work around for this?

GHMarcus commented 5 months ago

@mat1th Kind of, we ended up checking of we are running inside the Unit-Tests and setting clearButtonMode to .never for this cases.

For some search bars inside of our app it looks like this

if NSClassFromString("XCTest") != nil {
   searchBar.searchTextField.clearButtonMode = .never
}

Hope this will help you.

mat1th commented 5 months ago

Hi @GHMarcus, thank you. Will try out if this also is a solution for me.