Reputation: 1743
I am trying to get Watir to emulate a mobile environment and I followed the directions verbatim from the very helpful, http://watirwebdriver.com/mobile-devices/. Here's my code.
#!/usr/bin/ruby
require 'rubygems'
require 'watir-webdriver'
require "webdriver-user-agent"
require 'headless'
$headmode = 0
$screens = 0
headless = Headless.new if $headmode == 1
headless.start if $headmode == 1
driver = UserAgent.driver(:browser => :firefox, :agent => :iphone, :orientation => :landscape)
....... snip ......
....... snip ......
The exception being thrown is .....
/var/lib/gems/1.8/gems/webdriver-user-agent-0.0.5/lib/webdriver-user-agent.rb:39:in `agent_string_for': undefined method `downcase' for :iphone:Symbol (NoMethodError)
from /var/lib/gems/1.8/gems/webdriver-user-agent-0.0.5/lib/webdriver-user-agent.rb:11:in `driver'
from ./test_CAPI.rb:11
Not being a Ruby developer, or being proficient in WATIR (yet), I'm mystified by this error. Can anyone shed some light on this? Many thanks Janie
Upvotes: 2
Views: 613
Reputation: 46836
The webdriver-user-agent is complaining that the values you passed for :agent and :orientation cannot be downcased due to the method not existing.
I think there are two solutions:
Upgrade to Ruby 1.9.3. I am guessing like me, you ran the code using something like Ruby 1.8.7. The downcase() method for Symbols does not exist in 1.8.7, which gives you the error. So you need a later version of Ruby that does have the method (ex 1.9.3 based on http://www.ruby-doc.org/core-1.9.3/Symbol.html).
Pass in a string for the :agent and :orientation values (example below). It looks like it works for the one example (though I do not use this gem so cannot tell you if there are issues elsewhere).
driver = UserAgent.driver (:browser => :firefox, :agent => 'iphone', :orientation => 'landscape')
Upvotes: 6