I am trying to create test to admin panel. But it fails while the program try to log_in.
Failures:
1) Visit products login works correctly Failure/Error: expect(page).to have_content("Logged in successfully")
expected to find text "Logged in successfully" in "Login\nAll departments\nHome\nCart: (Empty)\n \nInvalid email or password.\nLogin as Existing Customer\nRemember me\nor Create a new account | Forgot Password?" # ./spec/features/home_spec.rb:14:in `block (2 levels) in '
The password, and the email are correct for admin. I found solutions in other posts, like adding configuration to capybara, but it still fails.
spec_helper
require 'capybara/rspec'
require 'rails_helper'
require 'spree/testing_support/controller_requests'
require 'capybara/rails'
Capybara.app_host = "http://localhost:3000"
Capybara.server_host = "localhost"
Capybara.server_port = "3000"
_spec.rb
require "spec_helper"
RSpec.describe 'Visit products' do
it 'login works correctly' do
visit spree.admin_path
fill_in "spree_user[email]", with: "[email protected]"
fill_in "spree_user[password]", with: "password"
click_button Spree.t(:login)
expect(page).to have_content("Logged in successfully")
end
end
Invalid email or password
either the email or password aren't correct, or the user for the test isn't being created correctly. How are you creating the user for the test, and what version of Rails are you using? – Thomas Walpoleserver_host
,server_port
, andapp_host
?? For most people leaving those as the defaults is a better config (doesn't prevent you running your dev instance at the same time, etc) – Thomas Walpolefactory_bot
to create users before your test run. – Thomas Walpole