iosobjective-ckif-framework

All KIF test steps are throwing the same error, what am I doing wrong?


When running my KIF target regardless of how I write my KIFTestScenario or KIFTestStep they are returning the following error:

12:20:58.434 - Test that a user can successfully dismiss the welcome screens
12:24:53.208 - FAIL (209.11s): Tap screen at point "{10, 10}"
12:24:53.209 - FAILING ERROR: Error Domain=KIFTest Code=0 "Step threw exception: 
*** -[__NSArrayM insertObject:atIndex:]:
object cannot be nil" UserInfo=0x842c1e0 {NSLocalizedDescription=Step threw exception: *** -[__NSArrayM insertObject:atIndex:]: 
object cannot be nil}
12:24:53.210 - END OF SCENARIO (duration 223.62s)

As suggested, I've included the code I'm using:

TestController.m

#import "TestController.h"
#import "KIFTestScenario+Additions.h"

@implementation TestController

- (void)initializeScenarios;
{
     [self addScenario:[KIFTestScenario scenarioToLogIn]];
}
@end

KIFTestScenario+Additions.m

#import "KIFTestScenario+Additions.h"

@implementation KIFTestScenario (Additions)

+ (id)scenarioToLogIn
{
    KIFTestScenario *scenario = [KIFTestScenario scenarioWithDescription:@"Test that a user can successfully dismiss the welcome screens"];
    KIFTestStep *step = [KIFTestStep stepToTapScreenAtPoint:CGPointMake(10.0f, 10.0f)];
    [scenario addStep:step];
    return scenario;
}
@end

I have walked through the debugger and the KIFTestStep I am adding to the scenario is non-nil and is a valid KIFTestStep.

Has anyone run into this problem before or have any thoughts on a fix?


Solution

  • This exception is being raised in your own code.

    Looking at the KIF source, insertObject:atIndex: is called in two places: in addStep: and in KIFTypist.

    Your exception is occurring in the execution of the step so it is not in addStep:, and you are not using the keyboard methods so KIFTypist isn't being used.

    What is likely happening is that KIF is tapping the screen at that point, and your gesture recognizer or callback listener is triggering the exception. This would normally crash your app but KIF's exception handler caught it and reported the test failure. You can catch the exception where it is raised using a breakpoint exception and find out what caused it.

    It is worth noting that screen coordinate 10, 10 is typically untappable because it is inside the status bar. To tap your app at 10, 10 you should pass 10, 30.


    Update

    Per our discussion in the comments, the exception is being raised in windowsWithKeyWindow where the key window was nil. The only situation where keyWindow would be nil in typical apps is before you call [self.window makeKeyAndVisible] in your app delegate. You need to make sure all setup logic (including making a key window) is done before you call KIF's startTestingWithCompletionBlock: method.