BeforeEach like Setup

Best practices, code snippets for common functionality, examples, and guidelines.
TestBalloon
Posts: 15
Joined: Thu Mar 03, 2022 9:19 am

BeforeEach like Setup

Post by TestBalloon » Mon Apr 11, 2022 5:00 pm

Hello,
I have several test cases which all have different recording modules in them, but the setup and teardown is exactly the same for all.

Code: Select all

TC1
    Setup A
     Module 1
TC2
     Setup A
     Module 2
TC3
    Setup A
     Module 3
Is there a way to reuse a Setup section I have defined once, for all the test cases? (So it will execute BeforeEach test case)
For now I can only copy-paste all recording modules from one setup to the next. I am worried that if we have to change the setup we might have to re-copy-paste hundreds of setup nodes which are virtually the same :/

Haven't found a way to execute test cases from within ranorex, like with TestSuiteRunner and TestModuleRunner. Where is TestCaseRunner? If that was there I could have used that.

Any suggestions that don't include starting ranorex from command line with the tc: argument?

Thank you.

User avatar
doke
Posts: 112
Joined: Fri Mar 29, 2019 2:33 pm

Re: BeforeEach like Setup

Post by doke » Tue Apr 12, 2022 1:56 pm

Hi,

1. You can add a Setup And Teardown to the TestSuite

2. Do you already use runconfigurations ? this solves probably some part of your problem.

Regards,
Don

TestBalloon
Posts: 15
Joined: Thu Mar 03, 2022 9:19 am

Re: BeforeEach like Setup

Post by TestBalloon » Wed Apr 13, 2022 7:55 am

Hello doke,

using the test suite setup won't help, beause that setup is only executed once before then running all test cases selected with a run configuration.
I want a setup which runs beforeEach testcase (So if there are 3 testcases I want the setup to run 3 times).

User avatar
doke
Posts: 112
Joined: Fri Mar 29, 2019 2:33 pm

Re: BeforeEach like Setup

Post by doke » Thu Apr 14, 2022 10:22 am

Hi,

You could use a moduleGroup in the setup of each testcase.
the ModuleGroup would consist of the all the setup recordings.

Regards,

Don

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

Re: BeforeEach like Setup

Post by odklizec » Thu Apr 14, 2022 10:54 am

Hi,

What you are asking for is not directly doable with Ranorex. The only easy 'workaround' I can think of is creating a 'root' smartfolder, enclosing all test cases. Then there should be a data connector in this smartfolder, where number of rows = number of test cases and then each row should be connected via condition to test each case. Like this...
ConditionalTCs.png
So basically, each SF iteration will run Setup section for every single TC. This is probably the easiest (but somewhat complicated) solution.
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

TestBalloon
Posts: 15
Joined: Thu Mar 03, 2022 9:19 am

Re: BeforeEach like Setup

Post by TestBalloon » Fri Apr 22, 2022 9:46 am

Hello Doke, odklizec,

thank you for your suggestions.
I like dokes idea, that would have worked if I used a regular setup, however, I enable/disable some recording modules in the setup node via custom code dynamically. Unfortunately it is impossible to disable modules inside a module group, so I cannot use your idea...

The smart folder idea would work, but the report would not be readable anymore, since every non-executed smart folder will get reported. So if I have 100 test cases then the report contains 10000 nodes of which only 100 are relevant. See this example with 4 nodes of which 2 are relevant:
ExampleReport.png
This is really tricky :D No tradeoff-free solution.
I think we will accept the copy&paste tradeoff then, which was my initial issue.
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: BeforeEach like Setup

Post by odklizec » Fri Apr 22, 2022 10:22 am

Hi,

Well, there is also another solution. Instead of using built-in SF/TC conditions, you can disable/enable TC/SF via code. In this case, there will be no "unplayed" test cases mentioned in report ;)

Just add a code module to SF setup section (from my original idea) and in this code module read the actual iteration value from SmartFolder and based of this enable/disable individual test cases, using this code:

Code: Select all

TestSuite.Current.GetTestCase("TestCaseName").Checked = false;

Code: Select all

var getTestCase = TestSuite.Current.GetTestContainer("SmartFolderName");
string columValue= getTestCase.DataContext.CurrentRow.Values[0];
if (columValue = "A")
{
    TestSuite.Current.GetTestContainer("TestCase1").Checked = true;
    TestSuite.Current.GetTestContainer("TestCase2").Checked = false;
    TestSuite.Current.GetTestContainer("TestCase3").Checked = false;
    TestSuite.Current.GetTestContainer("TestCase4").Checked = false;
}
else if (columValue = "B")
{
    TestSuite.Current.GetTestContainer("TestCase1").Checked = false;
    TestSuite.Current.GetTestContainer("TestCase2").Checked = true;
    TestSuite.Current.GetTestContainer("TestCase3").Checked = false;
    TestSuite.Current.GetTestContainer("TestCase4").Checked = false;
}
...
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