我有一个包含 3 个 div 的地址(主地址、辅助地址、添加地址)的表单。每个 div 包含以下元素 (text_field):姓名、地址、电话。根据场景,我想编辑特定 div 的文本字段。
所以我有这种情况:
Given I am at the form for editing addresses
When the div "main address" is visible
Then fill the "name" element for the "main address" div
And erase the "address" for the "main address" div
以及以下步骤定义:
Then(/^fill the "([^"]+)" element for the "([^"]+)" div$/) do |element, div|
on_page(AddressPage).fill_element element div
end
现在我不确定的部分 - 地址页面
class AddressPage
include PageObject
include DataMagic
div(:main_address, :id => 'main_address')
div(:secondary_address, :id => 'secondary_address')
div(:add_address, :id => 'add_address')
def fill_element(element, div)
current_div = self.send("#{div}_element")
# now the part I don't know how to do:
current_element = div.search_within(current_div, element)
fill_with_correct_data current_element
end
def search_within(div, element)
# How to do this?
end
end
我怎样才能做到这一点,这样我就不必为所有 div 定义所有元素(div 的数量是动态的)?我需要知道的是,是否有一种方法可以搜索一个元素以使其位于另一个元素中。
谢谢 :)
编辑html 将如下所示:
<div id='main_address'>
<input id='name'>
</input>
<input id='address'>
</input>
<input id='phone'>
</input>
</div>
<div id='secondary_address'>
<input id='name'>
</input>
<input id='address'>
</input>
<input id='phone'>
</input>
</div>
<div id='add_address'>
<input id='name'>
</input>
<input id='address'>
</input>
<input id='phone'>
</input>
</div>
第二次编辑重点是还要声明这一点:
select_list(:name, :id => 'name')
select_list(:address, :id => 'address')
select_list(:phone, :id => 'phone')
#Is this possible?
current_name_element = main_address.name
#?
#Also, at the end the point is to call the Datamagic populate_page_with method
populate_page_with data_for 'new_user'
“default.yml”看起来像这样:
new_user:
name: ~first_name
address: ~address
phone: ~phone
我可以在哪里选择将填充哪个 div。这可能吗?