free seo tool

Groovy script to Disable/ Enable soapUI test case

While performing web services automation testing, we might need to disable/ enable test cases on the fly, means via scripting. In this post, we will see how can we access test cases on the fly by using Groovy Script and how to enable/ disable it while doing web services testing.

Add a test step Groovy Script to the test case, this is our editor for performing the operation. The test step has object named "context" which will give access to the current context. We will get a handle to the TestSuite level by using the context object.

 def testSuite = context.testCase.testSuite;
 def totalTestCases = testSuite.getTestCases().size();

 for(n in (0..totalTestCases-1))
{    
   log.info(testSuite.getTestCaseAt(n).name)
   testSuite.getTestCaseAt(n).setDisabled(true)
   
}

The above lines of groovy script will first get access to the soapUI testSuite object and from there get the number of testCases in that testSuite. Next is a for loop traversing through the number of test cases and it prints the name of the test cases to the log. "testSuite.getTestCaseAt(n).setDisabled(true)" statement will disable the testCase. After execute this step all the test cases in that testSuite will be disabled. To enable the test cases, use "testSuite.getTestCaseAt(n).setDisabled(false)". To disable/ enable a particular test case which has a name say "testCase1" the below if block can be included inside the for loop.
if(testSuite.getTestCaseAt(n).name == "testCase1")
   testSuite.getTestCaseAt(n).setDisabled(true)


4 comments:
Post a Comment

This is a new website mainly for SOA Testers using soapUI. Let me know your thoughts/ suggestions.