【问题标题】:get the params value from a variable从变量中获取参数值
【发布时间】:2023-02-05 05:40:49
【问题描述】:

我有一个功能文件作为 功能:获取令牌

背景:

标头内容类型'application/json'

  • def CookieGenerator = Java.type('com.ade.Helpers.CookiesGenerator');

def endpoints read('classpath: src/test/java/com/ade/resources/endpoints.json')

给定 url endpoints.token

场景:检查响应的架构

给定 cookies (new CookieGenerator().getCookieValue())

当方法 GET

然后状态200

  • def txnToken = 响应

#打印令牌

从上面的代码我得到令牌的价值是这样的“gdjsgjshjhsjfhsg646”

现在我有另一个功能文件,我必须在我的查询参数值中使用上面的令牌值作为 功能:测试日期名称和客户

背景:

header Content-Type 'application/json""

def endpoints read('classpath:src/test/java/com/ade/resources/endpoints.json") def CookieGenerator Java.type('com.ade.Helpers.CookiesGenerator");

  • 调用 read('Token.feature') 给定 url baseUrl+endpoints.dit.Client.path

场景:检查响应的架构

给定 def head read('classpath:src/test/java/com/ade/resources/reqpay.json") =

def req head.data[1]

和 cookies (new CookieGenerator().getCookieValue())

并请求请求

和参数 {txntoken = txnToken} 当方法发布

然后状态200

从上面我的端点应该像https://something.com/clients?txntoken='gdjsgjshjhsjfhsg646' 但我得到了https://something.com/clients?txntoken=txnToken

https://something.com/clients?txntoken='gdjsgjshjhsjfhsg646'

【问题讨论】:

标签: api parameters karate


【解决方案1】:

正如@peter-thomas 所说,您的帖子很难阅读,请以后尝试更好地格式化它,或者如果我没有回答您的问题,请编辑帖子。

我相信您正在寻找的内容在文档here 中有所描述

  * def signIn = call read('classpath:my-signin.feature') { username: 'john', password: 'secret' }
  * def authToken = signIn.authToken

你可以看到信息是如何传递的

我最近也问了一个类似的问题here

相关位在这里:

* def key = karate.call('ReadRoundUpSubscription.feature');

* def keyvalue = key.acckey

我更喜欢这样称呼功能,而不是在可重用功能中定义内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多