Log Error Dialogs
*My application can potentially display a dialog containing an error message during test execution. The dialog can appear multiple times and will not always appear at the same point in the test, therefore I cannot use a standard Dialog Handler step.
I want to capture these error messages and automatically handle these dialogs if they appear.*
Solution
This is possible with a coded solution. The stipulation is that the dialog is displayed the same way and has the same title in each browser:
1. Add an Assembly Reference to System.Windows.Forms. 2. Add a coded step to the beginning of the test that creates a dialog monitor. 3. Define a custom dialog handler that is referenced in the coded step. 4. Override the OnAfterTestCompleted method to log whatever text the dialog handler captured. 5. Auto reset the dialog handler in case of multiple dialogs.
Here is the full code-behind file, excluding the standard using/Imports statements and the Dynamic Pages Reference region: