8
7

More than 5 years have passed since last update.

Capybaraで画面要素の表示順を検証する

Posted at

たとえばItemの一覧ページで要素がソートできていることを検証したいとします。

テストデータのItem#titleはランダムな文字列が入っているという前提があれば、下記のコードで検証できます。

expect(page.text).to match %r{#{item_1.title}.*#{item_2.title}}

他の箇所にも表示されている場合はwithinで検証する範囲を絞ればOK。

within('.item-list-container') do
  expect(page.text).to match %r{#{item_1.title}.*#{item_2.title}}
end
8
7
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7