I'm trying to use the Selenium Webdriver gem to write a test but am getting the following error.
"test.rb:4:in `': uninitialized constant Selenium (NameError)"
I can't seem to figure out why its giving me this error. I have pasted the code for the test below.
"require rubygems"
"require selenium-webdriver"
driver = Selenium::WebDriver.for :chrome
that is where it fails. The rest of the test is pretty page-specific js executions.
Your requires do nothing, you just wrote unused String literals, change it to:
require "rubygems"
require "selenium-webdriver"
Related
I am learning automation and have no prior programming knowledge. I am trying to learn Selenium with ruby: I am having issues with launching the firefox browser.What am i doing wrong?
My code is
require 'rubygems'
require 'selenium-webdriver'
System.setProperty("webdriver.gecko.driver","path of geckodriver.exe");
WebDriver = new FirefoxDriver();
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://facebook.com"
puts"facebook is loaded in FF browser"
I am getting the following error:
3:in '':uninitialized constant System (NameError)
Did you mean? SysytemExit
Using watir-webdriver, you can test your code while developing using IRB (interactive ruby).
But this does not seem to work when using the page-object gem.
When I run the ruby program, I can see my page-object calls are working.
This is not apparent from IRB. E.g. Here's what I type in IRB:
require 'page-object'
require 'watir-webdriver'
b = Watir::Browser.new :chrome
I then manually navigate to the page I want and go back to IRB:
b.table(:id => 'manage-groups-list').present?
IRB returns true. So, watir-webdriver knows the table control is present on the page. Can we do the same thing in page-object?
Continue coding in IRB:
class ManageGroupsPage
include PageObject
table(:groupsList, :id => 'manage-groups-list')
end
I then try to get the contents of the table from IRB. However, this returns an error:
irb(main):021:0> puts ManageGroupsPage.groupsList.to_s
NoMethodError: undefined method `groupsList' for ManageGroupsPage:Class
from (irb):21
from C:/Ruby193/bin/irb:12:in `<main>'
I am using page-object 1.0.3, watir-webdriver 0.6.11 and Ruby 1.9.3.
Looking at their basic usage docs, it seems like calling
table :groupsList, id: 'manage-groups-list'
generates an instance method rather than a class method. So you would need to call the generated method like so:
b = Watir::Browser.new :chrome
page = ManageGroupsPage.new(b) # build a new page object
page.groupsList # call the instance method
You can also use the 'pry' gem. Add to your env file, require 'pry' and then where ever you want the code to stop/inspect, add binding.pry
I'm trying to require hiredis in irb and it's already sending me an error:
irb(main):001:0> require "hiredis"
WARNING: could not load hiredis extension, using (slower) pure Ruby implementation.
=> true
irb(main):002:0>
Upon further investigation, I notice that it's crashing at this part of the code.
# hiredis-rb/lib/hiredis/connection.rb
module Hiredis
begin
require "hiredis/ext/connection"
Connection = Ext::Connection
rescue LoadError
warn "WARNING: could not load hiredis extension, using (slower) pure Ruby implementation."
require "hiredis/ruby/connection"
Connection = Ruby::Connection
end
end
So, I required the file hiredis/ext/connection and the error I get is the following error:
irb(main):001:0> require "hiredis/ext/connection"
LoadError: /home/***/projects/***/.gemset/extensions/x86_64-linux/2.1.0-static/hiredis-0.5.2/hiredis/ext/hiredis_ext.so:
undefined symbol: redisReaderFree -
/home/***/projects/***/.gemset/extensions/x86_64-linux/2.1.0-static/hiredis-0.5.2/hiredis/ext/hiredis_ext.so
from /home/***/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I'm using Ubuntu and latest stable version of Redis (2.8.18). How do I fix this? Thanks!
EDIT:
So after looking at the hiredis-rb page: https://github.com/redis/hiredis-rb, it says that I should do the following:
To use hiredis with redis-rb, you need to require
redis/connection/hiredis before creating a new connection.
So I did a require "redis/connection/hiredis" on irb and then require "hiredis" and everything worked fine, no more warnings.
But now the warnings don't happen at all anymore now. I assumed that I'd need to require "redis/connection/hiredis" everytime for it to work but now it just works. So I dunno why it's not warning me anymore now. I thought calling require "redis/connection/hiredis" during that irb session was only for that session, not all succeeding sessions.
I am trying to test a UI that has the ability to drag and drop. All im looking to do is to drag an element to another element on the page. The code is below.
it 'should drag and drop' do
draggable = #driver.find('//*[#id="2"]').first
droppable = #driver.find('//*[#id="dropmembers4"]').first
draggable.drag_to(droppable)
#driver.find('//div[contains(., "Dropped!")]').should_not be_nil
end
Currently im getting an error:
Failure/error: draggable = #driver.find('//*[#id="2"]').first
No method error: undefined method 'find' for nil:NilClass
Any help would be great.
Thanks
The #driver variable does not exist, that mean the initialization is not working. Here's the minimal initialization code:
$ [sudo] gem install selenium
$ selenium install
And the code for using it:
require 'selenium'
#driver = Selenium::WebDriver.for(:chrome)
And if you're using bundler to define dependencies, you should run:
$ bundle install
And then this code:
require 'rubygems'
require 'bundler/setup'
require 'selenium'
#driver = Selenium::WebDriver.for(:chrome)
I am experiencing issues when I am trying to run my .rb-file with the Ruby-command trying to access a gem. The gem i am trying to use is Ruby-Whois. I have an example script below that when I try to execute it through "ruby whois.rb" I get this error message:
./whois.rb:6: uninitialized constant Whois (NameError)
However, if I run the same script line by line in IRB I get the expected result. What may cause this?
Below is whois.rb
require "rubygems"
require "whois"
domain = "google.com"
c = Whois::Client.new
a = c.query(domain)
puts a
change the name of your file - there is ambiguity in require 'whois' and ruby is requireing your file instead of a gem. when you do it line by line in irb ruby knows what you exactly want to require, so everything works.