I am testing running selenium webdriver with phantomjs from Ruby on Rails. I am testing locally on my computer.
The following code runs fine within my test Ruby script when I run "ruby test.rb"
def google_title
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :phantomjs
driver.navigate.to "https://www.google.com"
page_title = driver.title
puts page_title
end
google_title
I have pretty much the same code in my application_controller.rb file:
def google_title
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :phantomjs
driver.navigate.to "https://www.google.com"
page_title = driver.title
render text: page_title
end
But when I run my app I get a "cannot load such file -- selenium-webdriver" error.
I have added this to my Gemfile and ran bundle install but get the same error.
gem 'selenium-webdriver', '~> 2.45'
When I run gem list --local it shows selenium is installed.
Any help would be appreciated.
Update:
I ran almost exactly the same code as above but with watir-webdriver and got the same results. The Ruby script ran fine by it's self but gave a "cannot load such file" error for watir-webdriver when I tried to run it from Rails.
I ran another test with nokogiri and it worked fine. Both by it's self and in Rails.
Update2:
It appears to be something I am doing and not my test environment. I just ran the same code on an online IDE and got the same type of error:
Update3:
Here is the full content of the application_controller.rb file when I run the test with watir-webdriver and headless. I get the same results. Maybe I am setting something wrong here?
class ApplicationController < ActionController::Base
def google_title
require 'watir-webdriver'
require 'headless'
headless = Headless.new
headless.start
b = Watir::Browser.start 'www.google.com'
page_title = b.title
b.close
headless.destroy
render text: page_title
end
end


