【问题标题】:How to dynamically create URL having path in between URL using Karate framework如何使用空手道框架在 URL 之间动态创建具有路径的 URL
【发布时间】:2019-02-24 18:41:33
【问题描述】:

我想使用空手道框架创建一个动态 url。假设我要创建的 URL 是:

https://www.mars.com/mars/profile/{profileID}/line

在上面的 URL {profileID} 是路径。

目前我在下面编写了能够创建 url 的功能文件,但是由于使用 path 关键字,它对 url 进行编码并在配置文件 ID 后添加 %0A

https://www.mars.com/mars/profile/264%0A/line

功能文件:

@smoke
Scenario: Create  a line score in existing  profile
And def urlname = marsuri+ '/mars/profile/'

Given url urlname
Given path id + '/line'

请告诉我如何在不编码的情况下创建一个在 URL 之间包含路径的 URL。

【问题讨论】:

    标签: karate


    【解决方案1】:

    您没有正确使用path 语法。请阅读文档:https://github.com/intuit/karate#path

    进行此更改:

    Given path id, 'line'
    

    编辑:另请参阅此答案:https://stackoverflow.com/a/54477346/143475

    【讨论】:

    • 我按照建议使用了,@smoke 场景:在现有配置文件中创建线分数和 def urlname = marsuri+ '/mars/profile/' 给定 url urlname 给定路径 id,'line'
    • 仍然低于错误:com.intuit.karate.exception.KarateException:状态代码为:404,预期:200,响应时间:13,url:mars.com/mars/profile/268%0A/line,响应: 404 Not Found

      Not Found

      在服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试。

      at com.intuit.karate.StepDefs.status(StepDefs.java:491)
    • @Automation_Test 是时候向您推荐这些说明了!一切顺利;)github.com/intuit/karate/wiki/How-to-Submit-an-Issue
    【解决方案2】:

    实际上,无论您从何处获取 id 变量,它在字符串末尾都有一个新行,类似于 "264\n" 这就是它被编码为 264%0A 的原因

    如果您只想传递"264",则必须先删除不需要的值,然后再将其添加到path

    Background:
    * def removeNewLine = function(x){return x.replace("\n","")}
    
    Scenario: Create  a line score in existing  profile
    And def urlname = marsuri+ '/mars/profile/'
    Given url urlname
    * def id = removeNewLine(id)
    Given path id + '/line'
    

    如果您可以直接从获得id 的源中修改数据,那就太好了。

    【讨论】:

    • Great Babu Sekaran,它起作用了,我从来没有意识到 id 带有“\n”。好渔获
    猜你喜欢
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 2020-01-27
    • 1970-01-01
    相关资源
    最近更新 更多