Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 910
Josep Bernad Espinosa Avatar asked Mar 10 '26 18:03

Josep Bernad Espinosa


1 Answers

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.

like image 119
Paulo Mattos Avatar answered Mar 12 '26 07:03

Paulo Mattos