问题
我有3页不同功能的文件。一个是用于EndToEndTest.feature(集成测试),一种是为创建-service.feature(一个基本API调用),另一种是用于创建关税(API调用,需要从创建-service.feature响应)
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')
创建-tariff.feature
Feature: Create Tariff
Background:
* def result = call read('../../get-user-token.feature')
* def service = serviceId
其明显的第二这里DEF(服务=服务ID)会失败,因为它会无法获得服务ID从第一组
我的问题是,什么是EndToEndTest.feature传递一个变量(服务Id)分配给其他变量(服务)的最佳方式创建,tariff.feature
其特点是互相依赖的是一个非常不好的做法,我不建议这样做。你不应该甚至有Scenario
-S依赖于其他的。
请仔细阅读本:https://github.com/intuit/karate#script-structure
请注意,您必须hooks - 特别karate.callSingle()
但它仅用于在您登入,并获得令牌,然后需要各地重新使用它的情况。