Josep Bernad Espinosa
Josep Bernad Espinosa

Reputation: 87

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!

Upvotes: 2

Views: 3264

Answers (1)

Paulo Mattos
Paulo Mattos

Reputation: 19339

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.

Upvotes: 6

Related Questions