Groovy 6 – clone test step assertion using Groovy script in soapUI

Posted: June 3, 2011 in Assertion in soapUI, context, groovy, Properties in soapUI, soapUI
Tags: , , , , , , , ,

Yesterday, I found one interesting question in eviware forum [thread] : seeking the information about replicating the “Clone Assertion” feature from soapUI Pro into the soapUI open source using the groovy. So i thought of trying my hand on the same and shared below is the working piece of code to achieve the same.

P.S. : I have also updated the eviware forum thread and people who ‘hates’ blog can read the solution in the thread. And thanks to the user for raising this question in forum 🙂

Initialize:
# Create 2 property at testcase level named “sourceTestStep” & “targetTestStep” respectively.
# Always copy and paste the name of teststep when update the value of newly defined property, so as to reduce the possibility of TYPO error.
# Create a groovy test step then paste the below code and run the test step. Done!

/*  
@Title : Gr-oooooo-vy 6
@Author : Pradeep Bishnoi
@Description : Clone all the assertion from TestStep [SourceTestStep proptery] into the target TestSTep [TargetTestStep property] by executing a groovy test step.
*/

import com.eviware.soapui.model.testsuite.Assertable
def project = context.testCase.testSuite.project
def testSuite = project.getTestSuiteAt(1)
def testCase = testSuite.getTestCaseAt(0)
def sourceTestStep = context.expand( ‘${#TestCase#SourceTestStep}’ )
def targetTestStep = context.expand( ‘${#TestCase#TargetTestStep}’ )

def testStepSrc = testCase.getTestStepByName(sourceTestStep)
def testStepTrgt = testCase.getTestStepByName(targetTestStep)
def counter = testStepSrc.getAssertionList().size()
for (count in 0..<counter)
{
    testStepTrgt.cloneAssertion(testStepSrc.getAssertionAt(count), testStepSrc.getAssertionAt(count).getName())
}

Advertisements
Comments
  1. kranti says:

    Hi I am new to this groovy script. what i am tryiing is cloning the assertions of one request to nother in a test suite.

    1)def testSuite = project.getTestSuiteAt(1) throwing out of bond exception.
    2)can’t access getAssertionListe on null

    test suite has 2 test cases . in a testcase – 9 teststeps are there

    any suggestion very helpful

  2. kranti says:

    Hi pradeep thanks for the immediate response.

    Groovy 5 article works fine for me. (this copies the assertion from one request to another).
    Groovy6 a bit confused to me.

    import com.eviware.soapui.model.testsuite.Assertable
    def project = context.testCase.testSuite.project
    def testSuite = project.getTestSuiteByName(‘MAN51’)
    def testCase = testSuite.getTestCaseByName(‘T1-MAN5100’) // has a step of 9 requests.

    def sourceTestStep = context.expand(‘${#TestCase#UCMAN50(IEA57)}’ ) // 3 rd request
    def targetTestStep = context.expand( ‘${#TestCase#UCMAN51(IEA65))}’ ) // 5th request

    def testStepSrc = testCase.getTestStepByName(sourceTestStep)
    def testStepTrgt = testCase.getTestStepByName(targetTestStep)
    def counter = testStepSrc.getAssertionList().size()
    for (int i=0;i< counter; i++) {
    testStepTrgt.cloneAssertion(testStepSrc.getAssertionAt(count), testStepSrc.getAssertionAt(count).getName())

    }
    i am new learner. so may be my questions bit foolish -:) but i want to put it.
    1) How this different from groovy5 article?
    2) i am still getting the Null pointer exception for getting assertion liste ?
    3) what is the role of creating the testcase level properties(sourceTestStep)?

  3. Rajasekar M says:

    Can this be used as a utility scripts, so this method can be invoked by any test suite/test step?

  4. cwlovell says:

    I am getting an unexpected char error on the first # on this line (def sourceTestStep = context.expand( ‘${#TestCase#SourceTestStep}’ ) ), any ideas?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s