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
Related
I'm using Capybara, Cucumber, and Selenium-Webdriver for basic web testing. If a test fails, I want to capture the failure message and send it to a separate log file.
Cucumber offers hooks to catch the failure message after the scenario fails (from their wiki):
After do |scenario|
if scenario.failed?
subject = "[Project X] #{scenario.exception.message}"
send_failure_email(subject)
end
end
However, when I implement this in my features/support/support.rb file, I get a no method error:
undefined method `exception' for #<Cucumber::RunningTestCase::Scenario:0x007fc7b4380968>
Is this error a result of my setup, or is this a bug specific to Cucumber 2.0?
Here is my code for features/support/support.rb:
require 'capybara/cucumber'
Capybara.default_driver = :selenium
After do |scenario|
if scenario.failed?
puts scenario.exception.message
end
end
Here is my code for features/step_definitions/step_definition.rb:
Given(/^I am on the Google homepage$/) do
visit 'http://www.google.com'
end
Then(/^I will search for "(.*?)"$/) do |searchText|
fill_in 'lst-ib', :with => searchText
end
Then(/^I should see "(.*?)"$/) do |expectedText|
page.should have_content(expectedText)
end
Then(/^I will click the Product link$/) do
click_link('Product')
end
Here is my code for features/findGameSparks.feature:
Feature: Find the GameSparks Website
Scenario: Search for the website
Given I am on the Google homepage
Then I will search for "GameSparks"
Then I should see "A NON-EXISTENT STRING CAUSING TEST FAILURE!!!!"
Then I will click the Product link
Here are the version numbers for everything I'm using:
OSX 10.10.1
ruby 2.2.1p85
rvm 1.26.11
gem 2.4.6
cucumber 2.0.0
cucumber-core 1.1.3
capybara 2.4.4
selenium-webdriver 2.45.0
This bug is fixed in this commit on April 1: https://github.com/cucumber/cucumber/commit/e92917c8f10a4907dedf26d77665116b69f3e3b9
The most recent release of Cucumber is 2.0.0, released March 27, so it seems the fix hasn't been released yet.
You can point to the github repo in your Gemfile to get the latest available code:
gem 'cucumber', git: 'https://github.com/cucumber/cucumber.git'
Note however that running "prerelease" code like this can lead to other problems, for example if a committer to cucumber messes up the master branch.
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 do you need the full name for mechanize as so:
#!/usr/bin/ruby -w
require 'rubygems'
require 'pp'
require 'yaml'
require "mechanize"
yml = YAML.load_file 'login.yml'
user = yml["user"]
pword = yml["pword"]
a = WWW::Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
a.get('http://google.com/') do |page|
search_result = page.form_with(:name => 'f') do |search|
search.q = 'Hello world'
end.submit
search_result.links.each do |link|
puts link.text
end
end
when the mechanize example doesn't do that? This is asked on top of a previous question. Code only worked after reading the previous question on this exact topic and adding the full class(?) name. I've seem somewhat similar in Java, but only when it's ambiguous. Here, there's nothing ambigious, there's only the one Mechanize.
Pardon, the actual previous question completely contradicts the above link. The previous question I was referencing is here. To reiterate, two different questions, two different answers. Maybe the API or idiom changed.
What version of Mechanize are you using? Try gem list mechanize.
Using Ruby 1.8.7-p357, 1.9.2-p290, and 1.9.3-p0 and Mechanize 2.1 I am able to instantiate an instance. For instance:
1.8.7 :001 > require 'mechanize'
true
1.8.7 :002 > agent = Mechanize.new
#<Mechanize:0x101baacf0
[...]
and:
1.9.3p0 :001 > require 'mechanize'
true
1.9.3p0 :002 > agent = Mechanize.new
#<Mechanize:0x102988610
[...]
I suspect you are using Mac OS, because you are accessing Ruby at /usr/bin. Ruby is not installed by default on Windows or Linux and wouldn't be at that path normally.
Apple's version of Ruby doesn't include Mechanize, so you added it at some point. Because Apple didn't install it it should be benign to update, so do:
sudo gem update mechanize
Apple does use Ruby for apps on Mac OS, so you have to be aware of that when updating their pre-installed gems.
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?
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