Showing posts with label SOAP UI – Automation using Groovy Scripting. Show all posts
Showing posts with label SOAP UI – Automation using Groovy Scripting. Show all posts

Friday 22 September 2017

SOAP UI – Automation using Groovy Scripting



SOAP UI – Automation using Groovy Scripting

 

groovy script in soapui examples, soapui global properties, script assertion in soapui examples, messageexchange groovy example soapui validate json response, contains assertion in groovy script, soapui groovy set property, property transfer in soapui using groovy, soapui properties

 


·        SaopUI is open source tool and there is also advanced version available i.e ReadyAPI which is licensed version.

·        Groovy scripting will be necessary if you are working with open version and little pinch is need in the ReadyAPI.

·        Here we will explore the Groovy Scripting which are necessary for SoapUI Automation.

·        In Groovy scripting most of the java libraries are included, henceforth all the functions and keywords can also be used in the Groovy scripting.

·        Groovy Scripting is dynamic language for the Java virtual machine, it is not a separate language. It is similar to java. There are no specific standards.     

·        It is loosely coupled language such as no need to mention the datatype, using “def” any variable can be defined

Comments in Groovy:


Single Line comment:

“// Sample Script”

Multiple Line Comment:

/*
Here we will see examples of Groovy
*/

Debugging:


log.info “debug”: This will print the string

Variable Declaration


def Auto = "Groovy Automation"
def day= 7
log.info Auto
log.info day
log.info "Number of days required to learn " + Auto + " is : " + day
log.info "Number of days required to learn  $Auto   is : $day"
Output:
INFO: Groovy Automation
 INFO: 7
INFO:Number of days required to learn Groovy Automation is : 7
INFO:Number of days required to learn  Groovy Automation   is : 7

Conditional Statements
IF Else:
if(day<=7)
{
               log.info "Completed"
}else
{
               log.info "Not Completed"
}

Output:
INFO:Completed

Assertion
Without the conditional statement too, the condition can be verified such as using the Assertion
assert day == 8 (Here the assertion will fail)

groovy script in soapui examples, soapui global properties, script assertion in soapui examples, messageexchange groovy example soapui validate json response, contains assertion in groovy script, soapui groovy set property, property transfer in soapui using groovy, soapui properties


assert day == 7 (Here the assertion will pass)


groovy script in soapui examples, soapui global properties, script assertion in soapui examples, messageexchange groovy example soapui validate json response, contains assertion in groovy script, soapui groovy set property, property transfer in soapui using groovy, soapui properties


For Loop
for(int K=0;K<=10;K++){
               log.info K
}

Note: without declaration, also this will work and with def also it will work

for(def K=0;K<=10;K++){
               log.info K
}

for(K=0;K<=10;K++){
               log.info K
}
Output:
INFO:0
INFO:1
INFO:2
INFO:3
INFO:4
INFO:5
INFO:6
INFO:7
INFO:8
INFO:9
INFO:10

While Loop
def K=0

while(K<=10){
               log.info K
               K++;
}
Output:
INFO:0
INFO:1
INFO:2
INFO:3
INFO:4
INFO:5
INFO:6
INFO:7
INFO:8
INFO:9
INFO:10

TestRunner Variables
We can create testrunner variables for the Test case, Test suite and project level and these can be obtained using the below methods.
Note: These methods will work only in groovy script
// Create a variable in TestCase-TestRunner variable and set and a value to it and get it
testRunner.testCase.setPropertyValue( "UID", "Sekar.Vadivel" )


groovy script in soapui examples, soapui global properties, script assertion in soapui examples, messageexchange groovy example soapui validate json response, contains assertion in groovy script, soapui groovy set property, property transfer in soapui using groovy, soapui properties


//Get the TestCase-Custom variable
def UID = testRunner.testCase.getPropertyValue( "UID" )
log.info UID
Output:
INFO:Sekar.Vadivel

// Create a variable in TestSuite-TestRunner Variable and set and a value to it and get it
testRunner.testCase.testSuite.setPropertyValue( "UID-TS", "Sekar.Vadivel_TS" )


groovy script in soapui examples, soapui global properties, script assertion in soapui examples, messageexchange groovy example soapui validate json response, contains assertion in groovy script, soapui groovy set property, property transfer in soapui using groovy, soapui properties


//Get the TestSuite-TestRunner variable
def TS = testRunner.testCase.testSuite.getPropertyValue( "UID-TS" )
log.info TS
Output:
INFO: Sekar.Vadivel_TS

// Create a variable in Project Variable and set and a value to it and get it
testRunner.testCase.testSuite.project.setPropertyValue( "UID-PJ", "Sekar.Vadivel_PJ" )


groovy script in soapui examples, soapui global properties, script assertion in soapui examples, messageexchange groovy example soapui validate json response, contains assertion in groovy script, soapui groovy set property, property transfer in soapui using groovy, soapui properties


//Get the Project-TestRunner variable
def PJ = testRunner.testCase.testSuite.project.getPropertyValue( "UID-PJ" )
log.info PJ
Output:
INFO: Sekar.Vadivel_PJ

//Global Properties
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( "UIDG", "Global" )
def globalProperty = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "UIDG" )
log.info globalProperty
Output:
INFO: Global
Note: This will work both in Groovy script as well as in Script assertion

MessageExchange variable
Note: This will work only in Script Assertion

//TestSuite Message exchange variable
messageExchange.modelItem.testStep.testCase.testSuite.setPropertyValue( "UID-TS-SA", "Script Assertion" )
 def UID = messageExchange.modelItem.testStep.testCase.testSuite.getPropertyValue( "UID-TS-SA" )
log.info UID

Output:
INFO: Script Assertion
Similarly these can be used for test case and project