Rya*_*ron 5 javascript ruby-on-rails capybara turbolinks ruby-on-rails-4
我正在努力升级我的 Rails 应用程序以使用 Turbolinks 5 来利用本机包装器。我已经更新了所有的 javascript,并且浏览器和 Android 应用程序中的一切都按预期工作。当我使用 js true 时,我的一些水豚测试遇到了问题。在撰写本文时,我正在使用最新的 capybara (2.11.0)、poltergeist (1.12.0) 和 phantomjs (2.1)。我也尝试过 capybara-webkit 驱动程序,但没有成功。
我似乎遇到问题的是,在 Turbolinks 5 中,所有表单都应远程提交,并且 Turbolinks 知道如何处理请求。我发现使用 Capbara,我的表单在提交后不会重定向,它会保留在同一页面上。我已经做了很多谷歌搜索和反复试验,但还是有一些不足。任何帮助将不胜感激。如果需要更多信息,请告诉我。
scenario 'user has dispatch permission and valid attributes', js: true do
sign_in('jdoe')
page.visit path
page.fill_in 'contact_text_input', with: 'Jimmy'
page.select 'Medium - 3 Hours', from: 'Priority'
page.fill_in 'Created By', with: 'John Doe'
page.click_button 'Create This'
save_and_open_page
expect(page.current_path).to eq("/dispatch")
expect(page).to have_content('This was created successfully')
end
def sign_in(username)
page.visit '/'
page.fill_in 'Username', with: username
page.fill_in 'Password', with: 'test'
page.click_button 'Log In'
end
Run Code Online (Sandbox Code Playgroud)
我有这个问题。expect(page).to have_text("Some text from the page you should be redirected to after login")我的解决办法是(就像 Thomas Walpole 在评论中建议的那样)在提交登录表单后添加一个。
在我们的例子中,我们有一个log_in_buyer_using_the_form测试助手,所以我修改它以接受参数:log_in_buyer_using_the_form(wait_for_content: item.title)
我的假设是,我们需要 1. 等待表单的 Ajax 提交发生,2. 然后等待 Turbolinks 根据 Ajax 响应进行重定向。通过让测试等待某些内容出现,我们知道它已经过了该阶段。
我还没有尝试过的更优雅的方法,但理论上应该可行,是使用该循环设置一个事件侦听器,page.execute_script直到某个事件turbolinks:load运行为止。
| 归档时间: |
|
| 查看次数: |
2384 次 |
| 最近记录: |