kif-framework / KIF

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

clearTextFromAndThenEnterText does not necessarily clear all existing text #294

Closed smroush closed 10 years ago

smroush commented 10 years ago

clearTextFromAndThenEnterText does not necessarily clear all existing text. If there is "too much" existing text, then the tap event used by the routine taps into the middle of the text rather than at the end of it (I believe because it is tapping in the middle of the view, in my case a UITextField). This ends up causing a time out and an exception.

I am not sure what the author expected but this was not the behavior I expected and does not seem to be in the spirit of the routine or consistent with the title of the routine; I expected any amount of existing text to be cleared.

bnickel commented 10 years ago

Resolved in master. I modified to select the whole body and delete if the view conforms to UITextInput. There are realistically other ways to do this emulating user behavior, e.g., long press, select all, backspace, but this is locale dependent. This seems like a reasonable solution.

smroush commented 10 years ago

Brian - looks reasonable to me. Thanks for the quick response.

jacebrowning commented 9 years ago

What version was this fixed in? I still experience this issue in 3.0 trying to clear a UISearchBar. With something like:

tester().enterText("A very long phrase right here...", intoViewWithAccessibilityLabel: "MySearchBar")
tester().clearTextFromViewWithAccessibilityLabel("MySearchBar")

typically "here..." still remains.

phatmann commented 9 years ago

@jacebrowning This was fixed as of 3.0. Can you figure out why this is failing in your case?

jacebrowning commented 9 years ago

@phatmann To me it seems like a timing issue.

Running:

tester().enterText("A long long time ago in a galaxy far far away...", intoViewWithAccessibilityLabel: "Search")
tester().clearTextFromViewWithAccessibilityLabel("Search")
tester().enterText("", intoViewWithAccessibilityLabel: "Search")

results in:

MyTests.swift:51: The step timed out after 1.00 seconds: Failed to get text "" in field; instead, it was "galaxy far far away...":

It seems that the action clearTextFromViewWithAccessibilityLabel is performing does not run long enough to delete all of the entered text.

angu-software commented 7 years ago

This issue is still present.

Seems clearTextFromViewWithAccessibilityLabel is selecting a whole word in the middle of the text view and then deleting all characters on the left side of the cursor.

justinseanmartin commented 7 years ago

Happy to look at proposals for fixing the issue. We haven't run into the problem in our tests, so haven't needed to look into it.

brunomunizaf commented 7 years ago

In my case is not clearing nothing at all from the textfield, i've also tried to clear and than enter separately but no success so far. I'm trying to find a workaround not so hack-ish as deleting char/char till length is zero. <- also it would make it so much slower CP v: 1.3.1 KIF v: 3.6.0

brunomunizaf commented 7 years ago

This seems to work for me: [tester tapViewWithAccessibilityLabel:@"accessibilityLabelValue"] [tester clearTextFromFirstResponder] [tester enterText:textValue intoViewWithAccessibilityLabel:@"accessibilityLabelValue"]

justinseanmartin commented 7 years ago

@brunomunizaf - That is a different issue than what is being reported above where KIF is only partially clearing the contents of a text field. I'm still not clear on the root cause of that issue, but haven't dug in closely.

If that is working for you, it seems to me that the element that is being matched on with accessibilityLabelValue is not the same UIView as the one that you actually want to be typing in. If you wanted to debug it closer, you could do:

UIView *tapView = [[viewTester usingAccessibilityLabel:@"accessibilityLabelValue"] waitForView];
[[viewTester usingAccessibilityLabel:@"accessibilityLabelValue"] tap];
UIView *firstResponderView = [[viewTester usingFirstResponder] waitForView];
[[viewTester usingFirstResponder] clearText];
NSLog(@"TAPPED: %@, FIRST RESPONDER: %@", tapView, firstResponderView);

You can also dump the entire accessibility hierarchy from a LLDB breakpoint using po [UIView printViewHierarchy].