白色框架+1!
你可以检查我发布的用于声明消息框的回答,并使用messageBox.Get()方法单击确定按钮。
编号:https://stackoverflow.com/a/35219222/2902212
window.MessageBox()是一个很好的解决方案
但会停留很长一段时间这种方法,如果消息框不会出现。有时我想检查一个消息框的“不显示”(警告,错误等)。所以我写了一个方法来通过线程来设置timeOut。
[TestMethod]
public void TestMethod()
{
// arrange
var app = Application.Launch(@"c:\ApplicationPath.exe");
var targetWindow = app.GetWindow("Window1");
Button button = targetWindow.Get<Button>("Button");
// act
button.Click();
var actual = GetMessageBox(targetWindow, "Application Error", 1000L);
// assert
Assert.IsNotNull(actual); // I want to see the messagebox appears.
// Assert.IsNull(actual); // I don't want to see the messagebox apears.
}
private void GetMessageBox(Window targetWindow, string title, long timeOutInMillisecond)
{
Window window = null ;
Thread t = new Thread(delegate()
{
window = targetWindow.MessageBox(title);
});
t.Start();
long l = CurrentTimeMillis();
while (CurrentTimeMillis() - l <= timeOutInMillsecond) { }
if (window == null)
t.Abort();
return window;
}
public static class DateTimeUtil
{
private static DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
public static long currentTimeMillis()
{
return (long)((DateTime.UtcNow - Jan1st1970).TotalMilliseconds);
}
}
也许你可以使用AutoIt的,看看http://www.autoitscript.com/site/autoit/ – yosbel
这将是一个有点昂贵..但感谢您的建议 –