如何在ios中停止自动化测试

时间:2013-02-21 09:16:20

标签: javascript ios button ui-automation ios-ui-automation

有没有办法阻止自动化测试?实际上我用自动化javascript测试我的应用程序。我的脚本中有两个测试。如果第一次测试失败,我不想继续我的脚本.. 我的代码:

var target = UIATarget.localTarget();
var testname = "Test1";
UIALogger.logStart(testname);
target.frontMostApp().mainWindow().buttons()[0].tap();
UIALogger.logPass(testname);
target.delay(2);

var testname = "Test2";
UIALogger.logStart(testname);
target.frontMostApp().mainWindow().buttons()[1].tap();
target.frontMostApp().mainWindow().buttons()[0].tap();
UIALogger.logPass(testname);

如果test1失败,我必须说脚本停止进程..请告诉我对此问题的任何建议。感谢...

2 个答案:

答案 0 :(得分:2)

你应该真正考虑抽象出你的测试。你可以使用类似的东西:

function test(description, steps) {
    try{
        UIALogger.logStart(description);
        steps();
        UIALogger.logPass("Test Passed");
    } catch (exception) {
        UIALogger.logError(exception.message);
        UIATarget.localTarget().logElementTree();
        UIALogger.logFail("Test Failed");
        throw exception;
    }
}

作为一个功能,您可以包装您的测试。如您所见,它将开始测试,完成测试的步骤(如果可能)。如果失败,测试将记录元素树(非常方便),然后再次抛出相同的错误,停止测试继续,并提供有关您遇到的错误的信息。

答案 1 :(得分:0)

我强烈建议您使用tuneup_js来运行UIAutomation。如果一个测试使用Instruments GUI失败,我认为你不能停止测试运​​行,但是当使用tuneup_js库并从命令行运行测试时它会停止

相关问题