Forum Discussion

TonnyLi's avatar
TonnyLi
New Contributor
2 years ago
Solved

Disable test cases depending on environment

In my project I have several test suites and several test cases in the each test suite. Quite normal.

All test cases have the same test steps, the differences are the payload. Something like this:

- generate access token

- Initiate

- signing

- execute

- get status

All these test steps are valid for our test environment. But for our sand box, which is more simple, we just need the following test steps:

- initiate

- execute

- get status

To be able to use the same test cases in both environments I would like to disable two test steps when executing my test cases against our sand box.

I have tried several methods but failed.

The optimal situation would be that all those test steps get disabled in all test cases when I change to the sandbox environment and get enabled when I change back to our test environment.

Could that be done on "Function Test-level", using SetUp Script/TearDown Script or using the Event Handler or are there any other methods for this?

Someone that knows?

 

  • Hi TonnyLi ,

     

    In your project setup script, you could try something like this:

    //given your environment config name is = "sandbox"
    
    project.testSuiteList.each { suite ->
    		suite.testCaseList.each { kase ->
    			kase.testStepList.each { step ->
    				if (step.name == "generate access token") {
    					if (project.activeEnvironment.name.contains("sandbox")){
    						step.setDisabled(true)
    						}else{
    						step.setDisabled(false)
    						}
    				}
    			}
    		}
    	}

     

  • WoW! It worked! Thanks alot JoostDG!

    /Tonny

6 Replies

  • JoostDG's avatar
    JoostDG
    Frequent Contributor

    Hi TonnyLi ,

     

    In your project setup script, you could try something like this:

    //given your environment config name is = "sandbox"
    
    project.testSuiteList.each { suite ->
    		suite.testCaseList.each { kase ->
    			kase.testStepList.each { step ->
    				if (step.name == "generate access token") {
    					if (project.activeEnvironment.name.contains("sandbox")){
    						step.setDisabled(true)
    						}else{
    						step.setDisabled(false)
    						}
    				}
    			}
    		}
    	}

     

    • TonnyLi's avatar
      TonnyLi
      New Contributor

      WoW! It worked! Thanks alot JoostDG!

      /Tonny

    • TonnyLi's avatar
      TonnyLi
      New Contributor

      Hm...no, not really. It is some test steps I would like to disable in every test case. Not test cases. 

  • when am suing above code getting below error.

    com.eviware.soapui.support.scripting.ScriptException: Error in Setup Script of Get_Pay_Off_Quote_allchannels

     

    please could you suggest...any lib file need to place or import function need to add.

    • JoostDG's avatar
      JoostDG
      Frequent Contributor

       Vigneshwaranit : I assume that is either because you are not running this script from the project setup script OR something else in your setup script fails. The above script was confirmed working from the project setup script, no need for any additional imports. Of course, you need to adjust the values "generate access token" & "sandbox" to your use case. 

       

      If first issue, you have to know that each place where you can do scripting has a limited set of "objects" you can use. Project setup script has these:

      A test case setup script has these:

      This means you cannot use a statement like project.testSuiteList in a test case setup script.

      To get the project object, you will need to use statement:  testCase.testSuite.project

       

      If second issue: You need to look in your "Error Log" tab to know what exactly is the issue (you will see line number where it breaks and more info)