简体   繁体   English

如何在Rails / Capybara中测试页面重新加载?

[英]How to test a page reloading in Rails / Capybara?

I am using Capybara for acceptance testing and I have several scenarios, where I need to test if a page has reloaded or not: 我正在使用Capybara进行验收测试,并且有几种情况,我需要测试页面是否已重新加载:

1) If I leave a search input field empty and click on the search icon I want to verify that nothing happens and in particular that the page does not reload. 1)如果我将搜索输入字段留空,然后单击搜索图标,则要确认没有任何反应,尤其是不会重新加载页面。

2) On the results page I have three sorting options for results. 2)在结果页面上,我有三个结果排序选项。 When I click on a sorting button the page reloads with the chosen sorting criterion applied. 当我单击排序按钮时,页面将重新加载并应用所选的排序标准。 I have some trouble with clicking an element using Capybara or even pure JavaScript, so a means for me to check if the element is clicked at all is to check if the page has been reloaded. 使用Capybara甚至纯JavaScript单击元素时遇到一些麻烦,因此,我检查元素是否全部单击的一种方法是检查页面是否已重新加载。 So how do I do that? 那我该怎么做呢?

一种方法是根据排序标准将一个类添加到表(或其他元素)中,并测试其存在:

page.find_by_css('table.sort_by_foo').should be

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM