karate - 在 karate-netty 中定义一个常数
问题描述
如果我想做类似的事情:
Feature: Register the account and obtain the jwt
Background:
* url baseUrl
* def email = 'qatest_api_' + String(new Date().getTime()) + '@redacted.com'
Scenario: Register
Given path '/identity/v1/register'
* request {email: '#(email)', password: '#(password)'}
When method post
Then status 200
Scenario: Obtain jwt
Given url 'https://redacted/oauth/token'
* request
"""
{
realm: "Username-Password-Authentication",
grant_type: "http://auth0.com/oauth/grant-type/password-realm",
username: '#(email)',
password: '#(password)',
audience: "https://redacted/userinfo",
scope: "openid",
client_id: "redacted",
client_secret: "redacted"
}
"""
When method post
Then status 200
它会在两种情况下评估变量,所以在第一种情况和第二种情况下email
我会得到类似的结果。qatest_api_1542209546879@redacted.com
qatest_api_1542209545312@redacted.com
如果可能的话,我会避免硬编码这个值,我读过callonce
但没有使用它,有一个独立的文件来生成时间戳听起来很有趣。
我正在使用 karate-netty,你对如何实现这一点有什么建议吗?:)
谢谢!
解决方案
callonce
被设计成它可以是右侧的 javascript。
试试这个Background
:
* def fun = function(){ return 'qatest_api_' + new Date().getTime() + '@redacted.com' }
* def email = callonce fun
拥有第二个文件的好处是它可以在多个场景中重复使用,它没有任何问题:)
推荐阅读
- php - 在哪里存储带有 cookie 且没有会话的用户的用户 ID(记住我)
- javascript - C3 使用分类 JSON 数据创建条形图
- java - 允许用户从计算机中选择音乐文件到处理草图中?
- c# - 在 Application_Start 中初始化 StructureMap 容器,但在 Application_BeginRequest 中为空
- java - 使用报告聚合报告和合并多模块 jacoco 报告
- python - 如何获取python操作码的大小
- c# - Linq 包含 - 不适用于子对象
- python - 引导时包括 y 错误 - python 包 seaborn
- python-3.x - PyType_Check() 替代 Python3.5 绑定
- java - javaFX - 等待事件处理程序中的事件