Closed iwasrobbed closed 6 years ago
+1 I encountered same issue with UITextField which has gesture recognizer
currently I'm using this workaround:
- (void)tapMiddlePoinInViewWithAccessibilityLabel:(NSString *)label {
UIView *view = [tester waitForViewWithAccessibilityLabel:label];
CGPoint middlePointOnScreen = [view convertPoint:CGPointMake(view.bounds.size.width / 2.0, view.bounds.size.height / 2.0) toView:nil];
[tester tapScreenAtPoint:middlePointOnScreen];
}
@iwasrobbed, do you have a suggested fix?
@phatmann It might be best to check the editable
state before checking if first responder since it only makes sense if it's editable anyways. If it's not editable, a tap screen at point could be done. FWIW, we thankfully removed this behavior from our app so I don't have this issue any more.
This strikes me as an iOS bug. canBecomeFirstResponder
is returning YES even though the field is not editable. I suppose one fix is to implement a new method called canReallyBecomeFirstResponder
that includes the check for editable.
The other fix, as you suggest, is to remove this check since you have proven that tapping a control does not necessarily make it the responder when we expect to. If we go this route, we should move the test to enterText:intoViewWithAccessibilityLabel:
to make sure the tapped control became the first responder.
Thoughts?
Indeed it does feel like an iOS bug, but it might be better to not have this check in the tapViewWithAccessibilityLabel
derived methods and rather leave it up to enterText:intoViewWithAccessibilityLabel:
to continue checking for this since it's specific to text field/view logic.
@iwasrobbed, I agree. Do you want to submit a pull request with this change or do you want me to do it?
@iwasrobbed I want to cut a new version of KIF today or tomorrow. Do you want me to wait for your change?
@iwasrobbed Did you find time to work up a fix yet?
Hi,
I have the same issue with trying to enter text into a textfield more than once, e.g. test login with invalid credentials then with valid ones: when trying to enter text in the username field the second time I get the same error: Failed to make the view into first responder.
When looking at the code I ended in KIFUITestActor#tapAccessibilityElement:inView:. This method taps the view and then expect the following condition to be true: ! [view canBecomeFirstResponder] || [view isDescendantOfFirstResponder]
The negated first term seems odd: if KIF want to make tapped view become first responder why throw an exception if the view CAN become first responder BUT is NOT a descendant of the current first responder ?
While debugging, I tested the terms: (lldb) po [view canBecomeFirstResponder] true
(lldb) po [view isDescendantOfFirstResponder] NO
Sorry if I'm totally off the point, I'm new to iOS and KIF
Brieuc
I will work on a fix.
I had similar issue, and turns out that I had made a very naive mistake. I have an "Edit profile" screen, and the view controller is the delegate for all the fields on the screen, by mistake I put the following delegate method implementation
(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { [self.view endEditing:YES]; if(textField == self.birthdateField){ return NO; }
return YES; }
As you can see, once any text field tries to become first responder, the first line of my method will resign it. Somehow, in the normal target it did not cause an issue; but it caused the issue when trying to implement the UI testing.
@applequist: is @Ahmed-Ali's post relevant to your situation?
If you place a
UIGestureRecognizer
on aUITextView
with editable set to NO and then have KIF tap that view, KIF will throw an exception since it expects theUITextView
to become first responder.Code reference: https://github.com/kif-framework/KIF/blob/master/Classes/KIFUITestActor.m#L176
Error thrown:
Failed to make the view into the first responder
Is there a specific reason that the view has to become first responder or could this be left out?