0

我正在处理一个问题,但无法找到一个聪明的解决方案。简而言之:假设我们在 page-object 中定义了许多文本字段元素:

 text_field(:txt_field_1, id: 'field1')
 text_field(:txt_field_2, id: 'field2')
 ....

我可以轻松地填写一个字段:

def fill_field1(content)
 self.txt_field_1 = content
end

...调用方法:

fill_field1('John Doe')

我正在寻找的是使用独特的方法来填充几个字段,使用页面对象元素名称作为方法参数,例如:

def fill_fields(field, content)
 self.field = content
end

...并以这种方式调用该方法:

fill_fields('txt_field_1', 'John Doe')

上面的示例因“未定义的方法”错误而失败。我尝试使用这种send()方法self.send('field') = 'John Doe'不成功。我很确定有办法做到这一点......你能解释一下这个问题吗?

4

1 回答 1

2

根据示例,您可以使用页面对象 gem 的内置populate_page_with方法。假设已经在页面对象中定义了文本字段,那么您可以执行以下操作:

example_page.populate_page_with :txt_field_1 => 'John Doe'

或者执行多个字段,例如:

example_page.populate_page_with :txt_field_1 => 'John Doe', :txt_field_2 => 'Jane Doe'
于 2014-02-06T14:05:54.410 回答