Guest User

Untitled

a guest
Jan 23rd, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. # Have you ever had to sleep() in Capybara-WebKit to wait for AJAX and/or CSS animations?
  2.  
  3. describe 'Modal' do
  4.  
  5. should 'display login errors' do
  6. visit root_path
  7. click_link 'My HomeMarks'
  8. within '#login_area' do
  9. fill_in 'email', with: 'will@not.work'
  10. fill_in 'password', with: 'test'
  11. click_button 'Login'
  12. end
  13. # DO NOT sleep(1) HERE!
  14. assert_modal_visible
  15. page.find(modal_wrapper_id).text.must_match %r{login failed.*use the forgot password}i
  16. end
  17.  
  18. end
  19.  
  20. # Avoid it by using Capybara's #wait_until method. My modal visible/hidden helpers
  21. # do just that. The #wait_until uses the default timeout value.
  22.  
  23. def modal_wrapper_id
  24. '#hmarks_modal_sheet_wrap'
  25. end
  26.  
  27. def assert_modal_visible
  28. wait_until { page.find(modal_wrapper_id).visible? }
  29. rescue Capybara::TimeoutError
  30. flunk 'Expected modal to be visible.'
  31. end
  32.  
  33. def assert_modal_hidden
  34. wait_until { !page.find(modal_wrapper_id).visible? }
  35. rescue Capybara::TimeoutError
  36. flunk 'Expected modal to be hidden.'
  37. end
Add Comment
Please, Sign In to add comment