LoginSignup
5
6

More than 5 years have passed since last update.

Capybaraで複数ページのフォームのテスト

Last updated at Posted at 2012-11-21

保険の申込など10画面ぐらいあるウィザード形式の申し込みフォームなどのテストをする時、セッションなどの情報を共有する時に使った方法。
肝はcontextは普通のclassなのでdefでメソッドが定義できるのでそこに共通処理をまとめる点。

context '発注する時' do
  def step1 
    visit '/order/new'
  end

  def step1_input
    fill_in 'name', with:"qiita"
    fill_in 'address', with:"tokyo"
  end

  def step2 
    step1
    step1_input
    click_button 'next'
  end

  def step3
    step2
    click_button 'order'
  end

  it "オーダーページが表示される" do
    step1
    #...
  end

  it "注文が完了する" do
    step3
    #...
  end
end
5
6
0

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
5
6