所有KIF测试步骤都抛出相同的错误,我在做什么错呢? [英] All KIF test steps are throwing the same error, what am I doing wrong?

查看:127
本文介绍了所有KIF测试步骤都抛出相同的错误,我在做什么错呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我如何编写KIFTestScenario或KIFTestStep,运行KIF目标时,它们都将返回以下错误:

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

TestController.m

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

@implementation TestController

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

KIFTestScenario+Additions.m

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

我已经遍历了调试器,并且我要添加到场景中的KIFTestStep是非nil,并且是有效的KIFTestStep.

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?

推荐答案

此异常正在您自己的代码中引发.

This exception is being raised in your own code.

查看KIF源,在

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

您的异常发生在步骤执行中,因此不在addStep:中,并且您没有在使用键盘方法,因此未在使用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.

可能发生的情况是,KIF此时正在敲击屏幕,而手势识别器或回调侦听器正在触发异常.这通常会使您的应用程序崩溃,但KIF的异常处理程序将其捕获并报告测试失败.您可以使用断点异常来捕获引发异常的地方并找出是什么原因造成的.

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.

值得注意的是,屏幕坐标10, 10通常不可应用,因为它位于状态栏中.要在10, 10上点击您的应用,您应该通过10, 30.

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.

更新

根据我们在注释中的讨论,在windowsWithKeyWindow中出现了例外,其中键窗口为nil.在典型应用程序中keyWindow将为nil的唯一情况是在应用程序委托中调用[self.window makeKeyAndVisible]之前.在调用KIF的startTestingWithCompletionBlock:方法之前,您需要确保完成所有设置逻辑(包括创建键窗口).

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.

这篇关于所有KIF测试步骤都抛出相同的错误,我在做什么错呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆