"NameError: uninitialized constant UserAgent" when using Watir - ruby

I'm new to ruby, I seem to have successfully installed watir-webdriver and webdriver-user-agent gems, but when I was trying to follow the instructions here I've stumbled. How to proceed?
>> require 'watir-webdriver'
=> true
>> require 'webdriver-user-agent'
=> true
>> driver = UserAgent.driver(:browser => :chrome, :agent => :iphone, :orientation => :landscape)
NameError: uninitialized constant UserAgent
from (irb):3
from /usr/bin/irb:12:in `<main>'

Try using Webdriver::UserAgent

Related

Error while creating and instance of IE

Hi all while I try to create an instance of IE I am facing the following error
my system configurations
Windows 7,64 bit
NameError: uninitialized constant Watir::IE
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'watir'
=> true
irb(main):003:0> ie=Watir::IE.new
NameError: uninitialized constant Watir::IE
from (irb):3
from D:/Ruby_1.8.7/lib/ruby/site_ruby/1.8/rubygems/specification.rb:630
irb(main):004:0>
To launch a browser in watir, you shoul use :
b = Watir::Browser.new :ie
# or :ff or :chrome or :opera ...
Note that for Internet explorer, you should download IEDriverServer.exe and add it to your path.

Unable to open excel with Roo or Spreadsheet Gems

When I try this with roo gem:
irb(main):001:0> require 'roo'
=> true
irb(main):002:0> oo = Excel.new("C:/Users/Abash/Desktop/test1.xls")
**NameError: uninitialized constant Excel** from (irb):2
from C:/Ruby193/bin/irb:12:in `<main>'
When I try this with spreadsheet gem:
irb(main):001:0> require 'spreadsheet'
=> true
irb(main):002:0>Spreadsheet.client_encoding = 'UTF-8'
=> "UTF-8"
irb(main):003:0> book = Spreadsheet.open 'C:/Users/Abash/Desktop/test1.xls'
**Errno::EACCES: Permission denied** - C:/Users/Abash/Desktop/test1.xls
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.8.2/lib/spreadsheet.rb:69:in `initialize'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.8.2/lib/spreadsheet.rb:69:in `open'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/spreadsheet-0.8.2/lib/spreadsheet.rb:69:in `open'
from (irb):3
from C:/Ruby193/bin/irb:12:in `<main>'
Can somebody show me a work around for these errors?
I believe you are using ruby 1.9 or above version. In such a case,you need to specify the gem while creating a new instance.
require 'roo'
s =Roo::Excel.new("myspreadsheet.xls")
s =Roo::Excelx.new("myspreadsheet.xlsx")

Can't create MongoClient.new

I don't know what the deal is with this. Everything works fine until i try to create a new MongoClient
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mongo'
=> true
irb(main):003:0> include Mongo
=> Object
irb(main):004:0> client = MongoClient.new('127.0.0.1', 27017)
NameError: uninitialized constant MongoClient
from (irb):4
from :0
irb(main):005:0>
You are using an older version (1.5.2) of the mongo gem instead of the most current one (1.8.0). That days the connection has been made by
conn = Mongo::Connection.new
Find out more in the documentation of version 1.5.2

undefined method for 'downcase'. (WATIR/Ruby related. webdriver-user-agent)

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
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')

S3 Obfuscated const_missing_from_s3_library error

I'm using the typical Mac/Ruby 1.9.3p125
irb>
require 'aws/s3'
AWS::S3::Base.establish_connection!(:access_key_id => 'AccessKey',:secret_access_key => 'SecretKey' )
Service.buckets
(Same error with Bucket.find or almost anything!)
Gives me:
NameError: uninitialized constant Service
from ~/.rvm/gems/ruby-1.9.3-p125/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206
:in `const_missing_from_s3_library'
from (irb):23
from ~/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `<main>'
I'm following documentation almost to spec but I'm so confused as to why this is happening?
You need to either include AWS::S3 in your class or do AWS::S3.Service.
Here's some code samples:
require 'aws/s3'
class MyClass
include AWS::S3
AWS::S3::Base.establish_connection!(:access_key_id => 'AccessKey',:secret_access_key => 'SecretKey' )
Service.buckets
end
or
require 'aws/s3'
class MyClass
AWS::S3::Base.establish_connection!(:access_key_id => 'AccessKey',:secret_access_key => 'SecretKey' )
AWS::S3::Service.buckets
end

Resources