Switch value on XCUITest in Settings app not working anymore with Xcode 11

Hello,


Since Xcode 11, getting value from a UISwitch in Settings app with XCUITest is not working anymore with iOS 12 devices.

For example, going on the Notification settings, I would like to check some switch values.


            let switchSounds = settingsApp.switches["Sounds"]
            let expectedValue = isEnabled ? "1" : "0"
            XCTAssert(switchSounds.value as? String == expectedValue)


The switchSounds is found but its value is nil. It was working before and it still works on the app I run my other tests on.


Is there any workaround I can use ? I tried using isSelected but it's not working either.

This issue is actual for all switches, not only for "com.apple.Preferences"

same here!

I just tested this issue with the latest xcode 11.3 release, same problem...

Have the same issue on iOS 11 device. Did you find any solutions?

We are seeing this same issue. We build with Xcode 11 and target iOS 11 - iOS 13 devices. We run our tests on FTL (which doesn't yet support iOS 13) and have found that we can no longer toggle switches on previous iOS versions. Has anybody filed a bug with  on this yet? I have opened FB7555409 to report this issue.


Ryan

I am still seeing this with Xcode 12.3 on iOS 12.4.1 devices. Anybody find a workaround?

Also ran into this very strange bug, also only on iOS 12.x. I found a workaround I've not seen posted here or on https://stackoverflow.com/questions/62413398/xcuitest-ios-12-switch-element-value-is-on when I was frustrated and searching for a solution.

It seems this issue appears only when referencing the switch element using the array style format. You can workaround by instead using the matching method of the XCUIElementQuery and - at least in my testing - the bug will not appear.

Here's the workaround applied to the original example:

let switchPredicate = NSPredicate(format:"(label MATCHES[c] %@)", "Sounds")
let switchSounds = settingsApp.switches.matching(switchPredicate).firstMatch
let expectedValue = isEnabled ? "1" : "0"
XCTAssert(switchSounds.value as? String == expectedValue)
Switch value on XCUITest in Settings app not working anymore with Xcode 11
 
 
Q