简体   繁体   English

使用json_spec在步骤定义中访问Cucumber功能变量

[英]Access Cucumber feature variable in a step defintion with json_spec

I downloaded the json_spec gem and I'm trying to access a variable that was stored in my Cucumber feature file. 我下载了json_spec gem,并尝试访问存储在Cucumber功能文件中的变量。 From the json_spec readme it shows that you can store a variable as follows; 从json_spec 自述文件中可以看出,您可以按以下方式存储变量; I keep the JSON response as "USER_1". 我将JSON响应保留为“ USER_1”。 Is there any way to access this "USER_1" variable for use in my step defintions? 有什么方法可以访问此“ USER_1”变量以在我的步骤定义中使用?

Yes there is. 就在这里。

JsonSpec.memory[:USER_1]

Will allow you to access the specific stored value. 将允许您访问特定的存储值。 However this is not really documented as supported behaviour and as such constitutes an implementation detail that is subject to change. 但是,这并未真正记录为受支持的行为,因此构成了可能更改的实现细节。 So i wouldn't rely on it. 所以我不会依靠它。

And additionally you should always be able to access the actual JSON as last_json , which is the method you need to provide for json_spec to work. 另外,您应该始终能够以last_json身份访问实际的JSON,这是为使json_spec工作而需要提供的方法。 If i needed to do something with the response (eg to issue additional requests) i would parse last_json myself. 如果我需要对响应做一些事情(例如发出其他请求),我将自己解析last_json

The code for the JsonSpec memory can be found here . JsonSpec存储器的代码可以在这里找到。 And the usage of it during the step-definition can be seen here . 可以在这里看到它在步进定义中的用法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我使用json_spec的Cucumber方案失败,并且last_json在哪里定义? - Why does my Cucumber scenario that uses json_spec fail, and where is last_json defined? 使用json_spec gem的“在“路径”处应包括:“步骤未按我预期的那样工作 - Using json_spec gem's 'at “path” should include:' step is not working as I would expect Cucumber功能可以将常量传递给步骤定义吗? - Can a Cucumber feature pass a constant to a step definition? 伪造RSpec和Capybara特征规范中的实例变量 - Faking instance variable in RSpec and Capybara feature spec 在Cucumber功能文件之前仅需要执行一次步骤(每个功能可能具有差异步骤) - Need to execute a step (each feature may have diff step) only once before a Cucumber feature file 我想在黄瓜特征文件中使用变量 - I Want to use variable in cucumber feature file 让黄瓜步骤在另一步骤中验证页面对象设置的变量 - Have Cucumber Step Verify Variable Set By A Page Object In Another Step 如何在步骤定义中访问Cucumber步骤名称? - How can I access a Cucumber step name in the step definition? 黄瓜:在步骤定义中访问当前控制器实例 - Cucumber: Access current controller instance within step definitions 如何从黄瓜步骤访问语言字符串? - How can I access language strings from a cucumber step?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM