Testing Devise - Capybara::ElementNotFound: Unable to find xpath "/html"
capybara, factory-bot, rspec, ruby-on-rails
Solution
It turns out I have to manually `visit a_path` after the `login_as` to see the additional login page content.
Problem
I'm trying to test the login functionality of my website with RSpec, Capybara and Factory Girl. I always get the following error in the terminal but couldn't find any solution to this. When I use `save_and_open_page` I get a blank page. I hope someone knows what's wrong. Thanks! Here is the `test output` ``` Failure/Error: expect(page).to have_text("Login successful.") Capybara::ElementNotFound: Unable to find xpath "/html" # ./spec/features/navigation_spec.rb:49:in `block (2 levels) in <top (required)>' ``` Here is my `sometest_spec.rb` file with the corresponding lines: ``` require 'spec_helper' include Warden::Test::Helpers describe "User login" do it "log in normal user" do Warden.test_mode! user = create(:normal_user) user.confirmed_at = Time.now user.save login_as(user, scope: :user) expect(page).to have_text("Login successful.") logout(:user) Warden.test_reset! end end ``` Here is my `factory_girl.rb` file ``` RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods end ``` And the `factories.rb` file ``` FactoryGirl.define do factory :normal_user, class: User do firstname "John" lastname "Doe" email "test@user.com" password "thepassword" admin false end end ```