Test Iteration Counts

Ranorex Studio, Spy, Recorder, and Driver.
User avatar
orko
Posts: 9
Joined: Wed Sep 14, 2016 9:28 pm
Location: Bartlesville, OK

Test Iteration Counts

Post by orko » Fri Sep 23, 2016 4:53 pm

Hello,

I'm trying to obtain (for reporting) the iteration that is currently running, of both the test case and also the sub-test case of a test suite in User Code.

For instance, I have this test scenario:

Test Case 1 (rows: 3)
- Test Case A (rows: 5)
- Test Case B (rows: 2)

I'd like to be able to obtain the main Test Case (Test Case 1) iteration, and also the sub-test case (Test Case A or B) iteration #. In this instance, if I have both A and B selected to run, I should see 15 (3 iterations of 5 iterations) of Test Case A and 6 (3 iterations of 2 iterations) of Test Case B.

So if I only have B selected, I should see:

Test Case 1 Iteration #1, Test Case B Iteration #1
Test Case 1 Iteration #1, Test Case B Iteration #2
Test Case 1 Iteration #1, Test Case B Iteration #3
Test Case 1 Iteration #2, Test Case B Iteration #1
Test Case 1 Iteration #2, Test Case B Iteration #2
Test Case 1 Iteration #2, Test Case B Iteration #3

I've tried what is described here: http://www.ranorex.com/forum/number-of- ... =iteration and it only gives the iteration of the main test case (Test Case 1 above). How do I get the current iteration of the sub-test cases?

Thanks in advance,
Joe
Last edited by orko on Wed Sep 28, 2016 4:13 pm, edited 1 time in total.

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

Re: Test Iteration Counts

Post by odklizec » Wed Sep 28, 2016 8:34 am

Hi,

You can use code like this to get the iteration number of given test case (I'm using it in my projects):

Code: Select all

int tcIteration = TestSuite.Current.GetTestCase("TestCaseName").DataContext.CurrentRowIndex;
Hope this helps?
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
orko
Posts: 9
Joined: Wed Sep 14, 2016 9:28 pm
Location: Bartlesville, OK

Re: Test Iteration Counts

Post by orko » Wed Sep 28, 2016 4:05 pm

Thanks! I modified it a little so I didn't have to pass in the string:

Code: Select all

int testCaseIdx = TestSuite.Current.GetTestCase(TestCaseNode.Current.Name).DataContext.CurrentRowIndex;
Before you gave me that, I was using something as a workaround that also seemed to work:

Code: Select all

int testCaseIdx = Ranorex.Core.Reporting.TestReport.CurrentTestCaseActivity.Children.Count
Joe

tvu
Posts: 195
Joined: Tue Apr 07, 2015 10:47 pm

Re: Test Iteration Counts

Post by tvu » Wed Feb 28, 2018 11:12 pm

How do we get the current iteration index for a test case in Ranorex v8? I've tried the two ways below, but always get a 0.

Code: Select all

int currentIterationIndex = TestSuite.Current.GetTestContainer(TestSuite.CurrentTestContainer.Name).DataContext.CurrentRowIndex;

Code: Select all

int currentIterationIndex2 = TestSuite.CurrentTestContainer.DataContext.CurrentRowIndex;
Thanks.

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

Re: Test Iteration Counts

Post by odklizec » Thu Mar 01, 2018 1:06 pm

Hi,

I'm successfully using this line:

Code: Select all

int currentIterationIndex = TestSuite.Current.GetTestContainer(TestSuite.CurrentTestContainer.Name).DataContext.CurrentRowIndex;
Are you sure the code is used at appropriate place (and while running entire test suite)?
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

tvu
Posts: 195
Joined: Tue Apr 07, 2015 10:47 pm

Re: Test Iteration Counts

Post by tvu » Thu Mar 01, 2018 8:00 pm

Where would be the appropriate location? I attached a test solution and tried several different locations. I get the same issue where the current iteration index is always 0.
You do not have the required permissions to view the files attached to this post.

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

Re: Test Iteration Counts

Post by odklizec » Fri Mar 02, 2018 9:15 am

OK, I now see the cause of issue. The problem is, that the suggested methods are designed to work with data connector iteration! In your case, you are not using data connector but instead testcase/smart folder iteration. Unfortunately, I found no equivalent "count" method for this kind of loop. There seems to be something called RunIterationCount, but this returns total iteration number set in given test case/smart folder. In other words, there seems to be no count method for test case/ smart folder iteration?

What you can do, is to implement your own "iteration count" mechanism, using global parameter and module variable. See the attached sample.
You do not have the required permissions to view the files attached to this post.
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

tvu
Posts: 195
Joined: Tue Apr 07, 2015 10:47 pm

Re: Test Iteration Counts

Post by tvu » Fri Mar 02, 2018 8:38 pm

Hi odklizec,

Thanks for the suggestion. It will get the job done for what I need, but there is an issue. The index isn't set correctly if you are iterating the Smart Folder and the code module LogCurrentIteration is in a test case.

Previously, I also notice that RunIterationCount only returns the total iteration number. The Ranorex report shows the proper iteration index when iterating on the Smart Folder and the Test Case level. There must be a more direct way of getting this value.

Ranorex Support, do you have an answer for this?

Thanks again.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Test Iteration Counts

Post by Support Team » Mon Mar 05, 2018 3:20 pm

Hi tvu,

You should be able to access to current iterationcount by using
var currentIterationIndex = Ranorex.Core.Reporting.TestReport.CurrentTestIterationActivity.Index;
Please let me know if you have any further questions about the iteration index.

Regards,
Markus (S)

tvu
Posts: 195
Joined: Tue Apr 07, 2015 10:47 pm

Re: Test Iteration Counts

Post by tvu » Mon Mar 05, 2018 7:30 pm

Thanks Markus!

TimoL
Posts: 46
Joined: Thu Sep 13, 2018 3:08 pm

Re: Test Iteration Counts

Post by TimoL » Fri Sep 21, 2018 11:50 am

Hi,

I 'm typing iteration count on keyboard by:
Keyboard.Press(Ranorex.Core.Reporting.TestReport.CurrentTestIterationActivity.Index.ToString());

It works fine when the test case has iterations, but when there's no iterations (Iteration count: 1), the test leads to an error "Object reference not set to an instance of an object". How to avoid that in a case of one iteration only?

User avatar
Stub
Posts: 515
Joined: Fri Jul 15, 2016 1:35 pm

Re: Test Iteration Counts

Post by Stub » Mon Sep 24, 2018 8:05 am

Check to see if CurrentTestIterationActivity is non-null first? Or whichever property is null.

TimoL
Posts: 46
Joined: Thu Sep 13, 2018 3:08 pm

Re: Test Iteration Counts

Post by TimoL » Tue Sep 25, 2018 2:10 pm

Actually I had if sentence to check that Ranorex.Core.Reporting.TestReport.CurrentTestIterationActivity.Index is not null. Compiler warns that it's never null. Tried the same for Ranorex.Core.Reporting.TestReport.CurrentTestIterationActivity as well.

Maybe it's better to have own variable and increase it in every iteration, if there's no other solution.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Test Iteration Counts

Post by Support Team » Wed Sep 26, 2018 8:52 am

Hi TimoL,

You need to check if the CurrentTestIetarionActivity is not null. You can do this by using the following code
var currentActivity = Ranorex.Core.Reporting.TestReport.CurrentTestIterationActivity;
			if(currentActivity!=null)
			{
				var currentIndex = currentActivity.Index;
				Report.Info("Current Iteration: "+ currentIndex);
			}
			else{
				Report.Info("Test case does not have an iteration");
			}
This will work with Data connectors as well as with Test Case iterations.

Please let me know if you need any further help.

Regards,
Markus (S)