LoginSignup
0

More than 1 year has passed since last update.

【RSpec】have_xpathの使い方|テキストフィールドの中身をテストする

Last updated at Posted at 2022-08-15

have_xpathの使い方

have_xpathを使うとタグの有無を確認することができます。

#ページ内に指定した属性が'hoge'である指定したタグがあるかテストする
expect(page).to have_xpath "//タグ名[@属性名='hoge']"

#ページ内にvalue属性が'サンプルデータ'であるinputタグがあるかテストする(テキストフィールドの中身が'サンプルデータ'かどうかテストする)
expect(page).to have_xpath "//input[@value='サンプルデータ']"

※XPathとはなんぞや?という人は以下のサイトを参考にしてください。
【図解】XPathとは?基本概念から書き方までわかりやすく解説!

参考

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
0