iosobjective-ckif-framework

how to programmatically tap a point on the iOS keyboard


I'm using KIF to automate my app, and I'm trying to automate typing something into a UISearchBar and searching for it. Unfortunately I couldn't find a satisfactory way to do that by programmatically clicking on the search button after I've entered my search text.

So instead, I considered simply using KIF's tapScreenAtPoint method. The problem with that method is that it does the following:

CGPoint windowPoint = [window convertPoint:screenPoint fromView:nil];
view = [window hitTest:windowPoint withEvent:nil];

It's expecting the tap to actually touch a view.. and since the keyboard is obviously not a view this test won't be able to trigger the search button on the keyboard.

How can one programmatically tap a button on the keyboard? I think this would be very useful for any automation-test suite.


Solution

  • It sounds like you're trying to tap the "Search" button in the keyboard. The accessibility labels on return keys don't follow any sort of sane pattern. Looking in the accessibility inspector, you'll see "SEARCH" but that may not be consistent on all OS versions.

    Update

    You can trigger the search button by adding \n to your enterText...

    [tester enterTextIntoCurrentFirstResponder:@"query\n"];
    

    Search button in selector