Page 1 of 1

Jumping to next test case using secondary Thread

Posted: Tue Aug 30, 2016 3:29 pm
by wellingtonsantana
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?

Re: Jumping to next test case using secondary Thread

Posted: Tue Aug 30, 2016 4:42 pm
by krstcs
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.

Re: Jumping to next test case using secondary Thread

Posted: Wed Aug 31, 2016 7:22 am
by odklizec
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).

Re: Jumping to next test case using secondary Thread

Posted: Thu Sep 29, 2016 8:16 pm
by wellingtonsantana
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.