Sample 1 - From Documentation
Code: Select all
void ITestModule.Run()
{
// Create PopupWatcher
PopupWatcher myPopupWatcher = new PopupWatcher();
// Add a Watch using a RanoreXPath and triggering the Method CloseUpdateCheckDialog
myPopupWatcher.Watch("/form[@controlname='UpdateCheckForm']/button[@controlname='m_btnClose']", CloseUpdateCheckDialog);
// Add a Watch using the info object of a button and triggering the Method CloseUpdateCheckDialog
// myPopupWatcher.Watch(repo.UpdateCheckDialog.btCloseInfo, CloseUpdateCheckDialog);
// Add a Watch using the info object of the dialog and the info object of the button to click
// myPopupWatcher.WatchAndClick(repo.UpdateCheckDialog.SelfInfo, repo.UpdateCheckDialog.btCloseInfo);
// Add a Watch using a repository folder object and the info object of the button to click
// myPopupWatcher.WatchAndClick(repo.UpdateCheckDialog, repo.UpdateCheckDialog.btCloseInfo);
// Start PopupWatcher
myPopupWatcher.Start();
}
public static void CloseUpdateCheckDialog(Ranorex.Core.Repository.RepoItemInfo myInfo, Ranorex.Core.Element myElement)
{
myElement.As<Ranorex.Button>().Click();
}
public static void CloseUpdateCheckDialog(Ranorex.Core.RxPath myPath, Ranorex.Core.Element myElement)
{
myElement.As<Ranorex.Button>().Click();
}
Code Sample 2 - From http://www.ranorex.com/blog/handling-di ... p-windows/
This sample is also referred in post http://www.ranorex.com/forum/handling-d ... t2882.html
Code: Select all
public static void ClosePopUpDialogs()
{
while (true)
{
if (repo.Dialog_01.SelfInfo.Exists() )
{
Thread.Sleep(300);
Report.Screenshot(repo.Dialog_01.Self);
repo.Dialog_01.Yes.Click();
}
if (repo.Dialog_02.SelfInfo.Exists() )
{
Thread.Sleep(300);
Report.Screenshot(repo.Dialog_02.Self);
repo.Dialog_02.Retry.Click();
}
if (repo.Dialog_03.SelfInfo.Exists() )
{
Thread.Sleep(300);
Report.Screenshot(repo.Dialog_03.Self);
repo.Dialog_03.Close.Click();
}
Thread.Sleep(1000);
// Check if the 'Start' button's enabled state is set to true
// The 'Enabled' property is used to determine whether
// the simulation has been stopped manually by the user
if (repo.AppDialogSimulator.ButtonStart.Enabled == true )
{
Report.Info("Simulation was interrupted manually");
Report.Screenshot(repo.AppDialogSimulator.Self);
break;
}
}
}
Sample 1 is simplistic but lacks clarity regarding background functioning and multithreading.
Sample 2 is comprehensive but difficult to configure.
The samples available on other posts use code sample 2.Hence I am attempting to use sample 2 but am not able to make it work.
Q2. Can anyone explain the location of where this code goes?
Possibly with a sample Program.cs file or its screenshot, to clarify the structure of the file.
P.S. I'm not using the default dialog or buttons shown in the code . I have "Track"ed the required dialog box and buttons in Ranorex.
I am using the popup watcher to handle the "Crash" dialog on windows to click on the "Close Program" button as shown in the screenshot below. Any help is much appreciated.
Thanks.