JsonPath Match和JsonPath RegEx Match断言在SoapUI 5.7.0(和v5.6.1一起



我们的安全部门要求我们使用嵌入在SoapUI 5.7.0中的log4j 2.17。这需要我们升级当前版本的SoapUI v5.2.1。

我用SoapUI 5.7.0测试了几个用户脚本,它们都运行得很顺利,但有几个集成测试失败了。我找了好几天也没找到这个问题的解决办法。这个问题与我们的代码无关,因为命令testrrun .sh在使用完全相同的参数时失败了(见下文)。

我首先运行mockservicerunner:

ubuntu@tab-sabrina-dev:~/MyRepo/git/TSM/hestia-software-scripts$ mockservicerunner.sh -m"REST MockService" -p 58475 test/integration/monitoring/soapui/soapui-project.xml
================================
=
= SOAPUI_HOME = /home/ubuntu/SmartBear/SoapUI-5.7.0
=
================================
OpenJDK 64-Bit Server VM warning: Option --illegal-access is deprecated and will be removed in a future release.
SoapUI 5.7.0 MockService Runner
17:40:40,385 INFO  [DefaultSoapUICore] Creating new settings at [/home/ubuntu/soapui-settings.xml]
17:40:45,326 INFO  [PluginManager] Adding plugin from [/home/ubuntu/.soapuios/plugins/ready-mqtt-plugin-dist.jar]
17:40:45,334 INFO  [PluginManager] Adding plugin from [/home/ubuntu/.soapuios/plugins/readyapi-postman-1.0.1.jar]
17:40:46,571 INFO  [PluginManager] Adding plugin from [/home/ubuntu/.soapuios/plugins/ready-uxm-plugin-os-1.0.3.jar]
17:40:46,991 INFO  [PluginManager] 3 plugins loaded in 1661 ms
17:40:46,992 INFO  [DefaultSoapUICore] All plugins loaded
17:40:50,191 INFO  [WsdlProject] Loaded project from [file:/home/ubuntu/MyRepo/git/TSM/hestia-software-scripts/test/integration/monitoring/soapui/soapui-project.xml]
17:40:50,201 INFO  [SoapUIMockServiceRunner] Running MockService [REST MockService] in project [Hestia Integration]
17:40:50,201 INFO  [SoapUIMockServiceRunner] Press any key to terminate
17:40:50,797 INFO  [JettyMockEngine] Started mockService [REST MockService] on port [58475] at path [/]
17:40:50,803 INFO  [SoapUIMockServiceRunner] MockService started on port 58475 at path [/]
17:40:50,803 INFO  [SoapUIMockServiceRunner] Started 1 runner
Press any key to terminate...
17:43:09,496 INFO  [log] Path: /pet/findByStatus
17:43:09,623 INFO  [log] QueryString: status=available
17:43:09,707 INFO  [SoapUIMockServiceRunner] Handled request 1; [/pet/findByStatus] with [Available] in [0ms] at [2022-06-28 17:43:09.523]
17:43:10,732 INFO  [log] Path: /pet/findByStatus
17:43:10,733 INFO  [log] QueryString: status=available
17:43:10,749 INFO  [SoapUIMockServiceRunner] Handled request 2; [/pet/findByStatus] with [Available] in [0ms] at [2022-06-28 17:43:10.733]
17:43:10,770 INFO  [log] Path: /pet/findByStatus
17:43:10,771 INFO  [log] QueryString: status=available
17:43:10,790 INFO  [SoapUIMockServiceRunner] Handled request 3; [/pet/findByStatus] with [Available] in [0ms] at [2022-06-28 17:43:10.770]
17:43:10,914 INFO  [log] Path: /pet/findByStatus
17:43:10,917 INFO  [log] QueryString: status=available
17:43:10,931 INFO  [SoapUIMockServiceRunner] Handled request 4; [/pet/findByStatus] with [Available] in [0ms] at [2022-06-28 17:43:10.915]
17:43:10,950 INFO  [log] Path: /pet/findByStatus
17:43:10,951 INFO  [log] QueryString: status=available
17:43:10,963 INFO  [SoapUIMockServiceRunner] Handled request 5; [/pet/findByStatus] with [Available] in [0ms] at [2022-06-28 17:43:10.951]

然后我用testrunner运行测试:

$ testrunner.sh -rAI -Duser.timezone=UTC -Dlogfilename=TestREST_-_test_simple_success_latest.log -Derrfilename=TestREST_-_test_simple_success_errors.log -Dsoapui.log.dir=test/integration/monitoring/soapui/rest/simple/success/logs -s 'Simple - REST Only - success' -h localhost:58475 -e http://localhost:58475 test/integration/monitoring/soapui/rest/simple/success/project.xml
================================
=
= SOAPUI_HOME = /home/ubuntu/SmartBear/SoapUI-5.7.0
=
================================
<snip>
17:59:41,810 INFO  [DefaultSoapUICore] All plugins loaded
17:59:43,215 INFO  [WsdlProject] Loaded project from [file:/home/ubuntu/MyRepo/git/TSM/hestia-software-scripts/test/integration/monitoring/soapui/rest/simple/success/project.xml]
17:59:43,219 INFO  [SoapUITestCaseRunner] Running SoapUI tests in project [Hestia Integration]
17:59:43,220 INFO  [SoapUITestCaseRunner] Running TestSuite [Simple - REST Only - success], runType = SEQUENTIAL
17:59:43,226 INFO  [SoapUITestCaseRunner] Running SoapUI testcase [No assertions]
17:59:43,230 INFO  [SoapUITestCaseRunner] running step [Get available pets]
17:59:44,245 INFO  [SoapUITestCaseRunner] Finished running SoapUI testcase [No assertions], time taken: 731ms, status: FINISHED
17:59:44,254 INFO  [SoapUITestCaseRunner] Running SoapUI testcase [Status code assertion]
17:59:44,254 INFO  [SoapUITestCaseRunner] running step [Get available pets]
17:59:44,285 INFO  [SoapUITestCaseRunner] Assertion [Valid HTTP Status Codes] has status VALID
17:59:44,290 INFO  [SoapUITestCaseRunner] Finished running SoapUI testcase [Status code assertion], time taken: 12ms, status: FINISHED
17:59:44,290 INFO  [SoapUITestCaseRunner] Running SoapUI testcase [JSON path existence assertion]
17:59:44,291 INFO  [SoapUITestCaseRunner] running step [Get available pets]
17:59:44,346 INFO  [SoapUITestCaseRunner] Assertion [JsonPath Existence Match - Id is returned] has status VALID
17:59:44,347 INFO  [SoapUITestCaseRunner] Finished running SoapUI testcase [JSON path existence assertion], time taken: 2ms, status: FINISHED
17:59:44,350 INFO  [SoapUITestCaseRunner] Running SoapUI testcase [JSON path match assertion]
17:59:44,350 INFO  [SoapUITestCaseRunner] running step [Get available pets]
17:59:44,372 INFO  [SoapUITestCaseRunner] Assertion [JsonPath Match - First status is available] has status FAILED
17:59:44,372 ERROR [SoapUITestCaseRunner] ASSERTION FAILED -> Comparison failed for path [$..status[0]], expecting [available], actual was [[]]
17:59:44,372 ERROR [SoapUITestCaseRunner] ASSERTION FAILED -> Comparison failed for path [$..status[0]], expecting [available], actual was [[]]
17:59:44,373 ERROR [SoapUITestCaseRunner] Get available pets failed, exporting to [/home/ubuntu/MyRepo/git/TSM/hestia-software-scripts/Simple__REST_Only__success/JSON_path_match_assertion/Get_available_pets-0-FAILED.txt]
17:59:44,373 ERROR [SoapUITestCaseRunner] Get available pets failed, exporting to [/home/ubuntu/MyRepo/git/TSM/hestia-software-scripts/Simple__REST_Only__success/JSON_path_match_assertion/Get_available_pets-0-FAILED.txt]
17:59:44,373 INFO  [SoapUITestCaseRunner] Finished running SoapUI testcase [JSON path match assertion], time taken: 3ms, status: FAILED
17:59:44,374 INFO  [SoapUITestCaseRunner] Running SoapUI testcase [JSON path regex match assertion]
17:59:44,374 INFO  [SoapUITestCaseRunner] running step [Get available pets]
17:59:44,399 INFO  [SoapUITestCaseRunner] Assertion [JsonPath RegEx Match - Pet name is valid] has status FAILED
17:59:44,400 ERROR [SoapUITestCaseRunner] ASSERTION FAILED -> Comparison failed for path [$..name[0]], expecting [true], actual was [false]
17:59:44,400 ERROR [SoapUITestCaseRunner] ASSERTION FAILED -> Comparison failed for path [$..name[0]], expecting [true], actual was [false]
17:59:44,400 ERROR [SoapUITestCaseRunner] Get available pets failed, exporting to [/home/ubuntu/MyRepo/git/TSM/hestia-software-scripts/Simple__REST_Only__success/JSON_path_regex_match_assertion/Get_available_pets-0-FAILED.txt]
17:59:44,400 ERROR [SoapUITestCaseRunner] Get available pets failed, exporting to [/home/ubuntu/MyRepo/git/TSM/hestia-software-scripts/Simple__REST_Only__success/JSON_path_regex_match_assertion/Get_available_pets-0-FAILED.txt]
17:59:44,402 INFO  [SoapUITestCaseRunner] Finished running SoapUI testcase [JSON path regex match assertion], time taken: 2ms, status: FAILED
17:59:44,405 INFO  [SoapUITestCaseRunner] TestSuite [Simple - REST Only - success] finished with status [FAILED] in 1179ms
SoapUI 5.7.0 TestCaseRunner Summary
-----------------------------
Time Taken: 1185ms
Total TestSuites: 1
Total TestCases: 5 (2 failed)
Total TestSteps: 5
Total Request Assertions: 4
Total Failed Assertions: 2
Total Exported Results: 5

我知道在SoapUI 6.7.0中有一个JsonPath Match断言的错误(见问题#53054188),并将它们替换为XPath Match,但它仍然不起作用,出现相同的错误信息。如有任何帮助,我将不胜感激。

最诚挚的问候,塞布丽娜

我终于弄清楚了pb是什么:这很可能与Jayway jsonpath库从0.9.1 (SOAPUI 5.6)升级到2.4.0 (SOAPUI 5.7)有关。参见SOAPUI发布说明:

我们已经更新了一些第三方库,包括后:—Apache Log4j库升级到2.17.1。- Jayway jsonpath到2.4.0.

在项目文件中,替换"$..status[0]";美元[0].status"已解决

我用这个网站进行JSONPath实现的差异和验证:https://jsonpath.herokuapp.com/.

SoapUI 5.7.0升级了JSONPath库(Jayway)。

在以前的版本中,Jayway JSONPath允许在任何JSON节点上使用括号[]操作符。在最近的版本中,这种行为已经被"修复"了。所以括号操作符[]只能用于JSON数组.

这里有更多关于JSONPath选择问题的信息。

最新更新