Forum Discussion

mrdwprice's avatar
mrdwprice
Contributor
6 years ago
Solved

Disable specific testcases in a particular Environment

Can anybody give me an example Setup Script or TearDown Script that can disable specific Testcases in a particular Environment?

 

 For example

 

Environment 1

Environment 2

Environment 3

 

Project

TestSuite

Testcase1

Testcase2

TestSuite

Testcase3

Testcase4

TestSuite

Testcase5

Testcase6

 

 

If Environment = Environment 1,Environment 3

then disable Testcase 1, Testcase 4, Testcase 6

else enable all.

 

 

I can’t see that using tags is environment specific, so I guess a script is the way to go.

 

Thanks!

  • Here is how you get the environment name and disable a test case. In your teardown script just change setDisabled to false to enable the test case again.

     

    //get the environment name
    def env =  runner.project.getActiveEnvironment().name
    
    //disable  the test case
    def ts = runner.project.getTestSuiteByName("testSuiteName")
    def tc = ts.getTestCaseByName("testCaseName")
    tc.setDisabled(true)

3 Replies

  • Here is how you get the environment name and disable a test case. In your teardown script just change setDisabled to false to enable the test case again.

     

    //get the environment name
    def env =  runner.project.getActiveEnvironment().name
    
    //disable  the test case
    def ts = runner.project.getTestSuiteByName("testSuiteName")
    def tc = ts.getTestCaseByName("testCaseName")
    tc.setDisabled(true)
    • nmrao's avatar
      nmrao
      Champion Level 3
      It would easy for the users if you specify if the above script is a setup of test suite or groovy script etc.,
    • mrdwprice's avatar
      mrdwprice
      Contributor

      I've used the below as a TearDown script

       

      Thanks!

      //get the environment name
      def env = runner.project.getActiveEnvironment().name
      //def testsuite name
      def ts = runner.project.getTestSuiteByName("TestSuite1")
      
      //disable the test suite
      if (env == "Environment1"|| env == "Environment3")
      {
      ts.setDisabled(false)
      }
      else
      {
      ts.setDisabled(true)
      }