Page 1 of 1

Enable SETUP/TEARDOWN via user code

Posted: Tue Jul 23, 2019 1:18 pm
by rea
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

Re: Enable SETUP/TEARDOWN via user code

Posted: Wed Jul 24, 2019 7:51 pm
by Support Team
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

Re: Enable SETUP/TEARDOWN via user code

Posted: Mon Aug 05, 2019 8:51 am
by odklizec
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?

Re: Enable SETUP/TEARDOWN via user code

Posted: Wed Aug 07, 2019 12:20 pm
by rea
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!

Re: Enable SETUP/TEARDOWN via user code

Posted: Wed Aug 07, 2019 12:50 pm
by odklizec
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?

Re: Enable SETUP/TEARDOWN via user code

Posted: Wed Aug 07, 2019 3:45 pm
by rea
Hi,

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

Regards