简体   繁体   中英

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. 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):

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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