[Tracking] UI Test Dialogs Reliably
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 1d 13m
- Merged PRs (30d)
- 85
Description
When UI testing for dialogs such as `FolderBrowserDialog`,`OpenFileDialog`,`SaveFileDialog`, etc. we should test reliably/quickly by:
1. Avoiding hunting for HWNDs
2. Interacting with the dialog programmatically rather than via mouse or keyboard input if possible
An example of this would be the following:
```c#
[WinFormsFact]
public void OpenFileDialog_ShowDialog_Success()
{
using DialogHostForm dialogOwnerForm = new();
using OpenFileDialog dialog = new();
Assert.Equal(DialogResult.Cancel, dialog.ShowDialog(dialogOwnerForm));
}
internal class DialogHostForm : Form
{
protected override void WndProc(ref Message m)
{
if (m.MsgInternal == WM.ENTERIDLE && m.WParamInternal == (uint)MSGF.DIALOGBOX)
{
HWND dialogHandle = (HWND)m.LParamInternal;
PInvoke.PostMessage(dialogHandle, WM.CLOSE);
}
base.WndProc(ref m);
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.