Module: SeleniumWebDriverRemoteRailsSupportMonkeyPathOfDoom

Defined in:
lib/selenium-webdriver-rails-support-via-monkeypatch.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/selenium-webdriver-rails-support-via-monkeypatch.rb', line 2

def self.included base
  base.class_eval do
    if respond_to? :alias_method_chain
      alias_method_chain :request, :rails_support_that_fixes_crappy_json
    else
      raise "alias_method_chain isn't defined ... are you in a Rails app?  If now, why are you using this evil monkeypatch?"
    end
  end 
end

Instance Method Details

#request_with_rails_support_that_fixes_crappy_json(verb, url, headers, payload, redirects = 0) ⇒ Object

This is what we SHOULD get

"{\"desiredCapabilities\":{\"javascriptEnabled\":false,\"version\":\"\",\"browserName\":\"htmlunit\",\"platform\":\"ANY\"}}"

But this is what we get instead

"{\"desiredCapabilities\":{\"browser_name\":\"htmlunit\",\"javascript_enabled\":false,\"version\":\"\",\"platform\":\"any\"}}"

To get this fixed immediately, we simply rewrite the payload to camelcase key names and upcase the platform.

We’ll find a better way to do this later and submit a patch to selenium. It’s ActiveSupport’s #to_json that is killing us!



24
25
26
27
28
29
30
31
# File 'lib/selenium-webdriver-rails-support-via-monkeypatch.rb', line 24

def request_with_rails_support_that_fixes_crappy_json(verb, url, headers, payload, redirects = 0)
  if payload
    payload.sub!('browser_name', 'browserName')
    payload.sub!('javascript_enabled', 'javascriptEnabled')
    payload.sub!(/"platform":"(\w+)"/){|x| %{"platform":"#{$1.upcase}"} }
  end 
  request_without_rails_support_that_fixes_crappy_json(verb, url, headers, payload, redirects)
end