Cannot create firefox browser with watir-webdriver
Asked Answered
N

2

0

I have firefox 20 which works with my version of watir-webdriver. I use the following code which can open any browser or a headless phantomjs browser. Chrome and phantom work, but firefox throws an exception.

Why? How do I fix this ?

require 'rubygems'
require 'watir-webdriver'
require 'phantomjs'

def get_browser(browser_name)
  browser = nil
  if browser_name != nil    
    puts "\n#{browser_name} created\n"  
    browser = Watir::Browser.new browser_name.to_sym
  else
    puts "creating phantom browser !"
    browser = Watir::Browser.new :phantomjs
    puts "\nphantom created\n"
  end
  return browser
end

browser_name = ARGV[0]
browser = get_browser(browser_name)
puts "\n\n"

browser.close

Exception-

C:/code/ruby/lib/ruby/gems/1.8/gems/json_pure-1.4.3/lib/json/pure/generator.rb:393:in `to_json': undefined method `ascii_only?' for {}:Hash (NoMethodError)
        from C:/code/ruby/lib/ruby/gems/1.8/gems/multi_json-1.3.7/lib/multi_json/adapters/json_common.rb:11:in `dump'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/multi_json-1.3.7/lib/multi_json.rb:115:in `dump'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/json_helper.rb:23:in `json_dump'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/profile.rb:254:in `write_prefs'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/profile.rb:253:in `each'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/profile.rb:253:in `write_prefs'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/profile.rb:252:in `open'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/profile.rb:252:in `write_prefs'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/profile.rb:232:in `update_user_prefs_in'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/profile.rb:79:in `layout_on_disk'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/launcher.rb:58:in `create_profile'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/launcher.rb:34:in `launch'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/driver.rb:31:in `new'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/common/driver.rb:31:in `for'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver.rb:67:in `for'
        from C:/code/ruby/lib/ruby/gems/1.8/gems/watir-webdriver-0.6.2/lib/watir-webdriver/browser.rb:46:in `initialize'
        from watir-browser.rb:9:in `new'
        from watir-browser.rb:9:in `get_browser'
        from watir-browser.rb:19
Nickeliferous answered 4/4, 2015 at 0:4 Comment(0)
T
1

you code is working for me without issue.

$ ruby test.rb
creating phantom browser !
phantom created

$ ruby test.rb firefox
firefox created

$ ruby test.rb chrome
chrome created

$ gem list | grep webdriver
selenium-webdriver (2.45.0, 2.44.0)
watir-webdriver (0.7.0, 0.6.11)

Firefox comes with selenium-webdriver, you probably just need to update your gem(s)

Tract answered 4/4, 2015 at 3:57 Comment(2)
selenium-webdriver (2.33.0), watir-webdriver (0.6.2). Can't really update them due to "constraints". btw, Carl, what is your preferred language and toolkit for QA automation testing ?Nickeliferous
@Nickeliferous I'm a fan of Cucumber with watir-webdriver and obviously Ruby (and I don't even use Cucumber the way it was intended)Tract
P
0

Ruby 1.8, Firefox 20, Watir 0.6.2 all look about 2ish years out of date. json_pure-1.4.3 however is 5 years old - https://rubygems.org/gems/json_pure/versions

Try updating that one.

Prostrate answered 4/4, 2015 at 18:16 Comment(2)
Yes, my gems are very old. I cannot update them due to "constraints". If not for them, I would be using the latest gems and browsers. Hoping for some magical workaround or monkey patching.Nickeliferous
Yeah, you're going to end up with a bunch of issues with open source projects if you don't have control over versioning. I suspect that multi_json is expecting something different from json_pure. if you can figure it out what that is, exactly, you could monkey patch, but you might just have to chalk this one up as not possible within the limitations you have.Prostrate

© 2022 - 2024 — McMap. All rights reserved.