SlideShare a Scribd company logo
1. Using Log variable
log.info(“Any Text message ”+anyVariable)
2. Using Context variable
defmyVar =context.expand( ‘${#TestCase#SourceTestStep}’) //will
expand TestCaseproperty valueinto the newvariable
context.testCase // returns thecurrent testCasehandle
3. Using TestRunner variable
testRunner.testCase.getTestStepByName(“TestStepName”)
testRunner.testCase // returnthehandleto currenttestCase
testRunner.testCase.testSuite.project.testSuites[“My_TestSuite”]
4. Using MessageExchange variable
messageExchange.getEndpoint() //endpointto theselected
teststep
messageExchange.getTimestamp() //timestamp
messageExchange.getTimeTaken() //time taken toprocess the
request/response
5. Using Project, TestSuite, TestCase, TestStepmethods
def project=testRunner.testCase.testSuite.project
def project=context.testCase.testSuite.project
def myTestSuite=project.getTestSuiteAt(IndexNumber)
def myTestSuite =project.getTestSuiteByName(“Nameof the
TestSuite”)
def myTestCase=myTestSuite.getTestCaseAt(IndexNumber)
def myTestCase=myTestSuite.getTestCaseByName(“Nameofthe
TestCase”)
def myTestStep=myTestCase.getTestStepAt(IndexNumber)
def myTestStep=myTestCase.getTestStepByName(“Name ofthe
TestStep”)
9. Reading & Writing user-defined property withGroovy
defuserIdInStep =testRunner.testCase.getTestStepByName(
“UserDefinedProperty”)
defuserIdStr =userIdInStep.getPropertyValue(
“myPropertyName”);
userIdInStep.setPropertyValue(“myPropertyName”,
“StringValueAsInput”)
7. groovyUtils& XmlHolder
def groovyUtils =new com.eviware.soapui.support.GroovyUtils(
context )
def holder =groovyUtils.getXmlHolder
(“Assert_Script#Response”)
8. Converting String into Integer & Integer intoString using groovy
anyStringVar =anyIntegerVar.toString()
anyIntegerVar=anyStringVar.toInteger()
6. RawRequest & RawResponse
messageExchange.getRequestContentAsXml.toString()
messageExchange.getResponseContentAsXml.toString()
Go Groovy with soapUI – nifty tool for Webservice testing!
Posted: May 19, 2011 in context, groovy, soapUI, testrunner
Tags: context, groovy,testcase,testrunner,teststep
2
Here i go with first groovy post about using Groovy script in soapUI. groovy comes very handy
when you want to put some script assertion or performing certain task before/after each teststep
execution etc.
First couple of things to remember before we proceed with actual code lines.
# Groovy script can be written in Assertion, Test Step, TestCase/TestSuite level as
TearDown/Setup script.
# To invoke the groovy script at each different level, script editor provides us with the list of
variables on top right corner of script editor. So it is possible that the code you have written in
groovy test step or as teardown script would not work properly for teststep script assertion.
In most of the cases we use either “context” or “testrunner” variable to invoke or create a new
object of any class or to call required method.
I frequently use these 2 standard lines of groovy code, to acheive the required script objective,
are :
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder (java.lang.String xmlPropertyOrString) // where this
xmlProperty can have either ‘teststepname#response’ ‘teststepname#request’ or any string value.
After having the object created refer the groovyUtils APIDocs
(http://www.soapui.org/apidocs/com/eviware/soapui/support/GroovyUtils.html) to find out all
the relevant methods which can be called with particular input parameter.
Now below are few code lines for quickly performing certain task :
/*
@Author : Pradeep Bishnoi
@Description : To count the number of nodes under any node in response using xPath & groovy
script.
*/
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder (“myTestStepName#Response”)
holder.namespaces[“namespacename1″] = “http://mywebservice.com/soapui/testing”
log.info(“Number of nodes :” +
holder.getNodeValue(“count(//namespacename1:GetSampleMethodResponse/namespacename1:
StudentDetails/namespacename1:Address)”))
// Address is comprised of house number, street name, city, country – so result = 4
/*
@Description : To store the response into a simple text file, append this code to the above.
*/
new File(‘D:/response_myTestStepName.txt’).write(holder.prettyXml)
Do provide your inputs/comments/question on the same blog and share if you have something
interesting. Thanks!

More Related Content

PDF
Testing in android
PPTX
Unit/Integration Testing using Spock
PDF
Servletand sessiontracking
PPTX
Mutation Testing: Testing your tests
PPTX
Smarter Testing With Spock
PPTX
Unit testing patterns for concurrent code
PDF
Bot builder v4 HOL
PDF
[xp2013] Narrow Down What to Test
Testing in android
Unit/Integration Testing using Spock
Servletand sessiontracking
Mutation Testing: Testing your tests
Smarter Testing With Spock
Unit testing patterns for concurrent code
Bot builder v4 HOL
[xp2013] Narrow Down What to Test

What's hot (20)

PPTX
Building unit tests correctly
PPTX
Qunit Java script Un
PPT
jUnit
PDF
Tutorial - 16 : How to pass parameters from one script to another by CallScri...
PPTX
Mockito intro
PPTX
Unit testing
PDF
Spock: Test Well and Prosper
PPTX
Writing and using Hamcrest Matchers
PDF
Stop Making Excuses and Start Testing Your JavaScript
PDF
Spock Framework
PDF
JUnit Kung Fu: Getting More Out of Your Unit Tests
PDF
Code Kata: String Calculator in Flex
PPTX
Testing And Mxunit In ColdFusion
PPTX
J unit스터디슬라이드
PDF
JUnit & Mockito, first steps
PDF
All about unit testing using (power) mock
PDF
Date Processing Attracts Bugs or 77 Defects in Qt 6
PDF
Servlet Filter
PDF
Be smart when testing your Akka code
PPT
JavaScript Control Statements I
Building unit tests correctly
Qunit Java script Un
jUnit
Tutorial - 16 : How to pass parameters from one script to another by CallScri...
Mockito intro
Unit testing
Spock: Test Well and Prosper
Writing and using Hamcrest Matchers
Stop Making Excuses and Start Testing Your JavaScript
Spock Framework
JUnit Kung Fu: Getting More Out of Your Unit Tests
Code Kata: String Calculator in Flex
Testing And Mxunit In ColdFusion
J unit스터디슬라이드
JUnit & Mockito, first steps
All about unit testing using (power) mock
Date Processing Attracts Bugs or 77 Defects in Qt 6
Servlet Filter
Be smart when testing your Akka code
JavaScript Control Statements I
Ad

Similar to Soaoui (20)

PPTX
Soap UI - Lesson45
PPTX
Introduction to SoapUI day 4-5
PDF
Deep dive into SoapUI
PPTX
Testwarez 2013 - Warsztat SoapUI
PDF
Oscon Java Testing on the Fast Lane
PDF
Groovy On Trading Desk (2010)
PDF
API Testing. Streamline your testing process.
PDF
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
PPTX
Roman iovlev. Test UI with JDI - Selenium camp
PDF
Web Services Automated Testing via SoapUI Tool
PPTX
Groovy features
PPTX
Dynamic Groovy Edges
PPT
Svcc Groovy Testing
PDF
Cool JVM Tools to Help You Test
PPTX
Introduction to SoapUI day 3
PPTX
Testing soapui
PPTX
WebServices using Soap
PPTX
SoapUi using WebServices
PPTX
WebServices using Soapui
PPTX
Testing soapui
 
Soap UI - Lesson45
Introduction to SoapUI day 4-5
Deep dive into SoapUI
Testwarez 2013 - Warsztat SoapUI
Oscon Java Testing on the Fast Lane
Groovy On Trading Desk (2010)
API Testing. Streamline your testing process.
Cool Jvm Tools to Help you Test - Aylesbury Testers Version
Roman iovlev. Test UI with JDI - Selenium camp
Web Services Automated Testing via SoapUI Tool
Groovy features
Dynamic Groovy Edges
Svcc Groovy Testing
Cool JVM Tools to Help You Test
Introduction to SoapUI day 3
Testing soapui
WebServices using Soap
SoapUi using WebServices
WebServices using Soapui
Testing soapui
 
Ad

Recently uploaded (20)

PPTX
artificial intelligence overview of it and more
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
Paper PDF World Game (s) Great Redesign.pdf
PPTX
Introduction to Information and Communication Technology
PPTX
Digital Literacy And Online Safety on internet
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
artificial intelligence overview of it and more
SAP Ariba Sourcing PPT for learning material
Decoding a Decade: 10 Years of Applied CTI Discipline
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
522797556-Unit-2-Temperature-measurement-1-1.pptx
Module 1 - Cyber Law and Ethics 101.pptx
Paper PDF World Game (s) Great Redesign.pdf
Introduction to Information and Communication Technology
Digital Literacy And Online Safety on internet
An introduction to the IFRS (ISSB) Stndards.pdf
presentation_pfe-universite-molay-seltan.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Tenda Login Guide: Access Your Router in 5 Easy Steps
Job_Card_System_Styled_lorem_ipsum_.pptx
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
SASE Traffic Flow - ZTNA Connector-1.pdf
WebRTC in SignalWire - troubleshooting media negotiation
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
Introuction about ICD -10 and ICD-11 PPT.pptx
Cloud-Scale Log Monitoring _ Datadog.pdf

Soaoui

  • 1. 1. Using Log variable log.info(“Any Text message ”+anyVariable) 2. Using Context variable defmyVar =context.expand( ‘${#TestCase#SourceTestStep}’) //will expand TestCaseproperty valueinto the newvariable context.testCase // returns thecurrent testCasehandle 3. Using TestRunner variable testRunner.testCase.getTestStepByName(“TestStepName”) testRunner.testCase // returnthehandleto currenttestCase testRunner.testCase.testSuite.project.testSuites[“My_TestSuite”] 4. Using MessageExchange variable messageExchange.getEndpoint() //endpointto theselected teststep messageExchange.getTimestamp() //timestamp messageExchange.getTimeTaken() //time taken toprocess the request/response 5. Using Project, TestSuite, TestCase, TestStepmethods def project=testRunner.testCase.testSuite.project def project=context.testCase.testSuite.project def myTestSuite=project.getTestSuiteAt(IndexNumber) def myTestSuite =project.getTestSuiteByName(“Nameof the TestSuite”) def myTestCase=myTestSuite.getTestCaseAt(IndexNumber) def myTestCase=myTestSuite.getTestCaseByName(“Nameofthe TestCase”) def myTestStep=myTestCase.getTestStepAt(IndexNumber) def myTestStep=myTestCase.getTestStepByName(“Name ofthe TestStep”) 9. Reading & Writing user-defined property withGroovy defuserIdInStep =testRunner.testCase.getTestStepByName( “UserDefinedProperty”) defuserIdStr =userIdInStep.getPropertyValue( “myPropertyName”); userIdInStep.setPropertyValue(“myPropertyName”, “StringValueAsInput”) 7. groovyUtils& XmlHolder def groovyUtils =new com.eviware.soapui.support.GroovyUtils( context ) def holder =groovyUtils.getXmlHolder (“Assert_Script#Response”) 8. Converting String into Integer & Integer intoString using groovy anyStringVar =anyIntegerVar.toString() anyIntegerVar=anyStringVar.toInteger() 6. RawRequest & RawResponse messageExchange.getRequestContentAsXml.toString() messageExchange.getResponseContentAsXml.toString() Go Groovy with soapUI – nifty tool for Webservice testing! Posted: May 19, 2011 in context, groovy, soapUI, testrunner Tags: context, groovy,testcase,testrunner,teststep 2 Here i go with first groovy post about using Groovy script in soapUI. groovy comes very handy when you want to put some script assertion or performing certain task before/after each teststep execution etc. First couple of things to remember before we proceed with actual code lines. # Groovy script can be written in Assertion, Test Step, TestCase/TestSuite level as TearDown/Setup script. # To invoke the groovy script at each different level, script editor provides us with the list of
  • 2. variables on top right corner of script editor. So it is possible that the code you have written in groovy test step or as teardown script would not work properly for teststep script assertion. In most of the cases we use either “context” or “testrunner” variable to invoke or create a new object of any class or to call required method. I frequently use these 2 standard lines of groovy code, to acheive the required script objective, are : def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder (java.lang.String xmlPropertyOrString) // where this xmlProperty can have either ‘teststepname#response’ ‘teststepname#request’ or any string value. After having the object created refer the groovyUtils APIDocs (http://www.soapui.org/apidocs/com/eviware/soapui/support/GroovyUtils.html) to find out all the relevant methods which can be called with particular input parameter. Now below are few code lines for quickly performing certain task : /* @Author : Pradeep Bishnoi @Description : To count the number of nodes under any node in response using xPath & groovy script. */ def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def holder = groovyUtils.getXmlHolder (“myTestStepName#Response”) holder.namespaces[“namespacename1″] = “http://mywebservice.com/soapui/testing” log.info(“Number of nodes :” + holder.getNodeValue(“count(//namespacename1:GetSampleMethodResponse/namespacename1: StudentDetails/namespacename1:Address)”)) // Address is comprised of house number, street name, city, country – so result = 4 /* @Description : To store the response into a simple text file, append this code to the above. */ new File(‘D:/response_myTestStepName.txt’).write(holder.prettyXml) Do provide your inputs/comments/question on the same blog and share if you have something interesting. Thanks!