上周我一直在为这个问题绞尽脑汁,无处可求。目前,每当我在 Instruments 中运行测试时,通过/失败日志记录功能几乎总是报告:
Issue: Script ended without explicting closing this test
注意——是的,拼写错误是正确的
但我的记录方法是正确的。有时当我对测试进行更改时,也许只是添加一个额外的空格或注释,然后保存并再次运行,通过/失败功能实际上会工作一次!
但是,如果相同的代码在没有任何更改的情况下立即再次运行,问题:脚本在未明确关闭此测试的情况下结束
问题再次发生。
太疯狂了!
这是我的测试代码的简化示例:
var target = UIATarget.localTarget();
var app = UIATarget.localTarget().frontMostApp();
var testName = "LoginCreateEntry";
//Start test logging
UIALogger.logStart(testName);
//**Do UI automation stuff here generated by Instruments/record**
//The automation creates a list entry in my application
//The flow goes, run the automation that creates the entry, then verify that the entry
//got created as expected and is visible to the user in the iPhone interface.
var window = app.mainWindow();
var tableView = window.tableViews()[0];
var tableGroup = tableView.groups()[0];
var entryName = "My Dogs!";
var myEntry = tableView.cells()[0].name();
//Do a bunch of UI automation here to create my entry, which results in the entry
//appearing in the mainWindow with the label: My Dogs!
//Get the value held in myEntry to print to the log so that I know
//the variable has a value in it to evaluate
UIALogger.logMessage("My Story Title: " + myEntry);
//If myEntry evaluates to true, then call this test a pass.
if (myEntry === entryName) {
UIALogger.logMessage("My entry was created!");
//Mark the test as a PASS
UIALogger.logPass(testName);
}
else {
UIALogger.logMessage("My entry was not created!");
//Mark the test as a FAIL
UIALogger.logFail(testName);
}
//End test
如前所述,运行此代码时我得到:
Issue: Script ended without explicating closing this test
但是如果我添加第二个 logMessage()
方法,或者对脚本进行任何更改——甚至添加注释,并保存这些更改然后再次运行——有 80% 的机会通过/失败将适用于单次运行。但是,如果代码在没有任何更改的情况下立即再次运行,那么令人愤怒的“Issue: Script ended...
”行为会再次发生。
我已经无计可施了。非常感谢任何帮助或反馈!
此外,其他人也遇到过同样的问题,如此处所述:Instruments Automation Tool: Script Ended Without Explicitly Closing This Test
--------------------更新------------------------ ---
我现在已经在运行 Xcode 4.6 的单独 MacBook Pro 上复制了这个问题。我也做了各种努力故意让我的测试失败——只是为了得到 react ,但仍然得到 Issue: Script ended without expliciting closing this test
日志消息,它告诉我条件可能不会甚至被阅读。然而,再说一次,如果我对脚本进行任何微小的更改,然后保存这些更改并再次运行,通过/失败功能很有可能会在单次运行中起作用,然后开始出现“问题:脚本结束.. 。”即使没有脚本更改,也会在下一次运行时再次出现这种行为。
--------------------更新 x 2------------------------ ------
似乎是 IF 语句没有触发,我什至不能使用断点来确定这一点。但我只是像这样运行了一个简单的测试:
UIALogger.logStart();
if (5 < 10)
{
//Mark the test as a PASS
UIALogger.logPass();
}
else
{
//Mark the test as a FAIL
UIALogger.logFail();
}
仍然有问题:脚本结束时没有解释关闭此测试
--------------------更新 x 3------------------------ ------
因此,我刚刚在 Instruments 中创建了一个全新的单独脚本,仅包含以下代码,现在无论我如何更改 IF
语句中的相对值,通过/失败始终有效。哇,现在越来越陌生了。
var target = UIATarget.localTarget();
UIALogger.logStart();
if (5 > 10)
{
//Mark the test as a PASS
UIALogger.logPass();
}
else
{
//Mark the test as a FAIL
UIALogger.logFail();
}
最佳答案
好的,这个问题是真实存在的,可能只影响 Xcode 4.6。该问题在多台机器上和多个跟踪脚本中重复出现。这是解决方案:
像这样在你的 if 语句中添加一个等待:
UIALogger.logStart( testName );
//Do automation stuff here
if (5 < 10) {
UIALogger.logMessage("We passed!");
//Wait a moment
target.delay(1);
UIALogger.logPass( testName );
} else {
UIALogger.logMessage("We Failed!");
UIALogger.logFail( testName );
UIALogger.logFail( testName );
}
此外,这可能听起来很愚蠢——但这对我有用,请注意,您的 IF 语句的 logFail() 部分没有延迟,但有两个 logFail() 语句(有时 3 个 logFail()需要声明)。如果您在 IF 语句的失败部分使用延迟,您将收到 ISSUE 消息而不是干净的 FAIL 消息。不,我不是在开玩笑。是的,这很愚蠢。
关于ios - Xcode INSTRUMENTS 通过/失败日志记录功能在 Xcode 4.6 中似乎已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15300737/