MonkeyTalk布尔逻辑

时间:2012-10-02 09:27:27

标签: testing automated-tests ui-testing

我正在尝试用JavaScripts编写脚本来测试使用MonkeyTalk的iPhone应用程序的UI。我如何使用逻辑和条件?现在我有一个块:

if (this.app.button("name").verify())
      do this if button exists

问题是验证没有返回bool,如果按钮不存在,它只会在测试中抛出错误。有没有办法捕获错误并相应地运行脚本?

1 个答案:

答案 0 :(得分:2)

这似乎有效:

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 exception