Forum Discussion

parxier's avatar
parxier
Occasional Contributor
15 years ago

How to access Test Step property from assertion script?

I'm new to SoapUI and Groovy, but an experienced Java programmer.

I created a TestCase with two Test Steps:

1. Properties step called "CID" with single property "correlationID" and value "${=java.util.UUID.randomUUID()}".
2. Test Request where I put "<CorrelationID>${correlationID}</CorrelationID>" in the request.

It works perfectly and submits unique CorrelationID value every time I run my tests.

Now I want to add new Script Assertion to Test Step 2 ("Test Request") that compares computed "correlationID" property value from Test Step 1 ("CID") with some data from Test Step 2 response. The problem is that I can not seem to be able to access generated value of "correlationID" from there.

If I try this:
log.info "${correlationId}"

I get:
No such property: correlationId for class: Script19


If I try this:
log.info "${CID#correlationId}"

I get:
startup failed:
Script43.groovy: 1: unexpected char: '#' @ line 1, column 16.
log.info "${CID#correlationId}"
^
org.codehaus.groovy.syntax.SyntaxException: unexpected char: '#' @ line 1, column 16.
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:97)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:71)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:158)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:814)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:511)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:487)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:464)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:727)
at groovy.lang.GroovyShell.parse(GroovyShell.java:739)
at groovy.lang.GroovyShell.parse(GroovyShell.java:766)
at groovy.lang.GroovyShell.parse(GroovyShell.java:757)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:148)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:93)
at com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.GroovyScriptAssertion.assertScript(GroovyScriptAssertion.java:116)
at com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.GroovyScriptAssertion.internalAssertResponse(GroovyScriptAssertion.java:133)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion.assertResponse(WsdlMessageAssertion.java:156)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest.assertResponse(WsdlTestRequest.java:189)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest.setResponse(WsdlTestRequest.java:159)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.run(WsdlTestRequestStep.java:346)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runTestStep(WsdlTestCaseRunner.java:207)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.internalRun(WsdlTestCaseRunner.java:138)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.internalRun(WsdlTestCaseRunner.java:39)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:135)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: Script43.groovy:1:16: unexpected char: '#'
at org.codehaus.groovy.antlr.parser.GroovyLexer.nextToken(GroovyLexer.java:695)
at org.codehaus.groovy.antlr.parser.GroovyLexer$1.nextToken(GroovyLexer.java:248)
at groovyjarjarantlr.TokenBuffer.fill(TokenBuffer.java:69)
at groovyjarjarantlr.TokenBuffer.LA(TokenBuffer.java:80)
at groovyjarjarantlr.LLkParser.LA(LLkParser.java:52)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.nls(GroovyRecognizer.java:780)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.openOrClosableBlock(GroovyRecognizer.java:8848)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.stringConstructorValuePart(GroovyRecognizer.java:13449)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.stringConstructorExpression(GroovyRecognizer.java:11932)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.primaryExpression(GroovyRecognizer.java:11091)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.argumentLabel(GroovyRecognizer.java:10863)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.commandArgument(GroovyRecognizer.java:10756)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.commandArguments(GroovyRecognizer.java:10173)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.expressionStatement(GroovyRecognizer.java:8948)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.statement(GroovyRecognizer.java:1258)
at org.codehaus.groovy.antlr.parser.GroovyRecognizer.compilationUnit(GroovyRecognizer.java:650)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:93)
... 31 more

1 error


How can I access that "correlationId" computed value?

Thank you

2 Replies

  • The problem with your approach is that even if you do access the property, it is dynamic and your UUID will be different each time you read the value of the property.

    Here is how you can access the property in your Script Assertion:

    log.info context.expand( '${Properties#correlationID}' )


    Instead you might want to replace your Properties test step with a Groovy test step (alternatively, use the Setup Script of the Test Case). In the Groovy script, generate your UUID and then store the UUID to a TestCase scope property. Each time your test case executes, a new UUID will be generated. Then future test steps may access this static test case level property.

    Set property with Groovy Test Step/Setup Script
    myUUID = context.expand( '${=java.util.UUID.randomUUID()}' )
    testRunner.testCase.setPropertyValue("correlationID", myUUID )

    Use property in Test Request:
    <CorrelationID>${#TestCase#correlationID}</CorrelationID>

    Get property in script assertion:
    log.info context.expand( '${#TestCase#correlationID}' )
  • parxier's avatar
    parxier
    Occasional Contributor
    Unhandled wrote:
    The problem with your approach is that even if you do access the property, it is dynamic and your UUID will be different each time you read the value of the property.

    ...
    Instead you might want to replace your Properties test step with a Groovy test step (alternatively, use the Setup Script of the Test Case). In the Groovy script, generate your UUID and then store the UUID to a TestCase scope property. Each time your test case executes, a new UUID will be generated. Then future test steps may access this static test case level property.


    It was very helpful, thanks a lot!