0

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?

mclaughj
  • 12,645
  • 4
  • 31
  • 37
  • can you show your kif code? – abbood Aug 30 '13 at 18:27
  • Can you include some additional context from the log? What were the lines leading up to the error? This error was triggered by a caught exception. Can you add an exception breakpoint and show where the exception was thrown? It could have been thrown in your code or KIF. – Brian Nickel Aug 30 '13 at 20:18
  • Brian Nickel: I've added a little context to the logged error. As for the exception, it's being thrown in KIFTestStep.m (line 852). While debugging around this area of execution it seems like everything is in order. – mclaughj Aug 30 '13 at 20:33
  • Line 852 is where it is being caught, not where it's thrown. An exception breakpoint will trigger when the exception is raised. – Brian Nickel Aug 30 '13 at 21:30

1 Answers1

2

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.

Brian Nickel
  • 26,890
  • 5
  • 80
  • 110
  • Thanks for the link explaining how to use a breakpoint exception. I misunderstood what you meant. However, it looks like the exception is being thrown on line 96 of UIApplication-KIFAdditions.m and isn't being thrown by my code. I'm still at a loss as to why this error is occurring. – mclaughj Sep 03 '13 at 07:15
  • Can you provide the line in question? I only see 89 lines in [that file](https://github.com/kif-framework/KIF/blob/79db32c4b36bbd8bdd10d9e8f2e028dadf63ef0a/Additions/UIApplication-KIFAdditions.m) – Brian Nickel Sep 03 '13 at 07:23
  • Interesting, my local copy of the file has a method named `dimmingViewWindow` right above `windowsWithKeyWindow`. The line in that appears to be throwing the exception is line 84, `[windows addObject:keyWindow];` – mclaughj Sep 03 '13 at 07:39
  • 1
    Okay, I must have had the wrong version. That is interesting. It suggests that you don't have a `keyWindow`. Are you using storyboards? If not, are you calling `[self.window makeKeyAndVisible]` before or after KIF's `startTestingWithCompletionBlock:`? – Brian Nickel Sep 03 '13 at 07:52
  • Brian, you're a lifesaver. Looking through my code there was a race condition that could prevent `[self.window makeKeyAndVisible]` from being fired before I ran my KIF tests. Do you think I should mark this as the correct answer? – mclaughj Sep 03 '13 at 08:04
  • Thanks @BrianNickel for your work here. The issue of not having a `keyWindow` was the source of my issue as well. We were swapping in a separate type of `AppDelegate` in when testing as seen here: https://stackoverflow.com/questions/28502498/feature-tests-with-kif-beforeeach-is-called-after-my-view-controller-is-loaded That separate kind of `AppDelegate` class was not configuring the `keyWindow` at all, hence my crash. Hopefully this is helpful for someone :-) – Brian Sachetta Aug 31 '18 at 19:24