1

I'm interacting with a JavaScript-heavy website which uses SignalR polling. This usually causes Watir-Webdriver to time out after loading a page.

I've managed partial success by appending the command:
driver.execute_script '$.connection.hub.stop();'
to every page navigation instruction, like goto or click.

However this doesn't work in every instance, as I think the polling sometimes starts just after the page loads. In some cases the polling is triggered by selecting a radio button or checkbox as well.

Is there a reliable way of handling polling, other than having to use Timeout and revisiting the page after each failure?

Virtuoso
  • 908
  • 1
  • 8
  • 14

1 Answers1

1

I wonder if you're getting hung up on the specifics of what you're trying to accomplish. I think I would create a handler for actions, pass them your code to try, handle specific exceptions and retry.

def action_handler(*arg, &code)
  begin
    code.call arg if block_given?
  rescue Some::Specific, Error::Classes => e
    @driver.execute_script '$.connection.hub.stop();'
    retry
  end
end
# ...
def whatever
  # ...
  action_handler { @browser.link(:id => 'obj').when_present.click }
  # ...
end

And maybe there are better JavaScript methods to stop polling -- return window.stop();, maybe? Or throw new Error("BOOM!");? Or $.connection.hub.abort()? (Some reading.)

To make your code DRY, you could go about monkey-patching Timer or Element or something like that in Watir-Webdriver, ymmv.

Community
  • 1
  • 1
Sam
  • 1,205
  • 1
  • 21
  • 39
  • Thanks, I'll look into your suggestions. I'm already using DRY timeouts and error handling, revisiting the url to regain control of the browser, but it's still difficult when onclick events in the page seem to re-establish the polling. I'm looking forward to testing your ideas out :) – Virtuoso Dec 18 '15 at 23:20
  • @Virtuoso Let me know how you get on with it. The only thought I've had since posting is maybe you can malform the URIs or some other part of the script (function names?) in the page's JavaScript while testing (and then re-form them as necessary). – Sam Dec 24 '15 at 08:54
  • I have no control of the page's content as I'm using watir to automate some repetitive input tasks. I've captured the page's url at the start of the error handling block so I can revisit it if there's a timeout error. – Virtuoso Dec 24 '15 at 18:27
  • I've found a way to avoid some of the more unpredictable long-polling events by using `profile['webdriver.load.strategy'] = 'unstable'` and `when_present`. – Virtuoso Mar 14 '16 at 13:55
  • ChromeDriver doesn't seem to experience this issue, I think it's a Firefox problem. – Virtuoso Feb 07 '18 at 10:10