【发布时间】:2011-01-12 17:14:01
【问题描述】:
我正在使用白色自动化 API 来测试 silverlight 应用程序,但是当 silverlight 中发生未处理的异常时,我不知道有什么方法可以将其报告回单元测试或检查白色 api 以查看是否存在是个例外。有人有办法做到这一点吗?
【问题讨论】:
标签: silverlight exception-handling automation ui-automation white-framework
我正在使用白色自动化 API 来测试 silverlight 应用程序,但是当 silverlight 中发生未处理的异常时,我不知道有什么方法可以将其报告回单元测试或检查白色 api 以查看是否存在是个例外。有人有办法做到这一点吗?
【问题讨论】:
标签: silverlight exception-handling automation ui-automation white-framework
我对白色测试框架不熟悉,但您可能可以在测试中执行以下操作:
[Test]
public void MyTest()
{
bool unhandledExceptionFired = false;
Application.Current.UnhandledException += (s,e) => unhandledExceptionFired = true;
//test code....
Assert.IsFalse(unhandledExceptionFired);
}
就像我说的,我没有使用提到的特定测试框架,但是这样的东西应该可以工作。或者您是否遇到了一些阻止此操作的问题?
【讨论】:
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'
【讨论】: