Using the code provided to make a custom Dialog handler, I am now trying to capture the Alert dialog as a screenshot and have been unsuccessful using both Manager.ActiveBrowser.Capture() and Manager.ActiveBrowser.Window.GetBitmap(). Both attempts save the window behind the Alert dialog.
Any help would be appreciated!
Any help would be appreciated!
public override void OnBeforeTestStarted() { AlertDialog myAlertDialog = new AlertDialog(ActiveBrowser, DialogButton.OK); myAlertDialog.HandlerDelegate = new DialogHandlerDelegate(MyCustomAlertHandler); //Manager.DialogMonitor.AddDialog(new AlertDialog(ActiveBrowser, DialogButton.OK)); Manager.DialogMonitor.AddDialog(myAlertDialog); Manager.DialogMonitor.Start(); } public void MyCustomAlertHandler(IDialog dialog) { // Simply close the dialog System.Threading.Thread.Sleep(1500); System.Drawing.Bitmap image = Manager.ActiveBrowser.Capture(); //System.Drawing.Bitmap image = Manager.ActiveBrowser.Window.GetBitmap(); image.Save(this.ExecutionContext.DeploymentDirectory.ToString() + @"\Data\alert.png", System.Drawing.Imaging.ImageFormat.Png); dialog.Window.Close(); try { // Wait until it is closed dialog.Window.WaitForVisibility(false, 50); Log.WriteLine("Alert Handled!"); } catch { Log.WriteLine("Failed to handle alert!"); } }