【发布时间】:2022-01-01 20:42:21
【问题描述】:
我正在寻找一种将数据驱动与外部请求文件结合使用的方法。
所以我的功能文件看起来像这样:
Feature: EPOS UNIT test - GetSpendingLimit
Background:
* url 'http://xxx-yyy-zzz'
* def GetSpendingLimit_request = read('classpath:examples/EPOS/request/GetSpendingLimit-dd-request.xml')
* def GetSpendingLimit_data = read('classpath:examples/EPOS/data/GetSpendingLimit.csv')
Scenario Outline: GetSpendingLimit External Request Datadriven
Given request GetSpendingLimit_request
When soap action 'TotalAmount'
Then status 200
# define a variable to check the response
* def total_amount = /Envelope/Body/GetSpendingLimitResponse/spendingLimit/totalAmount
# to print the result to the report
* print '\nTotal Amount is: ', total_amount
Examples:
|read('classpath:examples/EPOS/data/GetSpendingLimit.csv')|
我的请求是这样的:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://xxx-yyy-zzz/GetSpendingLimit/Request" xmlns:com="http://xxx-yyy-zzz/Common" xmlns:ser="http://xxx-yyy-zzz/Common/ServiceContext">
<soapenv:Header/>
<soapenv:Body>
<req:GetSpendingLimitRequest>
<ser:productServiceContext>
<ser:conversationId>GetSpendingLimit_1_1</ser:conversationId>
<ser:deviceTypeId>1</ser:deviceTypeId>
<ser:entityId>nl</ser:entityId>
<ser:product>
<ser:id><product-id></ser:id>
</ser:product>
<ser:user>
<ser:id><user-id></ser:id>
</ser:user>
</ser:productServiceContext>
</req:GetSpendingLimitRequest>
</soapenv:Body>
</soapenv:Envelope>
请注意,我已将产品 ID 和用户 ID 添加为变量,应将其替换为来自 csv 的数据驱动输入。但我收到以下错误:
[Fatal Error] :10:43: The element type "product-id" must be terminated by the matching end-tag "</product-id>".
11:35:18.404 [main] ERROR com.intuit.karate - src/test/java/examples/EPOS/GetSpendingLimit-external-request-datadriven.feature:5
* def GetSpendingLimit_request = read('classpath:examples/EPOS/request/GetSpendingLimit-dd-request.xml')
js failed:
>>>>
01: read('classpath:examples/EPOS/request/GetSpendingLimit-dd-request.xml')
<<<<
我已经尝试了功能文件中的请求,并且效果很好。但是外部文件中的请求失败。
【问题讨论】:
标签: request karate data-driven-tests