我正在尝试自动化测试一个winform应用程序。我在与测试代码相同的进程中运行它,因此很容易找到.Net控件并模拟用户对其的操作。然而,我遇到了一个问题,就是如何处理消息框(使用标准的MessageBox.Show方法创建)。我该如何获取它并模拟按下按钮?
我正在尝试自动化测试一个winform应用程序。我在与测试代码相同的进程中运行它,因此很容易找到.Net控件并模拟用户对其的操作。然而,我遇到了一个问题,就是如何处理消息框(使用标准的MessageBox.Show方法创建)。我该如何获取它并模拟按下按钮?
public class UserInterrogator : IUserInterrogator
{
private Form owner;
public UserInterrogator(Form owner)
{ this.owner = owner; }
public Font GetFontFromUser() // member of the IUserInterrogator interface
{
FontDialog fd = new FontDialog();
fd.ShowDialog( owner );
return fd.Font;
}
}
当然,更简单的方法是编写一些代码来查找对话框并关闭/终止它。我看到有些人使用Win32 APIs和NUnitForms取得了一些成功...
codeplex.com/white - 免费
testautomationfx.com - 商业软件但非常优秀
您可能需要使用WinAPI调用(FindWindowEx等)并发送LMB按下和松开的消息到按钮句柄。