[英]Page Objects as variables in Ruby/Watir
I know that you can do something like this: 我知道您可以执行以下操作:
class MyPage
include PageObject
text_field(:field_1, :id => 'field_1')
text_field(:field_2, :id => 'field_2')
end
page = new MyPage
page.field1 = 'foo'
page.field2 = 'bar'
What I would like to do is be able to pass in a variable as the field using cucumber: 我想做的是能够使用黄瓜将变量作为字段传递:
When(/^I set "([^"]*)" field to 'hello'$/) do |some_field|
page.some_field = 'hello'
end
I know you can use page.send(variable)
to call a method, but page.send(variable) = 'hello'
does not work or other variations of that that I have tried so far. 我知道您可以使用page.send(variable)
来调用方法,但是page.send(variable) = 'hello'
无效或到目前为止我尝试过的其他变化。 Is there a way to do what I am asking? 有没有一种方法可以解决我的要求?
使用send时,在方法名称上添加=
:
page.send("#{some_field}=", 'hello')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.