Unreliable/Flakey Capybara/AngularJS Integration Tests With Timing Issues

前端 未结 2 2016
隐瞒了意图╮
隐瞒了意图╮ 2021-02-10 14:57

How do I make these tests reliably pass?

Currently these tests are flakey.
Sometimes they pass. Sometimes they fail.
Below is the setup, code and output demons

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-10 15:21

    The immediate thing that jumps out is that your admin_sign_in doesn't actually wait for the sign_in to complete. This means that your call to create_costing can occur without the session cookie having been set in your browser. The last line in your admin_sign_in method should be something like

    expect(page).to have_text('You are signed in') # whatever message is shown upon sign in
    

    or

    expect(page).to have_current_path('/') # whatever path an admin is redirected to upon signing in
    

    That will make sure the login has actually completed and therefore the session cookies have been set in your browser.

    Also your database cleaner config should use an append_after block rather than after - see https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example

提交回复
热议问题