Page 1 of 1

Test Iteration Counts

Posted: Fri Sep 23, 2016 4:53 pm
by orko
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

Re: Test Iteration Counts

Posted: Wed Sep 28, 2016 8:34 am
by odklizec
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?

Re: Test Iteration Counts

Posted: Wed Sep 28, 2016 4:05 pm
by orko
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

Re: Test Iteration Counts

Posted: Wed Feb 28, 2018 11:12 pm
by tvu
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.

Re: Test Iteration Counts

Posted: Thu Mar 01, 2018 1:06 pm
by odklizec
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)?

Re: Test Iteration Counts

Posted: Thu Mar 01, 2018 8:00 pm
by tvu
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.

Re: Test Iteration Counts

Posted: Fri Mar 02, 2018 9:15 am
by odklizec
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.

Re: Test Iteration Counts

Posted: Fri Mar 02, 2018 8:38 pm
by tvu
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.

Re: Test Iteration Counts

Posted: Mon Mar 05, 2018 3:20 pm
by Support Team
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)

Re: Test Iteration Counts

Posted: Mon Mar 05, 2018 7:30 pm
by tvu
Thanks Markus!

Re: Test Iteration Counts

Posted: Fri Sep 21, 2018 11:50 am
by TimoL
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?

Re: Test Iteration Counts

Posted: Mon Sep 24, 2018 8:05 am
by Stub
Check to see if CurrentTestIterationActivity is non-null first? Or whichever property is null.

Re: Test Iteration Counts

Posted: Tue Sep 25, 2018 2:10 pm
by TimoL
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.

Re: Test Iteration Counts

Posted: Wed Sep 26, 2018 8:52 am
by Support Team
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)