【问题标题】:Karate: combine data driven with request in external file? [duplicate]空手道:将数据驱动与外部文件中的请求结合起来? [复制]
【发布时间】: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


    【解决方案1】:

    该错误清楚地表明 XML 格式不正确。使用一些 XML 工具并修复它,例如像这样:https://www.freeformatter.com/xml-formatter.html

    例如这应该是:

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

    【讨论】:

    • 是的,我明白,但这不是问题所在。我想将 csv 中的变量传递给外部请求。因此,当 xml 在功能文件中时,您使用 。所以我对外部请求做了同样的事情。但是我得到了关于错误格式的 xml 的错误。是否可以结合外部 csv 和外部请求(都在单独的文件中)?
    • @sst0107 如果这不能回答您的问题,请假设空手道不支持您想要的:stackoverflow.com/a/62449166/143475
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多