Albert Bori
Albert Bori

Reputation: 10012

How to check/test value of a UISwitch using KIF?

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?

Upvotes: 4

Views: 898

Answers (2)

Hiron
Hiron

Reputation: 1487

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)

Upvotes: 3

Albert Bori
Albert Bori

Reputation: 10012

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)

Upvotes: 2

Related Questions