キュウリを使用して、アプリの Ruby on Rails ビューの内容を確認しようとしています。ビューには、情報が表形式で表示されます。そのテーブルの 1 つの列の内容のみを確認できるようにしたい。Web ステップ定義を使用すると"I should see"
、ページ全体がチェックされます。これを行う簡単な方法はありますか?
例えば:column.should have_content("text")
キュウリを使用して、アプリの Ruby on Rails ビューの内容を確認しようとしています。ビューには、情報が表形式で表示されます。そのテーブルの 1 つの列の内容のみを確認できるようにしたい。Web ステップ定義を使用すると"I should see"
、ページ全体がチェックされます。これを行う簡単な方法はありますか?
例えば:column.should have_content("text")
Capybara のビルトイン スコーピングは、それらの xpath よりも保守が少し簡単かもしれません
within "#id_for_your_tr"
within('td', :class=> 'class_for_your_column')
page.should have_content "foo"
end
end
カピバラ+きゅうりを使って、あなたの歩みは
Then I should see the following (#MYTABLE)
| FOO | 94040 | "friendly" |
| BAR | 94050 | "competition"|
ステップ定義
Then /^I should see the following games:$/ do |expected_table|
table_results = page.find('#DOM_ID')
end
あなたの定義に対する私の複雑なアプローチ
When /^(.*) in the "([^\"]*)" column of the "([^\"]*)" row$/ do |
action, column_title, row_title|
col_number = 0
all(:xpath, "//*[(th|td)/descendant-or-self::*[contains(text(),
'#{column_title}')]]/th").each do |element|
col_number += 1
break if element.has_content?(column_title)
end
within :xpath, "//*[(th|td)/descendant-or-self::*[contains(text(),
'#{row_title}')]]/td[#{col_number}]" do
When action
end
end
テーブル構造が生成されていることを確認するには、行数の確認を使用できます page.should have_selector('table tr', :count => X)