1

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

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

问题是验证不返回布尔值,如果按钮不存在,它只会在测试中引发错误。有没有办法捕捉错误并相应地运行脚本?

4

1 回答 1

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
于 2012-10-07T08:54:42.793 回答