Search code examples
ruby-on-railsrubycapybaraheadlesscapybara-webkit

how to solve the 'undefined method `network_traffic'' error


I'm getting this error after recently switching from poltergeist to webkit headless

*** NoMethodError Exception: undefined method `network_traffic' for #Capybara::Selenium::Driver:0x007fc2f30bbbd0>

The offending line of code is

!page.driver.network_traffic.collect(&:response_parts).any?(&:empty?)

Solution

  • Whenever you call page.driver.xxxxxx you're calling driver specific methods which may not be supported by any other driver. network_traffic is one of those driver specific methods that is only supported by Poltergeist. In the future, if you want your tests to be compatible across multiple drivers stay away from any page.driver.xxxx calls.

    For this case, the code you show seems to be checking all responses had content. I'm not sure how that fits into your specific test, but feature tests really shouldn't be worrying directly about specific network transfers, rather they should be worrying about the actual data displayed to the user.