Jumping to next test case using secondary Thread

Experiences, small talk, and other automation gossip.
wellingtonsantana
Certified Professional
Certified Professional
Posts: 18
Joined: Sat Jan 23, 2016 12:50 am
Contact:

Jumping to next test case using secondary Thread

Post by wellingtonsantana » Tue Aug 30, 2016 3:29 pm

Hello fellow Ranorex ,
I'm trying to create an "Error Inspector". This module basically creates a thread that monitors an unexpected error, such as a message on the screen. To identify this error , the code will send a command to jump to the next test case.
Below the code I had created to do this.

Code: Select all

public void StartErrorVerifier()
        {
        	try {
				Thread tErrorV = new Thread(errorVerificator);
				tErrorV.IsBackground = true;
				tErrorV.SetApartmentState(ApartmentState.STA);
				tErrorV.Start();        		
        	} catch (Exception) {
        		throw;
//        		Report.Error("ErrorInspector - Error launched");
//        		throw new RanorexException("ErrorInspector - Error launched");
//				Ranorex.Validate.Fail("An error message was showed until test execution.");
        	}

        public static void errorVerificator(){
    		while (true) {
        		if (repo.SmilesOMelhorProgramaDeMilhasS1.ErrorMessage_GenericInfo.Exists(Duration.FromMilliseconds(5000))) {
        			Report.Screenshot();
        			Report.Failure("An error message was showed until test execution.");
        			return;
        			#############################################
//        			throw new Ranorex.ValidationException("An error message was showed until test execution.");
//					#############################################
//        			Ranorex.Validate.Fail("An error message was showed until test execution.");
//        			return;
//					#############################################
//        			throw new RanorexException();
        		}
    		}
        }

        }
Unfortunately, each ways demonstrated on both methods failed , each one crashes Ranorex.
I'm trying to thread throws exception and its jumps to next iteration or just use Ranorex method to jump to next iteration .
Any idea to solve this situation?

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Jumping to next test case using secondary Thread

Post by krstcs » Tue Aug 30, 2016 4:42 pm

This is currently not possible with the way Ranorex is designed. You cannot directly manipulate the currently running test case from a different thread. You could add a variable in your test suite that you check before starting the next test case.

However, I would highly recommend re-working your test so that this is not necessary. I don't believe there is any real need for it. Ranorex already has all of the error handling that you should need.

I would also suggest that there should not be any "unexpected" errors in our tests that aren't bugs in the SUT (and should, therefore, force our tests to stop). The tests should be designed so that every single step is known before hand and should be accounted for. Even Ranorex's built-in Popup Handler should be used only as a last resort for things like network issues (which still should not be unexpected, and if they are then we need to have our network staff fix the problems) and other truly unrelated (to our SUT) environmental issues that don't need more than an "OK" clicked to dismiss the dialog. This is a core concept of testing (not just automation): Every variable should be accounted for and controlled in a test, otherwise our tests may be invalid because we can't account for everything.
Shortcuts usually aren't...

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

Re: Jumping to next test case using secondary Thread

Post by odklizec » Wed Aug 31, 2016 7:22 am

Hi all,

I have a second opinion ;) Unexpected errors can and do happen. They are especially likely to happen while testing internet-based apps. The ability to stop/pause the main thread from second "error-watcher" thread would be a very useful option.

For example, I'm occasionally experiencing a brief network outage, where it's usually enough to refresh the page few times and then the test continues as expected. It does not happen frequently, but it happens. And for such cases, it would be extremely helpful to have a second-thread "watcher", which could pause the main test thread, try to refresh the page (or do whatever else we want) and then resume or kill the test, based of the second-thread result. You see, it's definitely better to have such "fails-safe", which can easily prevent the test failure, than to have failed test, which typically runs for a few hours.

Using variable, as suggested by Kelly, is not much of an option in this particular case, because it would require adding second-thread handling before almost every test case/module. And this would add, in my opinion, an unnecessary clutter to the test suite. In other words, the ability to stop the main thread from second thread would be extremely helpful and it's something we are requesting for a while (probably since the introduction of popupwatcher in Ranorex 4).
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

wellingtonsantana
Certified Professional
Certified Professional
Posts: 18
Joined: Sat Jan 23, 2016 12:50 am
Contact:

Re: Jumping to next test case using secondary Thread

Post by wellingtonsantana » Thu Sep 29, 2016 8:16 pm

I agree with all opinions.
Bit in my mind, I need timeout in steps that I know where erros can happen or errors that I don't expected. If I know, sometimes a error is showing in a step, identify this error, capture screenshot, log error quickly and jump to next iteration, I don't need wait timeout in cases like that. More production in executions.