我正在升级我的Rails应用程序,以便使用Turbolinks 5来利用Native包装器。我已经更新了我所有的javascript,一切都在浏览器和Android应用程序中正常工作。当我使用js true时,我的一些水豚测试遇到了问题。在写这篇文章的时候,我使用的是最新的水豚(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发布于 2019-09-21 13:26:43
您可以通过进度条跟踪Turbolinks AJAX请求,如下所示:
def wait_for_turbolinks
has_css?('.turbolinks-progress-bar', visible: true)
has_no_css?('.turbolinks-progress-bar')
end发布于 2020-01-28 04:28:35
不错的解决方案ErgoLau。我做了一些小改动来修正最大等待时间。
def wait_for_turbolinks timeout = nil
if has_css?('.turbolinks-progress-bar', visible: true, wait: (0.25).seconds)
has_no_css?('.turbolinks-progress-bar', wait: timeout.presence || 5.seconds)
end
end发布于 2017-10-03 21:49:54
我有这个问题。我的解决方案是(就像Thomas Walpole在评论中建议的那样)在提交登录表单后添加一个expect(page).to have_text("Some text from the page you should be redirected to after login")。
在我们的例子中,我们有一个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这样的事件运行为止。
https://stackoverflow.com/questions/41683670
复制相似问题