2
votes

I am using webdriver-user-agent mentioned here – http://watirwebdriver.com/mobile-devices/
This is the code I am using when trying out this gem
Browser: FF/Chrome Ruby: 1.9.3 / Selenium :2.30.0 / Watir : 4.0.2

http_client = Selenium::WebDriver::Remote::Http::Default.new
http_client.timeout = HTTP_TIMEOUT
profile = Selenium::WebDriver::Firefox::Profile.new
device = ENV["DEVICE"]
orientation = ENV["ORIENTATION"]
driver = UserAgent.driver(:browser => :firefox, :agent =>device, :orientation=>orientation)
devices = UserAgent.resolution_for(device,orientation)
UserAgent.resize_inner_window(driver,devices[0],devices[1])
Watir::Browser.new driver

Now when the last statement is executed, i get the following error

(STEP) Launching FIREFOX (using web driver user agent)……
browser:
#

undefined method `to_sym’ for # (NoMethodError)
/Users/user/.rvm/gems/ruby-1.9.3-p194/gems/watir-4.0.2/lib/watir/loader.rb:42:in `load_driver_for’
/Users/user/.rvm/gems/ruby-1.9.3-p194/gems/watir-4.0.2/lib/watir/loader.rb:8:in `new’

Based on some investigation, problem is happening at highlighted line below as its trying to .to_sym on the selenium webdriver object.

def load_driver_for(browser)

if browser && browser.to_sym != :ie && Watir.driver == :classic
Watir.driver = :webdriver
end
Watir.load_driver
end

But if we add a line like given below, this gem is working as expected.

def load_driver_for(browser)

if “#{ENV["BROWSER"]}”.eql?(“chrome_useragent”)||”#{ENV["BROWSER"]}”.eql?(“firefox_useragent”)
Watir.driver = :webdriver
else
if browser && browser.to_sym != :ie && Watir.driver == :classic
Watir.driver = :webdriver
end
Watir.load_driver
end
end

since this is watir code outside of our framework, this is not the right way to do this, any suggestion on how to avoid this situation ?

1
Is this not the same as the bug you already logged - Issue 6?Justin Ko
yes it is, but after i read your bloglink, i suspected that there is a solution to my problem based on how we require watir/watir-webdriver, so posted here to see if i am missing anything, your answer helped!aragavan

1 Answers

2
votes

The problem is reproducible when you do:

require 'watir'
require 'webdriver-user-agent'
driver = Webdriver::UserAgent.driver(:browser => :chrome, :agent => :iphone, :orientation => :landscape)
browser = Watir::Browser.new driver
browser.goto 'tiffany.com'
browser.url.should == 'http://m.tiffany.com/International.aspx'

You can fix the issue by requiring watir-webdriver directly instead of through the watir metagem. Change the first line to:

require 'watir-webdriver'