VS2013 Coded UI测试MouseClick对话框窗体的关闭按钮有时无法关闭窗体

VS2013 Coded UI test MouseClick on the close button of a dialogue form sometimes cannot close the form

我们有一个在主窗体上方显示为对话的窗体。 DialogResult rslt = cvForm.ShowDialog();

在编码 UI 测试中,当对话启动时,Mouse.Click 会立即尝试通过单击表单的 "x" 按钮将其关闭。 但是,x按钮有时似乎无法响应点击事件,在某台机器上它总是无法关闭窗体,除非我们在点击前等待。 所有 WaitForControlxxx() 都不作为等待,因为它们立即 returns。 只有在点击前放置 PlayWait(1000) 才能关闭窗体。 而且故障只发生在我们的实验室机器上。在我的笔记本电脑上,即使没有 PlayWait(1000),它也能正常工作。 看来只是时间问题。 有什么我可以等待的,而不是盲目地等待 1 秒才能在实验室机器上运行吗?

//this.UIAUDIO_TX_HPF_IIRWindow refers to the Form shown as a Dialogue:
// this.UIAUDIO_TX_HPF_IIRWindow

//ulCloseButton refers to the "x" button on the Form:
     WinButton uICloseButton = this.UIAUDIO_TX_HPF_IIRWindow.UIAUDIO_TX_HPF_IIRTitleBar.UICloseButton;

以下代码无法在我们的实验室机器上关闭 WinForm window,但可以在我的笔记本电脑上关闭它:

     uICloseButton.WaitForControlExist();
     uICloseButton.WaitForControlReady();
     uICloseButton.WaitForControlEnabled();
     this.UIAUDIO_TX_HPF_IIRWindow.WaitForControlReady();
     //Mouse.Click(uICloseButton, new Point(15, 9));
     Mouse.Click(uICloseButton);

以下代码可以关闭我们实验室机器上的 WinForm window:

     Playback.Wait(1000);        
     Mouse.Click(uICloseButton);

有意见吗?

似乎对话框还没有完全准备好更改对对话框的关注。 在焦点准备好之前,测试试图关闭它。 尝试使用以下代码。

Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.AllThreads;

此处 WaitForReadyLevel.UIThreads 选项也存在。

这会增加测试执行时间。