普通网友 2017-08-09 13:46
浏览 38

水豚等待ajax加载

Hi I have error in my capybara testing env

 unknown error: jQuery is not defined
        (Session info: chrome=43.0.2357.125)

I think it's related to ajax wait function

 def wait_for_ajax
    Timeout.timeout(Capybara.default_wait_time) do
      element = false
      until element do
        begin
          sleep(0.05)
          count = 0
          begin
            element = page.evaluate_script('jQuery.active') == 0
          rescue Errno::ECONNRESET => e
            count += 1
            restart_phantomjs
            retry unless count > RETRY_COUNT_ERROR_CONNECT
          rescue Capybara::Poltergeist::DeadClient
            count += 1
            restart_phantomjs
            retry unless count > RETRY_COUNT_ERROR_CONNECT
          rescue Capybara::Poltergeist::JavascriptError
          end
        end
      end
    end
  end

Any idea how to solve this? Any help is welcomed. Maybe updating chrome driver is required, not sure whats going on.

  • 写回答

1条回答 默认 最新

  • weixin_33704234 2017-08-09 17:20
    关注

    The wait_for_ajax method you show is specifically written to be used with Poltergeist and requires jQuery to be loaded in the page (the Capybara::Poltergeist error rescuing, restart_phantomjs, etc) so you should not be using it with what appears to be selenium-webdriver using Chrome.

    There's also the fact that wait_for_ajax shouldn't be needed 99.9% of the time with Capybara 2.1+, when used correctly, since it will automatically wait for elements/text to appear so whether it's coming from an ajax request or a page load shouldn't matter. That combined with the fact that more and more libraries are using XMLHttpRequest directly rather that through jQuery means wait_for_ajax is virtually unnecessary. Pretty much the only exception to that is when you have a badly designed UI that provides no feedback to the user about background requests and their effects, in which case I'd suggest fixing your UI.

    评论

报告相同问题?