【发布时间】:2022-01-09 17:14:19
【问题描述】:
我遇到了相当奇怪的行为。首先是一些背景: 我正在使用批处理文件在一组项目上运行 SoapUI testrunner,这样调用它们(参数是测试的 Web 服务的名称、测试环境的名称、soapui 运行器的类型、端点基本 url 和用于输出结果的目录):
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 脚本从我的库中调用脚本,该脚本遍历 \TestRequests\soap[WSname] 目录中的 xml 文件并将它们提供给步骤 2。此脚本还加载项目属性以了解在哪里可以找到测试请求 xmls 和在哪里输出结果。该脚本在所有soap Web 服务项目中都是通用的,并且非常相似的脚本用于我使用的一个rest 服务项目。主要区别在于其余版本显式填充了从 json 文件中读取的查询参数。这是使用外部库完成的,因此此步骤如下所示:
导入 wstests.RunTests
def RT = new RunTests(context: context, log: log)
RT.Cycle()
testRunner.gotoStep(2)
对于soap项目,对于其他项目也是这样:
import wstests.RunTests
def RT = new RunTests(context: context, log: log)
RT.CycleRest()
testRunner.gotoStep(2)
- 请求测试步骤 - 基本上是空壳,由步骤 1 中的脚本填充。
- 结束。
所以,问题是,当运行soap web 服务版本时,一切正常。但是当我运行其余的 Web 服务版本时,我遇到了异常:java.lang.NullPointerException: Cannot get property 'testCase' on null object 在下面突出显示的行:
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 相同。我一定是忽略了什么,我就是找不到什么。
提前致谢。
【问题讨论】:
-
将
call ..\..\Run\runSoapUITest.bat %%~nxa更改为call ..\..\Run\runSoapUITest.bat "%%~fa"会发生什么 -
"~fa" 会插入整个文件路径,所以它会在runSoapUITest.bat中找不到想要的项目,它会尝试打开:
p:\CAO\tests\..\resources\TestProjects-Auto\p:\CAO\tests\TestRequests\rest\NIA-jesle-soapui-project.xml并失败。 -
好吧,如果文件在那个路径中,那就应该打开它,不是吗?
-
如果您查看我发布的路径,您会发现它格式错误。 soapui runner 将失败,因为那不是正确的文件路径。 for 循环只读取以我需要测试的每个 Web 服务命名的子目录,并将它们传递给批处理文件 runSoapUITest.bat,后者又使用子目录名称来查找项目所在位置 - 查看最后一个参数
"%current_dir%\..\resources\TestProjects-Auto\%WSname%-soapui-project.xml".问题也不在于脚本没有找到正确的文件,它确实找到了。问题在于在 soapui 项目中运行 Groovy 脚本。
标签: rest batch-file groovy soapui