
[英]Null-pointer exception when invoking get in rest-assured: Cannot get property 'assertionClosure' on null object
[英]"Cannot get property 'testCase' on null object" in SoapUI REST project
我遇到了相当奇怪的行为。 首先是一些背景:我正在使用批处理文件在一组项目上运行 SoapUI testrunner,这样调用它们(参数是测试的 web 服务的名称、测试环境的名称、soapui 运行器的类型、端点基础 url 和目录为 Z78E6262811F39结果):
for /D %%a in ("\TestRequests\soap\*") do (
call ..\..\Run\runSoapUITest.bat %%~nxa environ test http://test.endpoint.com ../outputDir/
)
for /D %%a in ("\TestRequests\rest\*") do (
call ..\..\Run\runSoapUITest.bat %%~nxa environ test http://test.endpoint.com ../outputDir/
)
“\TestRequests\soap”包含子目录(每个测试的 web 服务一个),每个包含带有测试请求的 xml。 调用的 runSoapUITest.bat 如下所示:
set WSname=%1
set environementName=%2
set runner=%3
set endpoint=%4%
set output=%5%
...
"%SOAPUI_FOR_TEST_DIR%\bin\%runner%runner.bat" -sAutoTest -r -a -j -I -Pendpoint=%endpoint% -Penvironement=%environementName% -PoutputDir=%output% "%current_dir%\..\resources\TestProjects-Auto\%WSname%-soapui-project.xml"
如您所见,共有三个项目级自定义属性,称为endpoint 、 environment和outputDir 。 每个被调用的项目都包含一个名为 AutoTest 的测试套件和一个名为 Test 的测试用例,其中包含三个测试步骤:
Groovy script that calls script from my library that goes over the xml files in \TestRequests\soap[WSname] directory and feeds them to step 2. This script also loads the project properties to know where to find the test Request xmls and where to output结果。 此脚本在所有 soap web 服务项目中通用,并且非常相似的脚本用于我使用的一个 rest 服务项目。 主要区别在于 rest 版本显式填充了从 json 文件中读取的查询参数。 这是使用外部库完成的,因此此步骤如下所示:
导入 wstests.RunTests
def RT = new RunTests(上下文:上下文,日志:日志)
RT.Cycle()
testRunner.gotoStep(2)
对于 soap 项目,像这样对于 rest 项目:
import wstests.RunTests
def RT = new RunTests(context: context, log: log)
RT.CycleRest()
testRunner.gotoStep(2)
所以,问题是,当运行 soap web 服务版本时,一切正常。 But when I run the rest web service version I encounter exception: java.lang.NullPointerException: Cannot get property 'testCase' on null object at line highlighted below:
def CycleRest() {
--> def environement = testRunner.testCase.testSuite.project.getPropertyValue( "environement" )
def endP = testRunner.testCase.testSuite.project.getPropertyValue( "endpoint" )
def outRoot = testRunner.testCase.testSuite.project.getPropertyValue( "outputDir" )
def projectName= testRunner.testCase.testSuite.project.getName();
context.projectName = projectName
...
奇怪的是,脚本的这个开头部分与 soap 项目完全相同,可以正常工作:
def Cycle() {
def projectDir = context.expand('${projectDir}');
def environement = context.testCase.testSuite.project.getPropertyValue( "environement" )
def endP = context.testCase.testSuite.project.getPropertyValue( "endpoint" )
def outRoot = context.testCase.testSuite.project.getPropertyValue( "outputDir" )
def projectName= context.testCase.testSuite.project.getName();
context.projectName = projectName
...
为什么 soap 项目(基于 WSDL)的行为应该不同于 rest 项目(基于 WADL)?
一些评论:仅当我使用我的库运行脚本时才会发生这种情况。 如果我将脚本直接粘贴到 Groovy 测试步骤中,它就可以工作。 在批处理文件 runSoapUITest.bat 中设置项目参数似乎存在问题,但是 rest 的调用与 soap 的调用相同。 我一定是忽略了什么,我就是找不到什么。
提前致谢。
好的,经过仔细检查,我发现了关键区别-尽管您可以运行
def environement = testRunner.testCase.testSuite.project.getPropertyValue( "environement" )
从 SoapUI 客户端内部,当仅由 testrunner 运行时,缺少testRunner 。 您必须将其交换为上下文- 这甚至可以从我的工作代码片段中看出。
当我用“context”替换“testRunner”的所有实例时,它按预期工作。 我猜你每天都在学习。 甚至你显然已经知道但忘记的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.