Tuesday, September 27, 2011

Now we have new address

Going forward all the new blog post will be only available on/at http://learnsoapui.wordpress.com/
This will be no longer active & i will not be able to reply to questions asked here.

So requesting all the blog followers & readers to subscribe the learnsoapui.wordpress blog feed.

Regards,
Pradeep Bishnoi

Friday, July 15, 2011

10 Groovy scripts on your finger tips - soapUI

In this series of Groovy blogs [numbered 10], i will be sharing very frequently  used "10 groovy scripts" which should be on your finger tips. These would come handy in order to perform any Automation using the Groovy in soapUI.

/* 
@Author : Pradeep Bishnoi
@Description : Collection of groovy script snippets required to achieve automation in soapUI
*/

1. Using Log variable
    log.info("Any Text message " + anyVariable)

2. Using Context variable
    def myVar = context.expand( '${#TestCase#SourceTestStep}') //will expand TestCase property value into the new variable
    context.testCase  // returns the current testCase handle

3. Using TestRunner variable
    testRunner.testCase.getTestStepByName("TestStepName")
    testRunner.testCase // return the handle to current testCase
    testRunner.testCase.testSuite.project.testSuites["My_TestSuite"]

4. Using MessageExchange variable
    messageExchange.getEndpoint() //endpoint to the selected teststep
    messageExchange.getTimestamp()    //timestamp
    messageExchange.getTimeTaken()    //time taken to process the request/response

5. Using Project, TestSuite, TestCase, TestStep methods
    def project = testRunner.testCase.testSuite.project
    def project = context.testCase.testSuite.project

    def myTestSuite = project.getTestSuiteAt(IndexNumber)
    def myTestSuite = project.getTestSuiteByName("Name of the TestSuite")

    def myTestCase = myTestSuite.getTestCaseAt(IndexNumber)
    def myTestCase = myTestSuite.getTestCaseByName("Name of the TestCase")

    def myTestStep = myTestCase.getTestStepAt(IndexNumber)
    def myTestStep = myTestCase.getTestStepByName("Name of the TestStep")

6. RawRequest & RawResponse
    messageExchange.getRequestContentAsXml.toString()
    messageExchange.getResponseContentAsXml.toString()

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 into String using groovy
    anyStringVar = anyIntegerVar.toString()
    anyIntegerVar = anyStringVar.toInteger()

9. Reading & Writing user-defined property with Groovy
    def userIdInStep = testRunner.testCase.getTestStepByName( "UserDefinedProperty" )
    def userIdStr = userIdInStep.getPropertyValue( "myPropertyName" );
    userIdInStep.setPropertyValue("myPropertyName", "StringValueAsInput")

10. Refer soapUI API docs & go soapUI Pro inorder to get Advanced functionality without writing code ;-)

Happy Scripting!! Do share this blog post with others and also share any useful scripts/ideas if you have.