mercredi 25 octobre 2017

Capybara test case for Login page authentication

I have capybara test case below.

it "Testing login page with valid data" do
  fill_in 'email', with: 'kiran@gmail.com'
  expect(page).to have_selector("input[value='kiran@gmail.com']")#Checking values are inserted in email field

  fill_in 'password', with: 'Kiran.6565'
  expect(page).to have_selector("input[value='Kiran.6565']")#Checking values are inserted in password field

  click_button('submit')

  expect(current_path).to eql(patient_detail_path(4))

end

I am checking Login page once the email and password fields are matches it should redirect to patient_details_path with id field value. In above code i specified email and password is working fine for manual login, but problem is in test case. Expected result: it should redirect to another page(patient_details_path) but it redirecting to home page(/) again.

Failures:

1) Login Page Interface Test login page with valid data
   Failure/Error: expect(current_path).to eql(patient_detail_path(4))

   expected: "/patient_details/4"
        got: "/"

   (compared using eql?)
 # ./spec/views/login_spec.rb:41:in `block (2 levels) in <top (required)>'

Finished in 1.08 seconds (files took 2.13 seconds to load)
14 examples, 1 failure

I tried different solution's from stackoverflow but nothing work for me. Below are the different solution's tried.

#expect(current_path).to eql(patient_detail_path(4))
#expect(page).to have_current_path(patient_detail_path(4))

If email and password mismatch it will throw an error and redirect to login page again. In my scenario it was throwing an error even if email and password are valid . If i add below code in my test case it will work pass the test case.

#expect(page).to have_content "Invalid username/password combination"

Any one please help me i am new to ruby on rails and capybara.

Aucun commentaire:

Enregistrer un commentaire