アドレス用の 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>
2番目の編集ポイントは、これも宣言することでした:
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を選択できる場所。これは可能ですか?