SoapUI is used to test Web Services. For large number test cases, automation we can use Groovy script to reduce manual effort. Using Java, Groovy we can all manual task as automated in SoapUI. To create data driven framework or automating test cases we can use Groovy script.

The "How to use properties" article has how read/write/remove properties values using Groovy script. The article "" has how change/update the request XML for both RESTful as well as SOAP services.

The article "SoapUI Set/Read Request Header values using Groovy Script" has how to read/write HTTP method header values in both RESTful and SOAP Services.

This article has how to set/read the following values.
  1. Endpoint 
  2. Username 
  3. Password 
  4. Domain 
  5. Accept type [ Applicable for POST/PUT Request in RESTFul web service only ] 
  6. Media type [ Applicable for POST/PUT Request in RESTFul web service only ] 
  7. Step property 
  8. Request 
  9. Response [ We can able to read it ]
Read write property

Assign/Set values using Groovy Script.

        
     testRunner.testCase.testSteps["stepname"].httpRequest.setEndpoint("value");
     testRunner.testCase.testSteps["stepname"].httpRequest.setUsername("value");
     testRunner.testCase.testSteps["stepname"].httpRequest.setPassword("value");
     testRunner.testCase.testSteps["stepname"].httpRequest.setDomain("value");
     testRunner.testCase.testSteps["stepname"].httpRequest.setAccept("value");
     testRunner.testCase.testSteps["stepname"].httpRequest.setMediaType("value");
     testRunner.testCase.testSteps["stepname"].setPropertyValue("name","value");
     testRunner.testCase.testSteps["stepname"].setPropertyValue("Request","value");
The article "" has details about how set request data with parametrization. Read values using Groovy Script.

        
 def strVar = testRunner.testCase.testSteps["stepname"].getHttpRequest().getEndpoint();
 log.info strVar
 strVar = testRunner.testCase.testSteps["stepname"].getHttpRequest().getEndpoint();
 log.info strVar
 strVar = testRunner.testCase.testSteps["stepname"].getHttpRequest().getUsername();
 log.info strVar
 strVar = testRunner.testCase.testSteps["stepname"].getHttpRequest().getPassword();
 log.info strVar
 strVar = testRunner.testCase.testSteps["stepname"].getHttpRequest().getDomain();
 log.info strVar
 strVar = testRunner.testCase.testSteps["stepname"].getPropertyValue("Request");
 log.info strVar
 strVar = testRunner.testCase.testSteps["stepname"].getPropertyValue("Response");
 log.info strVar
 
 // Applicable for POST/PUT Request in RESTFul web service only
 strVar = testRunner.testCase.testSteps["stepname"].getHttpRequest().getAccept();
 log.info strVar
 strVar = testRunner.testCase.testSteps["stepname"].getHttpRequest().getMediaType();
 log.info strVar  
Single script to update the details of all testSteps in a test case.

  testRunner.testCase.testSteps.each
  {
   q->
   if(q.getValue().config.type.equals("restrequest") || q.getValue().config.type.equals("request"))
   {
    q.getValue().httpRequest.setEndpoint("value");
    q.getValue().httpRequest.setUsername("value");
    q.getValue().httpRequest.setPassword("value");
    q.getValue().httpRequest.setDomain("value");
   }
   if(q.getValue().config.type.equals("restrequest"))
   {
    q.getValue().httpRequest.setAccept("value");
    q.getValue().httpRequest.setMediaType("value");
   }
  }
  

Reactions:
 
Top