[英]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.