Page 1 of 1

Mark iteration as success and skip therest of the recordings

Posted: Tue Jul 12, 2016 4:10 pm
by bpdyna
Hello,

I have looked through the forum for some code to solve my issue, but have not found exactly what I want to achieve.

My issue
I have a testcase with 10 recordings. We use a data-driven method to create iterations on this test case.
Most iterations are about the "happy-flow" where you follow all the steps from beginning to end and then you're done. Some iterations however are used to test non-happy flow; these end in a certain results on recording 6 after which the test case is actually successful. At this point there is no need to run recording 7-10 anymore.
Ordinarily I would create a separate testcase for these non-happy flows, but for this project I do not want to do that. The AUT is a Magento-based website with 9 different store views. Most store views are the more or less the same, so I created a testcase for each store view and want to apply data-driven to them. Creating a separate testcase for all 9 store views, would mean that I end up with 18 testcases, rather than 9. This would also mean we need to maintain 18 testcases and maintain 18 data sources. This is something we want to avoid.

In more detail
From the 10 recordings in a testcase, I want to call a specific method by means of an IF-statement and perform some validation checks. When this IF-statement is called and the validation checks are all successful, I need a piece of code that will then:
- Skip the remaining recordings 7-10.
- Mark the iteration as successful.
- Continue with the next iteration.


I have checked several threads already, but none of the below provide me with an answer:
http://www.ranorex.com/forum/how-to-ove ... t6354.html
http://www.ranorex.com/forum/skip-itera ... t7917.html
http://www.ranorex.com/forum/skip-recor ... t6153.html

Re: Mark iteration as success and skip therest of the recordings

Posted: Tue Jul 12, 2016 5:23 pm
by Vaughan.Douglas
I think I understand what you're trying to accomplish, basically you want to end the iteration if after step 6 the status = Success.

Is there a reason you can't just nest 7-10 in their own testcase and skip them as needed. Here is a snippet of the code where I've implemented similar functionality:

Code: Select all

            
If Not execute Then
   'http://www.ranorex.com/forum/how-to-force-a-test-iteration-to-skip-t3360.html
   'http://www.ranorex.com/forum/starting-testcase-by-condition-t3899.html
   TestSuite.Current.GetTestCase(TestCaseNode.Current.Name.ToString & "_RUN").Checked = False
   ActivityStack.Current.CustomProperties("ignore") = " "
   ActivityStack.Current.Parent.CustomProperties("ignore") = " "

Else
   TestSuite.Current.GetTestCase(TestCaseNode.Current.Name.ToString & "_RUN").Checked = True
End If
For context I used a naming convention where the nested testcase was name the same as the parent with a "_RUN" appended to the end.

So it's like this

Parent Test Case "Do_Something"
Nested test case "Do_Something_RUN"

This way I could create a single coded module to handle all of my test cases.

The variable "execute" is a bln based on a case statement that isn't relevant. You could just key off status of the current iteration.

My initial sources are commented in my code because I just can't be asked to remember it on my own :roll:

Re: Mark iteration as success and skip therest of the recordings

Posted: Thu Jul 14, 2016 11:36 am
by bpdyna
Thanks for your input.

You understood exactly what I am trying to do. I was hoping it could be done without moving those recordings 7-10 to a new nested testcase, but for now I am happy with this solution.

I have named the child testcase "_Payment" and have put the following line in code:

Code: Select all

string ChildTestCase = TestCaseNode.Current.Name + "_Payment";
        	TestSuite.Current.GetTestCase(ChildTestCase).Checked = false;
The code

Code: Select all

TestSuite.Current.GetTestCase(TestCaseNode.Current.Name.ToString & "_RUN").Checked = False
did not build well and gave me an error:
Operator '&' cannot be applied to operands of type 'method group' and 'string' (CS0019)

By using the 1st piece of code above I worked around this and it is now working properly to skip the underlying child testcase.

Thank you very much :)

Re: Mark iteration as success and skip therest of the recordings

Posted: Thu Jul 14, 2016 12:55 pm
by Vaughan.Douglas
Operator '&' cannot be applied to operands of type 'method group' and 'string' (CS0019)
My sample was in VB and based on the semicolons at the end of your sample code you're using C#

I think this code would work

Code: Select all

TestSuite.Current.GetTestCase(TestCaseNode.Current.Name.ToString + "_RUN").Checked == false;
It's hard for me to keep the nuances of both languages in my head at the same time, so I use Telerik's code converter to switch back and forth.

I understand not wanting to use nested test cases, in my case I have a testcase with a single module containing the above discussed logic which then acts on the nested test case, I'd much rather just have a testcase where the first module does the check and terminates the test case all within itself. I was not able to find a way to do this while maintaining status = success.

I'm sure someone will eventually come along and straighten us both out.

Re: Mark iteration as success and skip therest of the recordings

Posted: Thu Jul 14, 2016 2:56 pm
by Vaughan.Douglas
I found another potential solution

Code: Select all

var tc1=(TestCaseNode) TestCaseNode.Current ;
           
foreach(TestModuleLeaf a in tc1.AllModules)  
      {  
           a.Enabled = false;  
           Report.Info("TestModuleLeaf disable."+a.Name);
      } 
Rather than collecting ALL of the modules, you would collect the ones that haven't run. Not sure how you'd do this, you might be able to look for a property that indicates a module hasn't been run in the current iteration.

I'm not going to refactor my current code to incorporate this, but I will look at this solution the next time the opportunity presents itself.

Re: Mark iteration as success and skip therest of the recordings

Posted: Mon Jun 05, 2017 1:07 pm
by Vaughan.Douglas
I still reference this topic, so I thought I'd throw in an update for Ranorex 7.x

The object GetTestCase has been replaced by GetTestContainer and TestCaseNode.Current is now TestSuite.CurrentTestContainer

So
TestSuite.Current.GetTestCase(TestCaseNode.Current.Name.ToString + "_RUN").Checked == false;
is now
TestSuite.Current.GetTestContainer(TestSuite.CurrentTestContainer.Name.ToString + "_RUN").Checked == false;
I have not had an opportunity to test out these changes to ensure they still function completely as expected.