Mark iteration as success and skip therest of the recordings

Best practices, code snippets for common functionality, examples, and guidelines.
bpdyna
Posts: 13
Joined: Wed Mar 30, 2016 2:11 pm

Mark iteration as success and skip therest of the recordings

Post by bpdyna » Tue Jul 12, 2016 4:10 pm

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

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

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

Post by Vaughan.Douglas » Tue Jul 12, 2016 5:23 pm

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:
Doug Vaughan

bpdyna
Posts: 13
Joined: Wed Mar 30, 2016 2:11 pm

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

Post by bpdyna » Thu Jul 14, 2016 11:36 am

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 :)

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

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

Post by Vaughan.Douglas » Thu Jul 14, 2016 12:55 pm

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.
Doug Vaughan

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

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

Post by Vaughan.Douglas » Thu Jul 14, 2016 2:56 pm

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.
Doug Vaughan

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

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

Post by Vaughan.Douglas » Mon Jun 05, 2017 1:07 pm

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.
Doug Vaughan