通过Selenium Capybara Rspec测试中的前端登录用户



我想在使用javascript的测试中以用户身份登录,所以我想我应该有一个通过前端登录用户的辅助方法。但是与助手

    def log_user_in_via_frontend(user)
        visit root_path
        fill_in 'user_session_login', :with => user.login
        fill_in 'user_session_password', :with => user.password
        click_on('Login')
    end

只要我不把:js => true放在最后,我就可以登录并被重定向到正确的页面。我通过以下方式称呼这个助手

    user = FactoryGirl.create(:user)
    log_user_in_via_frontend(user)

事后访问root_path会产生No route matches {:controller=>"users", :action=>"show", :id=>#<User id: nil, login: nil...

在我的硒测试中让登录用户的最佳方式是什么?

实际上,现在这对我有用。我不确定究竟是什么,但我认为关键是停用过渡夹具,并让数据库清理器进行清理。

最新更新