Command to stop iteration

Ranorex Spy, Recorder, and Studio.
Pixi6s
Posts: 92
Joined: Tue Jun 28, 2011 8:57 pm

Re: Command to stop iteration

Post by Pixi6s » Thu Jul 28, 2011 7:06 pm

Thank.

Our data is ever changing and I can't make the sql source query a variable it change it on the fly, but waybe I can make my query more specific. thanks for the info

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

Re: Command to stop iteration

Post by odklizec » Fri Sep 07, 2012 2:43 pm

Hi folks,

Sorry for bringing this old discussion back. I want to stop the iteration if there is issued an unexpected dialog.

I added throw new RanorexException("string") (discussed in this topic) at the appropriate place in my unexpected window handling procedure. The iteration is now stopped but it shows the "Unexpected exception" dialog with Break/Terminate buttons. This is not what I want. What I want is to stop the iteration (at the point of exception) without the need of user action and then continue with next iteration.

I tried to enclose the window handling procedure in Try...Catch and the exception is now handled by the Catch block. "Unexpected exception" dialog is no longer displayed. The problem is that the iteration is not stopped! It continues with next test case step, which of course fails, because of previously displayed and handled unexpected dialog.

Any idea how to improve my code to stop the iteration at the point of new thrown exception (and without displaying the unexpected exception dialog)? Here is my code...

Code: Select all

public static void ClosePopUpDialogs()  
		{  
        while (true)  
        	{  
        	try
        	  {
            	if (repo.Warning.SelfInfo.Exists() )  
            	{  
                	Thread.Sleep(300);  
                	Report.Screenshot(repo.Warning.Self);  
                	repo.Warning.Warning3.ButtonOK2.Click();               	
            	}  
            	if (repo.FileNotSupported.SelfInfo.Exists())  
            	{  
                	Thread.Sleep(300);  
                	Report.Screenshot(repo.FileNotSupported.Self);  
                	repo.FileNotSupported.FileNotSupported3.ButtonOK2.Click();
                	throw new RanorexException("File not supported!");
            	}  
            	if (repo.InsufficientFileversion.SelfInfo.Exists())
            	{  
                	Thread.Sleep(300);  
                	Report.Screenshot(repo.InsufficientFileversion.Self);  
                	repo.InsufficientFileversion.QWidget5.Abort.Click();
                	throw new RanorexException("Incorrect file version!");
            	}          	
            	if (repo.FatalError.SelfInfo.Exists())
            	{  
                	Thread.Sleep(300);  
                	Report.Screenshot(repo.FatalError.Self);  
                	repo.FatalError.QWidget4.ButtonOK.Click();
               	
            	}
            	Thread.Sleep(500);  
        	  }
        	catch (Exception e)
        	  {
        		Report.Error("Unexpected exception occurred: " + e.ToString());
        	  }
        	}  
    	} 
Thank you in advance and have a nice weekend!
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

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

Re: Command to stop iteration

Post by Support Team » Mon Sep 10, 2012 3:34 pm

Hi,

Tobias wrote the following:
you can do this by calling Report.Failure(String) within you user code if you know, you are not in the correct product page. Report.Failure will make your iteration stop and by selecting "Continue with iteration" for Error behavior in your Test Case settings the next iteration will be executed.
Did you already try it this way?

Regards,
Markus
Ranorex Support Team
.
Image

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

Re: Command to stop iteration

Post by odklizec » Mon Sep 10, 2012 4:09 pm

Hi Markus,

Thanks for the reply. No, I did not try Report.Failure(String) because in his following post (this one) Tobias said this:
Sorry my colleague mixed something up. Report.Failure() logs a logical failure (e.g. test step failure) message and it doesn't abort the whole iteration. If you want to abort the whole iteration you have to throw a new exception.
So I tried the "new exception" way but it shows "Unexpected exception" dialog which requires user input. And this is unfortunately not very useful ;)
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

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

Re: Command to stop iteration

Post by Support Team » Mon Sep 10, 2012 4:38 pm

Hi,

Oh sorry :oops:, I should have really read the whole forum post carefully, ashes on my head, this is of course true, what you can do to skip the iteration is to use a "wrong" validation:
Validate.IsFalse(true);
Regards,
Markus
Ranorex Support Team
.
Image

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

Re: Command to stop iteration

Post by odklizec » Mon Sep 10, 2012 5:51 pm

Hi Marcus,

No problem ;) And thanks for the tip! I will try it as the first thing tomorrow.
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

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

Re: Command to stop iteration

Post by odklizec » Tue Sep 11, 2012 8:08 am

Hi Markus,

I'm afraid, the trick you suggested throws ValidationException with Break/Terminate buttons. In other words, the result is the same like using "throw new RanorexException" and therefore not very useful, because it requires user input. In addition, "Break" only pauses the test case run and "Terminate" kills the test case run. What I want is just to skip the actual iteration and continue with the next one. Any other idea? ;)
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

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

Re: Command to stop iteration

Post by odklizec » Tue Sep 11, 2012 12:03 pm

OK, a small update. I found that I need to set the "exceptionOnFail" to false (to suppress the exception). So instead of this...

Code: Select all

Validate.IsFalse(true);  
I'm using this...

Code: Select all

Validate.IsFalse(true,"Incorrect file!",false);
The problem is that it does not stop the iteration. Could it be because I'm using this validation code in another thread (unexpected windows handling procedure)?
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

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

Re: Command to stop iteration

Post by Support Team » Wed Sep 12, 2012 2:38 pm

Hi,

That's because the exception forces the iteration to stop and if there is no exception the iteration will not stop.
Yes this could of course be the case, because if you execute the specific code in your Thread and the exception is thrown the exception handler of that thread will catch that method, although the handler of the test suite should be the one which should catch it.

Regards,
Markus
Ranorex Support Team
.
Image

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

Re: Command to stop iteration

Post by odklizec » Thu Sep 13, 2012 7:14 am

Hi Markus,

Thanks for the reply! So what are my options? All I need is to stop the test case at some point but without displaying an exception dialog, which requires user input. Is there a way to achieve this in threaded environment? If so how? I'm sorry, but I'm new in .Net coding ;)

I just tried the Validate.IsFalse(true,"Incorrect file!") and Validate.IsFalse(true,"Incorrect file!",false) in a single threaded test case.

The first one (without suppressing the exception) works exactly as I want! It simply terminates the test case at that point and no exception dialog is displayed!

The second code (with suppressed exception) simply sets the "Validation failed" to report and because it suppress exception, the test case continues as if nothing happened.

So it works without exception dialog in single threaded test case, but not in multi-threaded test case. Any suggestion? Thank you in advance!
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

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

Re: Command to stop iteration

Post by odklizec » Thu Sep 13, 2012 1:14 pm

OK, I think I solved my problem! Instead of killing the iteration from another thread (from unexpected window handler), I just set a global variable in that second thread. Then I created a new "User Code" action right after the action where an unexpected dialog may appear. In this User Code I evaluate the global variable. If the variable is true, I know an unexpected dialog appeared in previous step and then I use the above Validate function to kill the iteration and no exception dialog is displayed, because the user code is called from the main thread. Simple yet effective solution ;)
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

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

Re: Command to stop iteration

Post by Support Team » Fri Sep 14, 2012 2:25 pm

Hi,

This is a good solution.
I am glad you were able to solve the issue :).

Regards,
Markus
Ranorex Support Team
.
Image