kif-framework / KIF

Keep It Functional - An iOS Functional Testing Framework
Other
6.21k stars 914 forks source link

KIF expects UITextView to become first responder #302

Closed iwasrobbed closed 6 years ago

iwasrobbed commented 11 years ago

If you place a UIGestureRecognizer on a UITextView with editable set to NO and then have KIF tap that view, KIF will throw an exception since it expects the UITextView 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?

chrischenyc commented 10 years ago

+1 I encountered same issue with UITextField which has gesture recognizer

chrischenyc commented 10 years ago

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];

}
phatmann commented 10 years ago

@iwasrobbed, do you have a suggested fix?

iwasrobbed commented 10 years ago

@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.

phatmann commented 10 years ago

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?

iwasrobbed commented 10 years ago

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.

phatmann commented 10 years ago

@iwasrobbed, I agree. Do you want to submit a pull request with this change or do you want me to do it?

phatmann commented 10 years ago

@iwasrobbed I want to cut a new version of KIF today or tomorrow. Do you want me to wait for your change?

phatmann commented 10 years ago

@iwasrobbed Did you find time to work up a fix yet?

ghost commented 9 years ago

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

phatmann commented 9 years ago

I will work on a fix.

Ahmed-Ali commented 8 years ago

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

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.

phatmann commented 8 years ago

@applequist: is @Ahmed-Ali's post relevant to your situation?