Search code examples
iosswiftcoded-ui-testsuiswitchuitest

Get UISwitch state/value in UITests


I'm working with a UISwitch, and I'm currently coding the UI Tests. The problem is that I don't know how to get the Switch value/state in these tests. In the program code, I can use mySwitch.isOn that returns true or false, but in the UI Tests I don't know how to get this value.

A little help in english correction would be appreciated.

Thanks!


Solution

  • Try this:

    let app = XCUIApplication()
    let mySwitch = app.switches["mySwitch"]
    let isOn = mySwitch.value as! String
    

    The current UISwitch.isOn value should then be reflected in the isOn variable above.