title: Capybara/Selenium gets a Net::ReadTimeout randomly on location.reload()
body: <p>I'm using Capybara, the selenium-webdriver gem, and chromedriver in order to drive my javascript enabled tests.</p>
  
  <p>The problem is that about 50% of our builds fail due to a <code>Net::ReadTimeout</code> error. At first this was manifesting as a 'could not find element' error, but after I upped Capybara's default max wait time to 30 seconds, I started seeing the timeout.</p>
  
  <p>I examined the screenshots of when the timeout happens, it's stuck on a 'Successfully logged in' modal that we show briefly before using the Javascript function, <code>location.reload()</code>, to reload the page.</p>
  
  <p>I've ran the test locally and can sometimes reproduce it, also randomly. Sometimes it zips by this modal and does the reload so fast you can barely see it, and other times it just hangs forever.</p>
  
  <p>I don't feel like it's an asset compilation issue, since the site has already loaded at that point in order for the user to access the login form.</p>
  
  <p>Wondering if anyone has seen this before and knows a solution.</p>
  
  <p>The specific code:</p>
  
  <pre><code>    visit login_path
  
      page.within '#sign-in-pane__body' do
        fill_in 'Email', with: user.email
        click_button 'Submit'
      end
  
      expect(page).to have_content 'Enter Password'
  
      page.within '#sign-in-pane__body' do
        fill_in 'Password', with: user.password
        click_button 'Submit'
      end
  
      expect(page).to have_text 'Home page landing text'
  </code></pre>
  
  <p>The hang up happens between <code>click_button 'Submit'</code> and expecting the home page text. </p>
  
  <p>The flow of the logic causing the timeout is the user submits the login form, we wait for the server to render a <code>.js.erb</code> template that triggers a JS event upon successful login. When that trigger happens we show a modal saying that login was successful, then execute a <code>location.reload()</code>.</p>