【问题标题】:bubble unhandled exception to white automation from silverlight来自silverlight的白色自动化气泡未处理异常
【发布时间】:2011-01-12 17:14:01
【问题描述】:

我正在使用白色自动化 API 来测试 silverlight 应用程序,但是当 silverlight 中发生未处理的异常时,我不知道有什么方法可以将其报告回单元测试或检查白色 api 以查看是否存在是个例外。有人有办法做到这一点吗?

【问题讨论】:

    标签: silverlight exception-handling automation ui-automation white-framework


    【解决方案1】:

    我对白色测试框架不熟悉,但您可能可以在测试中执行以下操作:

    [Test]
    public void MyTest()
    {
        bool unhandledExceptionFired = false;
        Application.Current.UnhandledException += (s,e) => unhandledExceptionFired = true;
    
        //test code....
    
    
        Assert.IsFalse(unhandledExceptionFired);
    }
    

    就像我说的,我没有使用提到的特定测试框架,但是这样的东西应该可以工作。或者您是否遇到了一些阻止此操作的问题?

    【讨论】:

    • 感谢您的建议,但这不起作用,因为我没有直接使用 silverlight 应用程序 - 它正在自动化 - 基本上这模拟了应用程序上的用户交互,即按钮点击、输入文本等所以它在应用程序的外部——这是一个功能测试框架,类似于 web 应用程序的 selenium。我可以看到 IE 的“页面上的错误”警告,所以我知道应用程序中触发了异常,但白色 api 中没有报告它(或者我无论如何都找不到解决方法)。跨度>
    【解决方案2】:

    IE 的“页面错误”警告是一个 GUI 元素,因此您应该能够通过白色 api 检查它。找到 IE 状态栏,查询状态消息,如果消息 == 'error on page',则在测试中记录错误。下面的示例代码用于检查状态栏上的文本。

    app = Application.Attach(Process.GetProcessesByName('iexplore')[0])
    win = app.GetWindows()[0]
    statusBar = win.Get(SearchCriteria.ByAutomationId('StatusBar'))
    for item in statusBar.Items:
        print item.Id, String.Format("'{0}'", item.Text)
    

    输出

    StatusBar.Pane0 'Done'
    StatusBar.Pane1 '' 
    StatusBar.Pane2 ''
    StatusBar.Pane3 '' 
    StatusBar.Pane4 ''
    StatusBar.Pane5 '' 
    StatusBar.Pane6 ''
    StatusBar.Pane7 'Internet'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      • 2010-12-09
      • 2011-09-01
      • 1970-01-01
      相关资源
      最近更新 更多