簡體   English   中英

空手道:將數據驅動與外部文件中的請求結合起來?

[英]Karate: combine data driven with request in external file?

我正在尋找一種將數據驅動與外部請求文件結合使用的方法。

所以我的功能文件如下所示:

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>

請注意,我已將 product-id 和 user-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')
<<<<

我已經嘗試了功能文件中的請求,並且效果很好。 但是外部文件中的請求失敗。

該錯誤清楚地表明 XML 格式不正確。 使用一些 XML 工具並修復它,例如: https://www.freeformatter.com/xml-formatter.html

例如,這應該是:

<ser:id><product-id/></ser:id>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM