[英]How to test auto periodic updates on the page using capybara?
我有一個頁面,用戶可以在其中打開一段時間。 javascript正在使用setInterval進行更新。 我該如何測試?
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
我可以睡在“添加了某人的物品”上,但這是個好方法嗎? 無論如何,出於某些原因,“睡眠”對我而言不起作用。
提前致謝。
Capybara的has_content將自動等待(您可以決定多少)一些內容出現,因此您可以使用以下內容(rspec語法):
page.should have_content 'Update 1'
page.should have_content 'Update 2'
page.should have_content 'Update 3'
當然,測試介於兩者之間的狀態可能會有所幫助,但這可能就足夠了。
編輯:我假設間隔很小,最多最多只有幾秒鍾,否則您的測試將運行非常緩慢。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.