I am making a "before each" step and I am wanting to do steps to logout. I can't find anything about checking if an element exists before I try to touch it, then if it doesn't exist do something else. Is it possible to do this with KIF without having a reference to the object I want to check for?
Something like:
if([tester elementExistsWithAccesibilityLabel:@"backButton"])
{
[tester tapViewWithAccessibilityLabel:@"backButton"];
}
else
{
[tester tapViewwithAccesibilityLabel:@"Logout"];
}
In case anyone is still looking for an answer, there is a family of methods in KIF that does just that
KIFUITestActor-ConditionalTests.h
:If you're using the Accessibility Identifier additions (
pod 'KIF/IdentifierTests'
) there's also the very handy equivalent method:- (BOOL) tryFindingViewWithAccessibilityIdentifier:(NSString *) accessibilityIdentifier;
I would suggest to try this approach:
For swift 3:
Alright, none of these worked for me... However I have a solution
Checkout this gist.
What I've done is taken KIF's code and just removed their error checking - works like a charm for me.
This won't fail your tests when it can't find an element!
These methods do the trick. Add them to a category for KIFUITestActor.
It works for me very well.
If using the Swift you can simply use the
viewTester().tryFindingView()
: