Replay a test inside user code

Mobile Testing, Android App Testing.
Jeff
Posts: 9
Joined: Mon Oct 10, 2016 2:51 pm

Replay a test inside user code

Post by Jeff » Mon Oct 10, 2016 3:07 pm

Hi,

In our app we have an unexpected popup, which I can catch thanks to the codes examples in the doc.
When the popup appeared, I want to replay the test but I can't find anywhere how to do it. :cry:

If you need more details or you have any solutions, i'd be happy to discuss about it.
Thanks

Regards,
Jeff

__________________________
Setup:
Windows 7 Pro
Ranorex 6.1
Iphone 5 | IOS 10.0.2

User avatar
Vega
Posts: 109
Joined: Mon Jul 11, 2016 2:15 pm

Re: Replay a test inside user code

Post by Vega » Tue Oct 11, 2016 3:14 pm

Hi,

I'm not sure how your test is structured, but if you want to start a module you can do so like below:

<Module Name>.Start();

Example: I have a recording module named "cheese" and I can start it via code like so:

cheese.Start();

I'm not sure about the structure of your test(s) but it may be possible for you to take advantage of error behavior settings or a teardown section.

Maybe a screenshot of how your test is structured and what exactly you wish to replay would be helpful.

Jeff
Posts: 9
Joined: Mon Oct 10, 2016 2:51 pm

Re: Replay a test inside user code

Post by Jeff » Wed Oct 12, 2016 9:33 am

Hi Vega,

Thanks for your response, but it's not exactly what I want to do.
My post isn't clear, so here is exactly the behavior I expect:

I've a lot of recordings, inside different tests cases. In each tests a popup can appear, and I catch it thanks to the PopupWatcher.
This PopupWatcher launch a function, and in this function I want to replay the test where this popup appeared.
It's because this random popup make the test fails, so I want to restart the current recording where it happen. The problem is that it can be any test, not only one so I think I couldn't apply your response.

Here is a view of my code:
void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;

            PopupWatcher myPopupWatcher = new PopupWatcher();
            myPopupWatcher.Watch("what_I_want_to_catch", ReplayTest);
            myPopupWatcher.Start();
        }

public static void ReplayTest(Ranorex.Core.RxPath myPath, Ranorex.Core.Element myElement)  
        {
		//Here I want to restart the current recording without breaking the test workflow.
		//The test where the popup appeared should be replace
        }
Thanks again for your time,
I hope it will help you.

Regards,
Jeff

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

Re: Replay a test inside user code

Post by odklizec » Wed Oct 12, 2016 9:44 am

Hi,

I'm afraid, there is no way to replay a specific TC from code. Also, the problem is that the popupwatcher runs from different thread and there is currently no way to pause/restart the main thread from popupwatcher/second thread (the only workaround seems to be something like >this<)
The only thing you can probably do is to save the failing TCs somewhere (text file or so) make the entire test to fail/wait for finish and then restart the test with only specific test cases specified in a command line?
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

Jeff
Posts: 9
Joined: Mon Oct 10, 2016 2:51 pm

Re: Replay a test inside user code

Post by Jeff » Wed Oct 12, 2016 2:02 pm

Hi odklizec,

Thanks for your response, I will find a way like yours to replay the failed test cases after the run.
I will read carrefully your link,
Or maybe it will be very usefull to do like this for me:
-The popup appeared (OK)
-The popup watcher run my function (OK)
-My function break my recording (how?)
-My function close the popup (OK) and run the last action played (how?) in order to repair the recording (a touch for exemple)
-My function start the rest of my recording (how?)

So is there any possibilities to run the last action?
Unfortunately I think no, but why not...

Thanks for all

Regards,
Jeff

jma
Posts: 111
Joined: Fri Jul 03, 2015 9:18 am

Re: Replay a test inside user code

Post by jma » Fri Oct 14, 2016 10:14 am

Hi Jeff,

What could be done is to throw an exception in the popup watcher function. This doesn't fail your module/test case, but it would indicate an error in that test case.

Code: Select all

public static void ReplayTest(Ranorex.Core.RxPath myPath, Ranorex.Core.Element myElement)
{
        //Handle popup
	Validate.Fail();
}
error_in_popup_dialog_handler.png
error_in_popup_dialog_handler.png (4.53 KiB) Viewed 790 times
I'm afraid there is no way to start the last played action and the rest of the recording after closing the popup.

Jeff
Posts: 9
Joined: Mon Oct 10, 2016 2:51 pm

Re: Replay a test inside user code

Post by Jeff » Fri Oct 14, 2016 11:09 am

Thanks jma,

I will use it in combination with odklizec answer, to force the test case to fail, warn the user and replay the test at the end.
I write the test cases in a temporary file, at the end I recover the test cases names as strings.
I want to launch this tests, but I'm not able to find how I can start a test case with only his name.
Somobody have any idea?

Thanks a lot,
Regards

jeff

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

Re: Replay a test inside user code

Post by odklizec » Fri Oct 14, 2016 11:17 am

Hi,

You need to use /tc: command line parameter, as described here:
http://www.ranorex.com/support/user-gui ... html#c4827
Here is an example:

Code: Select all

test.exe /tc:test_case_name_string
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

Jeff
Posts: 9
Joined: Mon Oct 10, 2016 2:51 pm

Re: Replay a test inside user code

Post by Jeff » Mon Oct 17, 2016 9:46 am

Hi,

Thanks odklizec. In the popup handler, I'm only able to get the name of the current recording and not the test case.
So I can't replay the test case no?

Thanks,
Regards

Jeff

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

Re: Replay a test inside user code

Post by odklizec » Mon Oct 17, 2016 12:24 pm

Hi,

Luckily, there is a way to get the test case name from popup watcher thread.

Add this code to method called by popup watcher (the one which actually handles the unexpected dialog/element):

Code: Select all

	TestModuleLeaf curModule = (TestModuleLeaf)TestModuleLeaf.Current;
	string tcName = GetTestCaseName(curModule);
And this is the method, which returns actual test case name (at a time of processing popup watcher method):

Code: Select all

	public static string GetTestCaseName(TestSuiteEntry entry)
	{
		string tcName = string.Empty;
		while (entry != null)
		{
			if (entry is TestCaseNode)
			{
				tcName = entry.Name;
				break; 
			}
			entry = entry.Parent;
		}
		return tcName;			 	
	}
Eventually, you can use this method to return the "root" TestCase name, instead of immediate TestCase name (in case of nested structure of test cases)...

Code: Select all

	public static string GetTestCaseName(TestSuiteEntry entry)
	{
		string tcName = string.Empty;
		while (entry != null)
		{
			if (entry is TestCaseNode && (!(entry as TestCaseNode).IsRootTestCase))
			{
				tcName = entry.Name;
				break; 
			}
			entry = entry.Parent;
		}
		return tcName;			 	
	}
Hope this help? I got the second method from Ranorex support and after a small modification (first posted method), it turned out to be useful also in your case ;)
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

Jeff
Posts: 9
Joined: Mon Oct 10, 2016 2:51 pm

Re: Replay a test inside user code

Post by Jeff » Mon Oct 17, 2016 4:49 pm

Hi,

Thanks a lot it's exactly what I needed! :P
However I couldn't find anywhere how to launch several tests cases with code or command line, except by group this test cases inside a run config.
So how to create a run config and add tests inside with code? Or how to launch several tests with one command line?
Is it possible?

Regards,
Jeff

(Beginner)

Jeff
Posts: 9
Joined: Mon Oct 10, 2016 2:51 pm

Re: Replay a test inside user code

Post by Jeff » Wed Oct 19, 2016 5:07 pm

Hi,

Solved, thanks for your response.

Regards,
jeff