Test Iteration Counts
Test Iteration Counts
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
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.
Re: Test Iteration Counts
Hi,
You can use code like this to get the iteration number of given test case (I'm using it in my projects):Hope this helps?
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;
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
Re: Test Iteration Counts
Thanks! I modified it a little so I didn't have to pass in the string:
Before you gave me that, I was using something as a workaround that also seemed to work:
Joe
Code: Select all
int testCaseIdx = TestSuite.Current.GetTestCase(TestCaseNode.Current.Name).DataContext.CurrentRowIndex;
Code: Select all
int testCaseIdx = Ranorex.Core.Reporting.TestReport.CurrentTestCaseActivity.Children.Count
Re: Test Iteration Counts
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.
Thanks.
Code: Select all
int currentIterationIndex = TestSuite.Current.GetTestContainer(TestSuite.CurrentTestContainer.Name).DataContext.CurrentRowIndex;
Code: Select all
int currentIterationIndex2 = TestSuite.CurrentTestContainer.DataContext.CurrentRowIndex;
Re: Test Iteration Counts
Hi,
I'm successfully using this line:
Are you sure the code is used at appropriate place (and while running entire test suite)?
I'm successfully using this line:
Code: Select all
int currentIterationIndex = TestSuite.Current.GetTestContainer(TestSuite.CurrentTestContainer.Name).DataContext.CurrentRowIndex;
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
Re: Test Iteration Counts
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.
Re: Test Iteration Counts
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.
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 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
Re: Test Iteration Counts
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.
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.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Test Iteration Counts
Hi tvu,
You should be able to access to current iterationcount by using
Regards,
Markus (S)
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
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?
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
Check to see if CurrentTestIterationActivity is non-null first? Or whichever property is null.
Re: Test Iteration Counts
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.
Maybe it's better to have own variable and increase it in every iteration, if there's no other solution.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Test Iteration Counts
Hi TimoL,
You need to check if the CurrentTestIetarionActivity is not null. You can do this by using the following code
Please let me know if you need any further help.
Regards,
Markus (S)
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)