4

I've been able to find the following KIF method for setting the value of a UISwitch:

tester.setOn(false, forSwitchWithAccessibilityLabel: "Enable Feature")

However, I have been unable to figure out how to retrieve the value of a UISwitch, using KIF, in an assert/test approach.

Any ideas?

Albert Bori
  • 9,832
  • 10
  • 51
  • 78

2 Answers2

3

The waitForViewWithAccessibilityLabel returns a view. So how about this?

let view = tester().waitForViewWithAccessibilityLabel("Enable Feature")
let switchView = view as? UISwitch
XCTAssertNotNil(switchView)
XCTAssertTrue(switchView!.on) // or XCTAssertFalse(switchView!.on)
Hiron
  • 1,457
  • 1
  • 13
  • 12
2

I figured it out:

To test for switch on:

tester.waitForViewWithAccessibilityLabel("Enable Feature", value: "1", traits: UIAccessibilityTraitNone)

To test for switch off:

tester.waitForViewWithAccessibilityLabel("Enable Feature", value: "0", traits: UIAccessibilityTraitNone)
Albert Bori
  • 9,832
  • 10
  • 51
  • 78