简体   繁体   English

实例变量将数据存储在黄瓜/红宝石/牛奶中?

[英]Instance Variable to store data in cucumber/ruby/watir?

I am writing some automation tests using ruby/watir/cucumber for a cart. 我正在使用红宝石/瓦特尔/黄瓜为购物车编写一些自动化测试。 I need to save the item info to be used on the review and confirmation pages. 我需要保存要在审阅和确认页面上使用的项目信息。 Are instance variables the way to do this? 实例变量是这样做的方法吗? I would imagine some type array of hashes stored in a instance variable since I would need to store the description, quantity ordered, price, and variant. 我想像一个散列类型数组存储在实例变量中,因为我需要存储描述,订购数量,价格和变量。 For example: 例如:

@cartItems = []

apple = {type: 'washington', quantity: 1, price: 0.74}
orange = {type: 'naval', quantity: 2, price: 1.25}
banana = {type: 'cavendish', quantity: 4, price: 0.50, size: 'large'}
@cartItems = push(apple)
@cartItems = push(orange)
@cartItems = push(banana)

Then I would read @cartItems to check for those things on the review/confirmation pages? 然后,我将阅读@cartItems来检查复查/确认页面上的那些内容? Would be able to add to the @cartItems from any page? 可以从任何页面添加到@cartItems吗?

There are several theories about whether this is appropriate or not. 关于这是否合适,有几种理论。 Here is an article which discusses the pros and con. 这是一篇讨论利弊的文章

Here is the outline. 这是大纲。

  • It leads to more readable steps 它导致更具可读性的步骤
  • We lose referential transparency for our steps 我们的步骤失去了参照透明度
  • Is it worth it? 这值得么?
    • We're relying on state anyway 无论如何我们都依赖状态
    • I'm not a big fan of step reuse. 我不是步骤重用的忠实拥护者。
  • Use member variables with care 小心使用成员变量

To get truly robust with this you should probably start using the "Test Data Builder" design pattern. 为了真正做到这一点,您可能应该开始使用“ Test Data Builder”设计模式。 This pattern will allow you to create and store large data structures to be used in your tests. 该模式将允许您创建和存储要在测试中使用的大型数据结构。 See the TestFactory gem's documentation for a description of one way to code this pattern: https://github.com/rSmart/TestFactory 请参阅TestFactory gem的文档,以获取对该模式进行编码的一种方法的描述: https : //github.com/rSmart/TestFactory

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

相关问题 黄瓜,watir数据工厂 - data factory for cucumber, watir Netbeans中的Ruby Watir和Cucumber-方案未定义 - Ruby Watir and Cucumber in Netbeans - scenario undefined 如何从网页复制数据并将其粘贴到文件中以便与ruby,watir和cucumber一起使用? - How do I copy data from web page and paste it in file for further use with ruby, watir and cucumber? 与 Capybara 在 Cucumber Ruby 中跨步骤共享实例变量 - Share instance variable accross steps in Cucumber Ruby with Capybara 存储在实例变量中,每个块都会产生红宝石 - store in instance variable, each block results ruby JSON数据到Ruby中的实例变量 - JSON data to instance variable in Ruby Ruby Cucuming Watir-WebDriver无法识别放置在框架中的对象 - Ruby cucumber watir-webdriver is not identifying the object which is placed in a frame 是否有将Cucumber / Watir / Ruby测试结果写入数据库的好方法? - Is there a good way to write Cucumber/Watir/Ruby test results to a database? 如何使用Ruby Watir和Cucumber设置QA自动化框架 - How to set up QA Automation Framework with Ruby Watir and Cucumber 使用Ruby / Watir在hooks文件中获取黄瓜数据表 - Get cucumber datatable in hooks file using Ruby/Watir
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM