简体   繁体   English

如何使用水豚在页面上测试自动定期更新?

[英]How to test auto periodic updates on the page using capybara?

I have one page where user can leave opened for a while. 我有一个页面,用户可以在其中打开一段时间。 And javascript is making updates using setInterval. javascript正在使用setInterval进行更新。 How could I test it? 我该如何测试?

Scenario: Auto update dashboard
  When I am on the dashboard page
    Then I should see nothing on the page

  When someone added item
    Then I should see a new item on the page in few seconds

I can put sleep to the 'someone added item', but is it good way to do it? 我可以睡在“添加了某人的物品”上,但这是个好方法吗? Anyway 'sleep' doesn't work for me for some reasons. 无论如何,出于某些原因,“睡眠”对我而言不起作用。

Thanks in advance. 提前致谢。

Capybara's has_content will automatically wait (you can decide for how much) for some content to appear, so you can have something like this (rspec syntax): Capybara的has_content将自动等待(您可以决定多少)一些内容出现,因此您可以使用以下内容(rspec语法):

page.should have_content 'Update 1'
page.should have_content 'Update 2'
page.should have_content 'Update 3'

Of course it may be helpful to test for the state in between, but this may be good enough. 当然,测试介于两者之间的状态可能会有所帮助,但这可能就足够了。

EDIT: I'm assuming the interval is very small, like a couple of seconds at most, otherwise your tests will run very slowly. 编辑:我假设间隔很小,最多最多只有几秒钟,否则您的测试将运行非常缓慢。

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

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