Handling unexpected Dialogs questions

Ask general questions here.
Stas_Tserk
Posts: 19
Joined: Tue Jan 27, 2015 4:09 pm

Handling unexpected Dialogs questions

Post by Stas_Tserk » Wed Mar 02, 2016 8:54 am

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.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Handling unexpected Dialogs questions

Post by odklizec » Wed Mar 02, 2016 9:38 am

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?
Pavel Kudrys
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

Stas_Tserk
Posts: 19
Joined: Tue Jan 27, 2015 4:09 pm

Re: Handling unexpected Dialogs questions

Post by Stas_Tserk » Wed Mar 02, 2016 10:31 am

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".

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);
        }
It builds, but doesn't close popup window.

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);
        	}
I can't find the difference in logic. Can you explain how it works?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Handling unexpected Dialogs questions

Post by odklizec » Wed Mar 02, 2016 10:38 am

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?
Pavel Kudrys
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

Stas_Tserk
Posts: 19
Joined: Tue Jan 27, 2015 4:09 pm

Re: Handling unexpected Dialogs questions

Post by Stas_Tserk » Wed Mar 02, 2016 10:54 am

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?
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.
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 (

Stas_Tserk
Posts: 19
Joined: Tue Jan 27, 2015 4:09 pm

Re: Handling unexpected Dialogs questions

Post by Stas_Tserk » Wed Mar 02, 2016 12:55 pm

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.

Stas_Tserk
Posts: 19
Joined: Tue Jan 27, 2015 4:09 pm

Re: Handling unexpected Dialogs questions

Post by Stas_Tserk » Wed Mar 02, 2016 4:20 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Handling unexpected Dialogs questions

Post by Support Team » Fri Mar 04, 2016 11:12 am

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:
Delay.Duration(TimeSpan.Parse(TestSuite.Current.Parameters["MyTimeOut"]));
Parsing is necessary because global parameters are stored as strings.

Hope that helps,
Stefan
.
Image

Stas_Tserk
Posts: 19
Joined: Tue Jan 27, 2015 4:09 pm

Re: Handling unexpected Dialogs questions

Post by Stas_Tserk » Sun Mar 06, 2016 10:28 am

Thanks support team!
How to use this global parameter in record?
I've tried $MyTimeOut, but it doesn't work.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Handling unexpected Dialogs questions

Post by Support Team » Mon Mar 07, 2016 3:19 pm

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.
delay_action.png
delay_action.png (2.51 KiB) Viewed 981 times
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.
unbound_variable.png
unbound_variable.png (5.58 KiB) Viewed 981 times
data_binding.png
data_binding.png (17.6 KiB) Viewed 981 times
More information about data binding can be found in the user guide.

If you need more information, please do let me know.

Sincerely,
Johannes
.
Image