Ruby on rails 如何使用Capybara测试js重定向?
在我的控制器中,使用以下代码执行重定向: 会话控制器Ruby on rails 如何使用Capybara测试js重定向?,ruby-on-rails,capybara,Ruby On Rails,Capybara,在我的控制器中,使用以下代码执行重定向: 会话控制器 def create render js: "window.location.pathname = #{home_path.to_json}" end 但是,当我运行capybara时,它在登录提交后不会进入主页: describe "Login Test", :js => true do before do @user = FactoryGirl.create(:user) end it 'should sh
def create
render js: "window.location.pathname = #{home_path.to_json}"
end
但是,当我运行capybara时,它在登录
提交后不会进入主页:
describe "Login Test", :js => true do
before do
@user = FactoryGirl.create(:user)
end
it 'should show the users first name' do
visit login_path
fill_in 'email', with: @user.email
fill_in 'password', with: @user.password
click_button "Log In"
save_and_open_page
assert page.has_content? @user.first_name
end
end
当我通过添加launchy gem
并运行save_和_open_页面
进行故障排除时,我会得到一个包含以下文本的页面:
window.location.pathname=“/”
水豚给了我以下错误:
Capybara::ElementNotFound:找不到xpath”/html“
水豚似乎永远都无法通过登录按钮。你试过这个吗
respond_to do |format|
format.js { render :js => 'window.location.href = "#{home_path.to_json}"' }
end