【问题标题】:MonkeyTalk boolean logicMonkeyTalk 布尔逻辑
【发布时间】:2012-10-02 09:27:27
【问题描述】:

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

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

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

【问题讨论】:

    标签: testing automated-tests ui-testing


    【解决方案1】:

    这似乎有效:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-11
      • 1970-01-01
      • 2015-04-18
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多