free seo tool
Showing posts with label soapui testcase. Show all posts
Showing posts with label soapui testcase. Show all posts

Create Retrieve testCase testSuite Properties using Groovy Script

If you are familiar with automation testing you might know the importance of dynamically storing or retrieving property values. In soapUI, we can story properties on different levels, say on project level, testSuite level and testCase level. Either we can hardcode the property even before the test run or we can create update and retrieve the property values dynamically using groovy script. Let us see how can we achieve this using groovy in soapUI.
The below sample groovy script will allow you to add, set and retrieve properties.
/*To make this for a test case level property, change the below line to
 def testSuite = context.testCase; 
*/
def testSuite = context.testCase.testSuite; 
def PropertyName = "UserName"
/*Below line checks if there is already a property named "UserName"*/
if(!testSuite.hasProperty(PropertyName)) 
testSuite.addProperty(PropertyName)
/*Below line of groovy code will set the value "user01" for the property*/
testSuite.setPropertyValue(PropertyName,'user01')
//Below line will retrieve the property value 
def propertyValue = testSuite.getPropertyValue(PropertyName)

Read more »

soap ui Groovy Script to find testCase status

While doing automation testing, there will be cases one need to know the status of a test case on the fly. In soapUI, while doing automation for web services testing, I came across to this scenario different times. soapUI provides a unique feature called TearDown Script for its testCase. A groovy script can be written here to get the status of the testCase on the fly. Further action can be done via scripting based on the status or this can even be used for custom reporting. Let us see the groovy script samples for the same.


testRunner.status.toString();


This line of code will return the status of soapUI testCase. The status will be "FINISHED" if it is successfully completed and it will be "FAILED" if the test case failed for any reason.

Read more »

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)


Read more »