In my iOS app I've added UI tests, where I need to check if navigationBar button is enabled/disabled at different point of time.
Currently I'm using:
XCUIElement* saveButton = self.app.navigationBars[@"TSSIDAddCardView"].buttons[@"Save"];
XCTAssertEqual(saveButton.hittable, YES);
However, this always returns YES. The .exists test returns YES as well.
Does anyone knows how to do the proper test?
XCUIElement
conforms to XCUIElementAttributes
, which provides @property(readonly, getter=isEnabled) BOOL enabled;
.
So you can just do this on your XCUIElement* saveButton
:
Objective-C
XCTAssertEqual(saveButton.enabled, YES);
Swift
XCTAssertEqual(saveButton.isEnabled, true)
You can get the actual UI component via the value
property.
With that you can check if it is enabled or not.
Something like:
UIBarButtonItem *saveButton = self.app.navigationBars[@"TSSIDAddCardView"].buttons[@"Save"].value;
XCTAssertTrue(saveButton.enabled);
So with help of @InsertWittyName I found the solution:
UIBarButtonItem *saveButton = self.app.navigationBars[@"TSSIDAddCardView"].buttons[@"Save"];
XCTAssertFalse(saveButton.enabled);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With