gpt4 book ai didi

javascript - 如何停止 ios 中的自动化测试

转载 作者:行者123 更新时间:2023-11-28 22:39:18 25 4
gpt4 key购买 nike

有什么方法可以停止自动化测试吗?实际上,我正在使用自动化 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 失败,我必须说出停止进程的脚本。请告诉我对这个问题的任何建议。谢谢...

最佳答案

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

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;
}
}

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

关于javascript - 如何停止 ios 中的自动化测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14998421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com