Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

soapUI: 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 from my assertion Groovy script?

Thank you

like image 546
parxier Avatar asked Dec 17 '22 17:12

parxier


1 Answers

The problem with my approach was that even if I do access the property, it is dynamic and my UUID is different each time I read the value of the property.

Instead I replaced my Properties test step with Setup Script of the Test Case:

uuid = context.expand('${=java.util.UUID.randomUUID()}')
testRunner.testCase.setPropertyValue("correlationID", uuid)

Each time my test case executes, a new uuid is generated. Then future test steps may access this static test case level property.

In my Test Request I use:

<CorrelationID>${#TestCase#correlationID}</CorrelationID>

In script assertion I use:

correlationID = context.expand('${#TestCase#correlationID}')

Thanks to Unhandled from SoapUI forums.

like image 111
parxier Avatar answered Mar 07 '23 01:03

parxier