Hello! I am using Ranorex 5.4.4.
I read this article http://www.ranorex.com/support/user-gui ... html#c4678
What I am doing: I open windows and want to know, if some popup window with error opened instead of window.
My structure like this, 3 records:
1. Open window. <here we can have a error message. If we do, report a error, close popup, run 3rd step>
2. Do something.
3. Close window.
But I didn't catch some. My question:
1. I see code, that code is written in "void ITestModule.Run()". But we cannot modify it?
Or I should add it to "OpenWindow.UserCode.cs"?
2. Can I run script "Close window" and don't run "Do something" if I get a popup error?
PS I am trying to find best structure.
Handling unexpected Dialogs questions
Re: Handling unexpected Dialogs questions
Hi,
The unexpected dialog handling code should be placed either in a new Code module (which you can freely modify) or you can add it to Program.cs file.
Unfortunately, the nature of unexpected dialog handling does not allow to do what you want in your second question (skip some steps). At least not directly. The problem is that popupwatcher runs in a separate thread and there is currently no way to pause the main thread or to modify its run from the popupwatcher thread.
Probably the only way how to achieve what you want is what I described here:
http://www.ranorex.com/forum/command-to ... tml#p15846
In short, you need to set a variable/global parameter somewhere in popup watcher code (e.g. errorDialogFound = "true"). Then you need to evaluate this variable/parameter somewhere in your test case (at start, at end, anywhere else?). In your case, I would suggest to add a new code module before 'Do something' and this 'Do something' I would suggest to add to a new Test Case. So the structure of your test should look like this:
1. Open window. <here we can have a error message. If we do, report a error, close popup, run 3rd step>
2. CodeModule.cs <-- here you should evaluate the errorDialogFound parameter and eventually skip [Do Something TC] (via code like this: TestSuite.Current.GetTestCase("Do_Something").Checked = false;)
3. [Do_Something]
4. Close window.
The problem of this solution is that it's useful only if you actually know in which part of test you can expect an unexpected dialog
It may be somewhat impractical and messy to add parameter evaluation code before each recording/TC. Hope this helps?
The unexpected dialog handling code should be placed either in a new Code module (which you can freely modify) or you can add it to Program.cs file.
Unfortunately, the nature of unexpected dialog handling does not allow to do what you want in your second question (skip some steps). At least not directly. The problem is that popupwatcher runs in a separate thread and there is currently no way to pause the main thread or to modify its run from the popupwatcher thread.
Probably the only way how to achieve what you want is what I described here:
http://www.ranorex.com/forum/command-to ... tml#p15846
In short, you need to set a variable/global parameter somewhere in popup watcher code (e.g. errorDialogFound = "true"). Then you need to evaluate this variable/parameter somewhere in your test case (at start, at end, anywhere else?). In your case, I would suggest to add a new code module before 'Do something' and this 'Do something' I would suggest to add to a new Test Case. So the structure of your test should look like this:
1. Open window. <here we can have a error message. If we do, report a error, close popup, run 3rd step>
2. CodeModule.cs <-- here you should evaluate the errorDialogFound parameter and eventually skip [Do Something TC] (via code like this: TestSuite.Current.GetTestCase("Do_Something").Checked = false;)
3. [Do_Something]
4. Close window.
The problem of this solution is that it's useful only if you actually know in which part of test you can expect an unexpected dialog

Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 19
- Joined: Tue Jan 27, 2015 4:09 pm
Re: Handling unexpected Dialogs questions
Thanks for your answer!
At the moment I want to talk about my first question.
I've added my code to program.cs, inherited from "ITestModule".
It builds, but doesn't close popup window.
If I add the following code to "UserCode" in record, popup window closes
I can't find the difference in logic. Can you explain how it works?
At the moment I want to talk about my first question.
I've added my code to program.cs, inherited from "ITestModule".
Code: Select all
PopupWatcher myPopupWatcher = new PopupWatcher();
myPopupWatcher.Watch(repo.MSACCESS1, CatchAndClose);
myPopupWatcher.Start();
Code: Select all
private static void CatchAndClose(Ranorex.Core.Repository.RepoItemInfo myInfo, Ranorex.Core.Element myElement)
{
Delay.Milliseconds(2000);
repo.MSACCESS1.ButtonOK.MoveTo();
Delay.Milliseconds(2000);
repo.MSACCESS1.ButtonOK.Click();
Delay.Milliseconds(2000);
}
If I add the following code to "UserCode" in record, popup window closes
Code: Select all
if (repo.MSACCESS1.Self.Enabled)
{
Delay.Milliseconds(2000);
repo.MSACCESS1.ButtonOK.MoveTo();
Delay.Milliseconds(2000);
repo.MSACCESS1.ButtonOK.Click();
Delay.Milliseconds(2000);
}
Re: Handling unexpected Dialogs questions
Hi,
Have you tried to add a breakpoint to the CatchAndClose method? My guess is that Ranorex never goes inside this method and this is why the window is not closed. In other words, popupwatcher most probably failed to detect repo.MSACCESS1 element and therefore, the CatchAndClose method is not initiated? Are you sure the xpath behind the repo.MSACCESS1 element is unique and 100% recognizable?
Have you tried to add a breakpoint to the CatchAndClose method? My guess is that Ranorex never goes inside this method and this is why the window is not closed. In other words, popupwatcher most probably failed to detect repo.MSACCESS1 element and therefore, the CatchAndClose method is not initiated? Are you sure the xpath behind the repo.MSACCESS1 element is unique and 100% recognizable?
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 19
- Joined: Tue Jan 27, 2015 4:09 pm
Re: Handling unexpected Dialogs questions
I run application, open window with popup error, go to Ranorex repository, select MSACCESS1 and press "Highlight element" and Ranorex find it. And "if (repo.MSACCESS1.Self.Enabled)" works fine, so I think, that MSACCESS1 is recognizable.odklizec wrote:Hi,
Have you tried to add a breakpoint to the CatchAndClose method? My guess is that Ranorex never goes inside this method and this is why the window is not closed. In other words, popupwatcher most probably failed to detect repo.MSACCESS1 element and therefore, the CatchAndClose method is not initiated? Are you sure the xpath behind the repo.MSACCESS1 element is unique and 100% recognizable?
If I close popup window, Ranorex cannot find it. So I think, that this element is unique.
When I ran with breakpoint, Ranorex didn't stop. So, issue in finding window, but I don't have idea why it's happening.
Is adding "PopupWatcher" to "Program.cs" share to all runs? I didn't add anything to my record. Maybe I should?
Update: I've tried to catch another popup window and it fails too (
-
- Posts: 19
- Joined: Tue Jan 27, 2015 4:09 pm
Re: Handling unexpected Dialogs questions
Hello again,
I understand what was my issue and fix it.
As we talked, I do:
1. open window
2. do something
3. close window.
Between 1st and 2nd steps popupwatcher finds window, but it doesn't have enough time to click to "ok" or other button in popup window for close it. So, when I insert delay between 1st and 2nd step, problem solved.
But I have a question: inserting delays to all places will take a lot of time and delays will increase test running time.
Maybe I can change delay between records or between actions? Does Ranorex have this settings?
I deleted my delays in code, but it doesn't help.
I understand what was my issue and fix it.
As we talked, I do:
1. open window
2. do something
3. close window.
Between 1st and 2nd steps popupwatcher finds window, but it doesn't have enough time to click to "ok" or other button in popup window for close it. So, when I insert delay between 1st and 2nd step, problem solved.
But I have a question: inserting delays to all places will take a lot of time and delays will increase test running time.
Maybe I can change delay between records or between actions? Does Ranorex have this settings?
I deleted my delays in code, but it doesn't help.
-
- Posts: 19
- Joined: Tue Jan 27, 2015 4:09 pm
Re: Handling unexpected Dialogs questions
Anyway I read all forum and decide to add delay in all places where popup window can be.
One question here. Can I add global variable with timeout and use it in all records? I find only "copy variable from repository" but when I've changed variable value, records saved old value. I read about DDT and others approaches, but its all inflexible for me, because I think that my issue has really simple solution.
please help me.
One question here. Can I add global variable with timeout and use it in all records? I find only "copy variable from repository" but when I've changed variable value, records saved old value. I read about DDT and others approaches, but its all inflexible for me, because I think that my issue has really simple solution.
please help me.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Handling unexpected Dialogs questions
Hi Stas_Tserk,
You can add a global parameter to your test suite by performing a right-click on the test suite and choosing "Global Parameters..." from the context menu. A properties window pops up, which shows a grid of parameters. You can click at "Add row" and overwrite it with the name of your parameter, e.g. MyTimeOut. As value you can write a time span in the format HH:MM:SS, e.g. 00:00:12 if you want to wait 12 seconds. It is ok that the parameter is not bound to a variable.
In the code you can access the parameter like this:
Hope that helps,
Stefan
You can add a global parameter to your test suite by performing a right-click on the test suite and choosing "Global Parameters..." from the context menu. A properties window pops up, which shows a grid of parameters. You can click at "Add row" and overwrite it with the name of your parameter, e.g. MyTimeOut. As value you can write a time span in the format HH:MM:SS, e.g. 00:00:12 if you want to wait 12 seconds. It is ok that the parameter is not bound to a variable.
In the code you can access the parameter like this:
Delay.Duration(TimeSpan.Parse(TestSuite.Current.Parameters["MyTimeOut"]));Parsing is necessary because global parameters are stored as strings.
Hope that helps,
Stefan
-
- Posts: 19
- Joined: Tue Jan 27, 2015 4:09 pm
Re: Handling unexpected Dialogs questions
Thanks support team!
How to use this global parameter in record?
I've tried $MyTimeOut, but it doesn't work.
How to use this global parameter in record?
I've tried $MyTimeOut, but it doesn't work.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Handling unexpected Dialogs questions
Hi Stas_Tserk,
The way which was described by Stefan can be used in an User Code Action.
If you don't want to use User Code Actions, please add a Delay action to the recording module and create a new variable, which stores the timeout value.
After that, please bind the module variable to the global parameter. If the name of the module variable matches the name of the parameter, you could use the Auto-Bind function.
More information about data binding can be found in the user guide.
If you need more information, please do let me know.
Sincerely,
Johannes
The way which was described by Stefan can be used in an User Code Action.
If you don't want to use User Code Actions, please add a Delay action to the recording module and create a new variable, which stores the timeout value.
After that, please bind the module variable to the global parameter. If the name of the module variable matches the name of the parameter, you could use the Auto-Bind function.
More information about data binding can be found in the user guide.
If you need more information, please do let me know.
Sincerely,
Johannes