dsl - 从一个功能设置空手道中的全局变量以用于另一个功能
问题描述
问题
我有 3 个不同的功能文件。一个用于 EndToEndTest.feature(集成测试),一个用于 create-service.feature(基本 api 调用),另一个用于 create-tariff(需要 create-service.feature 响应的 api 调用)
EndToEndTest.feature
Feature: End To End Standard
Background:
* def result = call read('../get-user-token.feature')
* def service = call read('create-service.feature')
* def location = service.responseHeaders['Location'][0]
* def serviceId = location.substring(location.lastIndexOf('/') + 1)
# I want serviceId to be set globally so I can access it into the create-tariff.feature
* def tariff = call read('create-tariff.feature')
创建关税特征
Feature: Create Tariff
Background:
* def result = call read('../../get-user-token.feature')
* def service = serviceId
很明显,这里的第二个 def (service=serviceid) 将失败,因为它将无法从第一个获取 serviceId 集
我的问题是,从 EndToEndTest.feature 传递一个变量(serviceId)以分配给 create-tariff.feature 中的另一个变量(服务)的最佳方法是什么
解决方案
使功能相互依赖是一种非常糟糕的做法,我不建议这样做。你甚至不应该让Scenario
-s 依赖于其他的。
请阅读:https ://github.com/intuit/karate#script-structure
请注意,您有钩子- 特别karate.callSingle()
是但它仅适用于您登录并获取令牌然后需要重新使用它的情况。
推荐阅读
- javascript - 在一个语句中从 ES6 模块导入类和副作用
- javascript - Three.js TimeLineLite 动画不起作用
- c - 与 c 中的 NULL 指针的比较
- arrays - SwiftUI:我有一个列表,当我单击一个对象时,我想进入一个详细视图,我可以在其中选择或取消选择当前对象
- swift - 如何在 swiftUI 中更改 @State public var 值?
- mysql - MySQL index_merge 导致查询运行速度慢 10 倍
- javascript - 无法读取未定义 Javascript 的“长度”类型的属性
- android - HTTP 在 web 中有效,但在实际的 android 设备中无效(IONIC 移动开发)
- python - 转换为日期时间时如何修复 ValueError?
- javascript - 使用数组解构时出现运行时错误?