我正在尝试用JavaScripts编写脚本来测试使用MonkeyTalk的iPhone应用程序的UI。我该如何使用逻辑和条件句呢?现在我有一个代码块:
if (this.app.button("name").verify())
do this if button exists问题是verify不会返回bool,如果按钮不存在,它只会在测试中抛出一个错误。有没有办法捕获错误并相应地运行脚本?
发布于 2012-10-07 16:54:43
这似乎起作用了:
function verifiedViewOrNull (view)
{
var exists = false;
try
{
view.verify();
exists = true;
}
catch (e)
{
}
return exists ? view : null;
}你可以这样称呼它:
if (verifiedViewOrNull(this.app.view("name")) != null
{
// It exists
} else
//doesn't exist, not gonna throw exceptionhttps://stackoverflow.com/questions/12687749
复制相似问题