gpt4 book ai didi

testing - soapUI:如何从断言脚本访问测试步骤属性?

转载 作者:行者123 更新时间:2023-11-28 19:50:57 26 4
gpt4 key购买 nike

我是 SoapUI 和 Groovy 的新手,但却是一名经验丰富的 Java 程序员。

我创建了一个包含两个测试步骤的测试用例:

  1. 属性步骤称为 CID单一属性(property)correlationID和值(value)${=java.util.UUID.randomUUID()} .
  2. Test Request我把 <CorrelationID>${correlationID}</CorrelationID> 放在哪里在请求中。

它完美地工作并提交独特的 CorrelationID每次运行测试时的值(value)。

现在我想在测试步骤 2 ( Test Request ) 中添加新的脚本断言来比较计算的 correlationID来自测试步骤 1 (CID) 的属性值以及来自测试步骤 2 响应的一些数据。问题是我似乎无法访问 correlationID 的生成值从那里开始。

如果我尝试这个:log.info "${correlationId}"

我得到:No such property: correlationId for class: Script19

如果我尝试这个:log.info "${CID#correlationId}"

我得到:

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

我怎样才能访问那个 correlationId从我的断言 Groovy 脚本计算值?

谢谢

最佳答案

我的方法的问题在于,即使我确实访问了该属性,它也是动态的,并且每次我读取该属性的值时我的 UUID 都是不同的。

相反,我用测试用例的设置脚本替换了我的 Properties 测试步骤:

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

每次我的测试用例执行时,都会生成一个新的 uuid。然后 future 的测试步骤可能会访问这个静态测试用例级别的属性。

在我的测试请求中,我使用:

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

在我使用的脚本断言中:

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

感谢Unhandled来自 SoapUI 论坛。

关于testing - soapUI:如何从断言脚本访问测试步骤属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5038594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com