How to use Capybara for IE8 in pure Ruby (without Rails)? - ruby

I've been using the following code to test run using Capybara with IE8 in pure Ruby, i.e. NOT a rails app but every time I run the script IE8 pops up but then Firefox pops up and the tests run through Firefox leaving IE8 sitting in the background:
$:.unshift(File.dirname(__FILE__) + '/../../lib')
begin require 'rspec/expectations'; rescue LoadError; end
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
Capybara.run_server = false
Capybara.app_host = 'http://www.google.com'
require 'selenium-webdriver'
Selenium::WebDriver.for :internet_explorer
Capybara.default_driver = :selenium
require 'cukesalad'
begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end

This isn't too old maybe you can find some useful information from it:
Run Capybara & Cucumber Features In Internet Explorer On Remote Windows

Related

Can't run ruby automation file with cucumber - cannot load such file -- capybara (LoadError)

When I run cucumber, I get this error
cannot load such file -- capybara (LoadError)
According to this answer that's because i don't have poltergeist installed.
And if I run gem install poltergeist, I get
ERROR: While executing gem ... (ArgumentError)
wrong number of arguments (given 1, expected 0)
If I run gem list capybara, I just get
* LOCAL GEMS *
For last, this is what part of my env.rb file looks like
Learn more or give us feedback
require 'selenium-webdriver'
require 'capybara'
require 'capybara/poltergeist'
require 'capybara/cucumber'
$browser = ENV['browser'] ||:chrome
$browser = $browser.to_sym
$driver = ENV['driver'] || :selenium
$driver = $driver.to_sym
puts "Driver: #{$driver}"
puts "Browser: #{$browser}"
# For browser Firefox, geckodriver is required: https://github.com/mozilla/geckodriver/releases
# echo $PATH
# cd into geckodriver directory (probably Downloads) and extract from zip/tar
# mv geckodriver /usr/local/bin/ (or whatever your $PATH is)
# Run Firefox with:
# cucumber /dir/some.feature driver=selenium browser=firefox
Capybara.default_driver = $driver
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => $browser,)
end
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {js_errors: false, phantomjs_options: ['--ssl-protocol=auto']})
$platform = 'poltergeist'
end
Any help will be appreciated
You don’t want or need Poltergeist anymore, it’s obsolete. Instead add capybara to your Gemfile, or if not using a Gemfile run gem install capybara. Also you should be doing require ‘capybara/dsl‘ instead of ‘require ‘capybara’`
See : https://github.com/teamcapybara/capybara/blob/master/README.md#setup

Capybara/Selenium - NS_ERROR_MALFORMED_URI for app on http://localhost

I'm trying to set up RSpec, Capybara & Selenium to test a PHP application running on the traditional localhost:80. Whenever I run the suite, Selenium fails and complains about a malformed URI.
Here's my spec_helper.rb.
require 'bundler/setup'
require 'rspec'
require 'capybara/rspec'
Capybara.server_port = 80
Capybara.app_host = 'http://localhost'
Capybara.run_server = false
Capybara.default_driver = :selenium
And here's my only spec:
require File.dirname(__FILE__) + '/../spec_helper'
describe "visting the website", :type => :request do
it "should display an html page" do
visit ( '/' )
page.should have_selector( 'html' )
end
end
But it bails. What am I missing?
Failures:
1) visting the website should display an html page
Failure/Error: visit ( '/' )
Selenium::WebDriver::Error::UnknownError:
Component returned failure code: 0x804b000a (NS_ERROR_MALFORMED_URI) [nsIIOService.newURI]
# ./spec/requests/sign_in_spec.rb:6:in `block (2 levels) in <top (required)>'
My URI doesn't look malformed to me... visit works if I pass in 'http://localhost' but that's not ideal.
Here's my Gemfile for good measure
gem 'rspec'
gem 'capybara', :git => 'https://github.com/jnicklas/capybara.git'
gem 'launchy'
gem 'ruby-debug19'
Thanks for any help.
#andrykonchin was right - switching back to stable worked
You need install bundler if it is not install
gem install bundler
Then you need to create a file called gemfile in the root directory (For my simple example I am using just capybara and no rspec)
source "http://rubygems.org"
gem "capybara" , "1.1.3"
Create a basic ruby file as follows
require 'bundler/setup'
require 'capybara/dsl'
Capybara.server_port = 80
Capybara.app_host = 'http://google.com'
Capybara.run_server = false
Capybara.default_driver = :selenium
class Browser
include Capybara::DSL
end
w = Browser.new
w.visit("/")
Use the command
bundle install
Now you will be using the stable version of Capybara
For more information on bundler look at http://gembundler.com/

Why does this not work on IE9 but works on Firefox?

I am trying to run webdriver tests on IE. My script works on Firefox but not on IE9. I am using selenium-webdriver version 2.5.0 with ruby 1.8.7 patch level 352
Here is my ruby script:
require 'rubygems'
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :ie
driver.navigate.to "http://www.gapinc.com/"
element = driver.find_element(:name, 'search')
element.send_keys 'Employees'
element.submit
puts driver.title
driver.quit
On IE9, I get Unable to find element with name == search (Selenium::WebDriver::Error::NoSuchElementError) and it passes on Firefox
It may be sync issue. Did you try using ImplicitlyWait or WebDriverWait?

Use Watir in Shoes (ruby)

I'm trying to do an application in ruby. I want to collect information from the user using some UI interface. Then use this info in my script to fill some form on a web page.
I use Shoes as UI
I use Watir as Browser "manager"
Here a simple sample of what i'm trying to do
Shoes.setup do
gem 'watir'
end
require 'watir'
Shoes.app do
stack do
edit_line do |e|
#url = e.text
end
button("Test"){
browser = Watir::Browser.new
browser.goto #url
#Do some stuff
}
end
end
But then When the application start it's trying to installing watir and freeze because of error:
http://screencast.com/t/XWmeMmPQEBc
The error says that rake requires rubygems >= 1.3.2
You either need to upgrade rubygems or downgrade rake to a version compatible with your current rubygems.
Edit: or specifiy a version of watir that will run with an older rubygems & rake
Shoes has this problem with many native gems, i advise you to try this with green shoes
['rubygems','green_shoes','watir'].each(&method(:require))
Shoes.app do
stack do
Watir::Browser.default = 'ie'
browser = Watir::Browser.new
browser.goto 'http://bit.ly/watir-example'
browser.text_field(:name => 'entry.0.single').set 'Watir'
browser.text_field(:name => 'entry.1.single').set "I come here from Australia. \n The weather is great here."
browser.radio(:value => 'Watir').set
browser.button(:name => 'submit').click
end
end

How to use Capybara in pure Ruby (without Rails)?

I'm trying to get Capybara running in a simple Ruby script -- i.e. without/outside of Rails. Here's the script:
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
include Capybara
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.google.com'
visit('/')
The problem is that when I run this I get this error:
NameError: uninitialized constant Capybara::Session
at top level in dsl.rb at line 52
method gem_original_require in custom_require.rb at line 36
method require in custom_require.rb at line 36
at top level in capybara_test.rb at line 3
method gem_original_require in custom_require.rb at line 31
method require in custom_require.rb at line 31
at top level in capybara_test.rb at line
What am I doing wrong?
Some more info:
Mac OS X 10.5
ruby 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0]
capybara (0.3.9)
Thanks!
Neal
Note: Per the comment from jnicklas I tried this, which matches the new README more closely:
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
Capybara.default_driver = :selenium
Capybara.app_host = 'http://www.google.com'
module MyCapybaraTest
include Capybara
def test_google
visit('/')
end
end
Unfortunately, I'm still seeing the same error:
NameError: uninitialized constant Capybara::Session
Thoughts?
Thanks!
Here's something that seems to work for me:
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.google.com'
module MyCapybaraTest
class Test
include Capybara::DSL
def test_google
visit('/')
end
end
end
t = MyCapybaraTest::Test.new
t.test_google
It goes to show that even incorrect documentation lives forever. The Capybara README used to recommend to include Capybara in the global namespace, this is a really bad idea, and messes up any number of random things. You should include Capybara in your own module or class and use that instead.
Check out the README for current best practices.
Please check this CapybaraRspec101 example and fork it.
It's a small example for acceptance tests on http://www.hi5.com using from scratch:
Capybara
Rspec
Selenium-webdriver
All instructions are in the repo

Resources