Enable SETUP/TEARDOWN via user code

Best practices, code snippets for common functionality, examples, and guidelines.
rea
Posts: 3
Joined: Wed May 30, 2018 10:59 am

Enable SETUP/TEARDOWN via user code

Post by rea » Tue Jul 23, 2019 1:18 pm

Hello everybody,

Is there any way to enable or disable setup/teardown in a test suite using user code?

The project looks similar to:

Code: Select all

SUITE
  |_SETUP
  |_SmartFolder
      |_SETUP
      |_Test case
      |_TEARDOWN
  |_SmartFolder
  |_TEARDOWN
Thank you

User avatar
Support Team
Site Admin
Site Admin
Posts: 11931
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Enable SETUP/TEARDOWN via user code

Post by Support Team » Wed Jul 24, 2019 7:51 pm

Hi Rea,

Unfortunately, we can only control the parent test containers in code (or with conditional execution), not setup/teardown regions. If you have a need for this to be possible, I recommend creating a new feature request on our User Voice platform.

If you are able to provide more details on what you are trying to achieve, perhaps we can provide an alternative or better method of doing it.

Cheers,
Ned
.
Image

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

Re: Enable SETUP/TEARDOWN via user code

Post by odklizec » Mon Aug 05, 2019 8:51 am

Hi,

I'm using below code to disable/enable every teardown section (including SF teardown sections) located in current test case:

Code: Select all

    //disable cur. TC teardown section 
    var curTestCase = (TestCaseNode)TestSuite.CurrentTestContainer; 
    foreach(TestModuleLeaf module in curTestCase.AllModules)  
    {  
        if (module.IsDescendantOfTearDownNode())
        {
            module.Enabled = false; //enable  to enable it  
        }
    } 
Hope this helps?
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

rea
Posts: 3
Joined: Wed May 30, 2018 10:59 am

Re: Enable SETUP/TEARDOWN via user code

Post by rea » Wed Aug 07, 2019 12:20 pm

Hello,

thank you both for the reply!
Odklizec, I tried your solution and it works but it is not exactly what I need. I want to enable/disable every teardown section from the first setup of the testSuite. Instead of getting the currentTestContainer I would like to pass the testContainers from a list that I have created, and then check if the setup/teardown is enabled or not and if not then enable it. But I can't do it like this because of a "cannot convert string to .....TestCaseNode" error. Do you have any idea if this is even possible?

Best Regards!

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

Re: Enable SETUP/TEARDOWN via user code

Post by odklizec » Wed Aug 07, 2019 12:50 pm

Hi,

I think this line of code should help?...

Code: Select all

var curTestCase = (TestCaseNode)TestSuite.Current.GetTestContainer(varTCName);
Where you can simply fill the varTCName with whatever TC name you want. Hope this helps?
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

rea
Posts: 3
Joined: Wed May 30, 2018 10:59 am

Re: Enable SETUP/TEARDOWN via user code

Post by rea » Wed Aug 07, 2019 3:45 pm

Hi,

Thank you, this was very helpful. I had to use (SmartFolderNode) instead of (TestCaseNode) but I got it working.

Regards