Skip recording depending on ExcelSheet

Ranorex Spy, Recorder, and Studio.
IceT
Posts: 4
Joined: Fri May 09, 2014 2:39 pm

Skip recording depending on ExcelSheet

Post by IceT » Fri May 09, 2014 2:50 pm

Hello,

we are run our testcase data-driven by an Excel-Sheet. There are some recordings in the testcase, which we want to run dependently on a Cell from the Excel-Sheet. I give a little Example

testcase <- excel data-driven with some iterations.
recording1
recording2
recodring3

If a Excel-Cell is filled (has an value) in the iterations should recording1,recording2, recording3 be run.
If a Excel-Cell is empty (has no value) in the iterations should only recording1 and recording3 be run.

Is it possible to add a UserCode to the recording2, which decide if a Excel-Cell is filled or empty and if its empty, that skiped the recording2 and go to recording3?

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

Re: Skip recording depending on ExcelSheet

Post by Support Team » Tue May 13, 2014 11:43 am

Hello IceT,

It is possible to execute a recording from UserCode by using the Recording's Start() method or it is also possible to disable a certain module of a test case as described here: How to stop test case/ignore next iterations.
You could also add another test case for the second recording and check or uncheck it based on the specific value of the Excel-Cell. You could use the following structure:
SkipRecording.png
SkipRecording.png (11.65 KiB) Viewed 1454 times
In a UserCode action of Recording1 you can check or uncheck TestCase1 based on the value of your Excel-Cell.
Your code could be similar to the following one:
public void SkipRecording()
		{
			
			if(NewVariable=="0"){
				
				var testCase = TestSuite.Current.GetTestCase("TestCase1");
				testCase.Checked = false;
				
			}else{
				
				var testCase = TestSuite.Current.GetTestCase("TestCase1");
				testCase.Checked = true;
				
			}
		}
I hope this will help you to find a proper solution for your issue!

Regards,
Markus
.
Image

dochoa
Posts: 29
Joined: Tue Jul 16, 2013 11:36 pm

Re: Skip recording depending on ExcelSheet

Post by dochoa » Thu Jun 26, 2014 12:31 am

Hi Markus,

I tried using this method in our project but the problem is that my "TestCase1" is where the variable is bound to the data source so when I run the code where Recording1 is in the tree I get an error saying that the variable is not found (sorry, I don't have the exact text).

How do I get a test case the recognize the variables in the inner test cases?

Thanks,
Dan O.

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

Re: Skip recording depending on ExcelSheet

Post by krstcs » Thu Jun 26, 2014 1:24 pm

All you need to do is wrap the actions in Recording2 with an "if". You will need to select ALL of the actions and right-click, then select "Merge Items To User Code Item". Then right-click the merged item and select View Code.

Now you just need to add the if() {...} around the code inside the module and add a string parameter to take the value you want to use for the logic check.

Code: Select all

public void MergedUserCode(string dataVariableToCheck)
{
    if (!dataVariableToCheck.Equals(""))
    {
        //your test code should be here...
    }
}
Shortcuts usually aren't...

dochoa
Posts: 29
Joined: Tue Jul 16, 2013 11:36 pm

Re: Skip recording depending on ExcelSheet

Post by dochoa » Thu Jun 26, 2014 5:14 pm

Thanks again, krstcs, all the help has been awesome.

Forgive me for asking one more thing, how can I modify the code so that the report doesn't show this as an error but more of an info message that the variable value was not set in the report?

I have tweaked the error behavior so that my iterations run correctly but I can't get it to stop telling me there is a test case failure when I don't consider it a failure.

Thank you,
Dan O.

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

Re: Skip recording depending on ExcelSheet

Post by krstcs » Thu Jun 26, 2014 7:14 pm

Dan,

If you set it up the way I did it in the code I provided, you shouldn't get an error in the report for this.

If the logic returns true (the value is NOT blank) you should get the same result as before you wrapped it.
If the logic returns false (the value IS blank), you shouldn't get anything in the report since that section shouldn't run.

If you are getting an error, and the user code is not misconfigured (which might be the issue here), then you should make sure that the error is being thrown for this logic specifically. It could be that the error you are seeing is due to something else, like the actual test validation logic or object recognition is failing, which would be different.

What error are you getting specifically? Can you post a screen capture of it, or better, post the full report files? You can just zip the latest *.rxlog and *.data.rxlog that has the issue and post it here. Might be helpful in figuring out where the issue is.
Shortcuts usually aren't...

dochoa
Posts: 29
Joined: Tue Jul 16, 2013 11:36 pm

Re: Skip recording depending on ExcelSheet

Post by dochoa » Thu Jun 26, 2014 7:42 pm

Hi krstcs,

I was just about to respond with a solution I found when I noticed you already replied. Once again it is awesome how much you help others. Because of this you are the first person I have "friended" in this forum, so thank you very much.

What I ended up doing was using the:
Ranorex.Report.Info
line instead of throwing an exception which is meeting our current needs, but I wouldn't have found it without the help in the first place.

Thanks again,
Dan O.

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

Re: Skip recording depending on ExcelSheet

Post by krstcs » Thu Jun 26, 2014 8:08 pm

You are very welcome! If you need anything else, let me know!
Shortcuts usually aren't...