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.
Related
So after upgrading the Ruby version used with my app from 2.5.5 to 2.6.3, simplecov 0.17.0 now hangs silently and permanently at the end of my test suite.
I'm running Ruby 2.6.3 and Rails 5.2.3.
As for what else may be relevant, I have capybara 3.26.0 running and I'm using RSpec.
One thing I tried is adding "use_merging false" to my SimpleCov.start block, as I saw that suggested out and about. No luck for me.
Here's an example of the output I get:
138 examples, 0 failures, 1 pending
Randomized with seed 29475
Then that's where it hangs.
Any help is greatly appreciated!
Edit: SimpleCov config:
SimpleCov.start :rails do
add_filter "/app/channels/"
add_filter "/app/jobs/"
add_filter "/app/mailers"
end
From https://github.com/colszowka/simplecov
If you're making a Rails application, SimpleCov comes with built-in configurations (see below for information on profiles) that will get you started with groups for your Controllers, Views, Models and Helpers. To use it, the first two lines of your test_helper should be like this:
require 'simplecov'
SimpleCov.start 'rails'
The documenation also states:
Load and launch SimpleCov at the very top of your test/test_helper.rb (or spec_helper.rb, rails_helper, cucumber env.rb, or whatever your preferred test framework uses):
require 'simplecov'
SimpleCov.start
If this does not help, please share your simplecov entry in your Gemfile and the test-, spec-, rails_helper.
I have Rails 4.2 app, using bundler, rvm.
Added capybara and selenium-webdriver to Gemfile, bundle install ok.
I wrote small class that use selenium for some purpose:
require 'capybara'
class GoogleSite
include Capybara::DSL
def initialize
Capybara.default_driver = :selenium
end
def find_all(param)
url = 'https://google.com'
visit url
end
end
GoogleSite.new.find_all({v: "4"})
When I am calling it from rails console i got error:
Capybara's selenium driver is unable to load selenium-webdriver,
please install the gem and add gem 'selenium-webdriver' to your
Gemfile if you are using bundler.
On line with "visit url"
When I call this script from IRB or by ruby file.rb, it's working fine but not from rails console when i include it in lib and call as a class.
I want to use capybara with poltergeist (rails controller will create sidekiq job that will call this class) but I am trying to debug with selenium (to see errors and correct form filling).
I've been trying to follow the official rails guide and have run into an issue. There seems to be a syntax error message on code that was scaffolded in a new project using:
rails generate scaffold Post name:string title:string content:text.
Simple enough, right? I'm just going through the first page of the official rubyonrails.org "Make a blog" tutorial. But when I go to http://localhost:3000/posts I get this issue.
The SyntaxError Message:
/projects/blog/app/controllers/posts_controller.rb:9: syntax error, unexpected ':', expecting '}'
format.json { render json: #posts }
^
On step 6.3 I'm supposed to be seeing a simple "Listing posts" page, with presumably no blog entries.
My posts_controller.rb file:
class PostsController < ApplicationController
# GET /posts
# GET /posts.json
def index
#posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: #posts }
end
end
...(continued. This was all generated via a scaffold.)
My setup:
The guide says:
This Guide is based on Rails 3.2. Some of the code shown here will not work in earlier versions of Rails.
My rails -v says:
Rails 3.2.8
rubyonrails.org says:
We recommend Ruby 1.9.3 for use with Rails. Rails 3.2 is the last one that supports Ruby 1.8. Ruby 1.8.6 and earlier are not supported, neither is version 1.9.1.
My ruby -v says:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.2.0]
I always get that SyntaxError message, even after trying different versions of Ruby (using rbenv). Here are the versions I've tried:
1.9.2-p290
1.9.2-p320
1.9.3-p194 (latest)
Workaround:
Changing format.json { render json: #post } to format.json { render :json => #post } fixes the issue.
My Question:
Why, with the latest version of Ruby and the latest version of Rails, would I get a SyntaxError when the versions are supposed to be compatible? At this point in the first page of the official tutorial, I haven't even written any ruby. These lines in my posts_controller.rb file were generated by the latest stable version of Rails and the syntax is outdated? Rails hasn't been updated to use Ruby syntax going back to version 1.9.2?
In your Gemfile specify the ruby version like so ruby "1.9.3" right under the sources. See if that fixes it.
Edit I was having that problem deploying to heroku and adding that to my Gemfile fixed the error. Apparently it was trying to use 1.8.7 instead of 1.9.3 even though the ruby version specified by heroku was 1.9.3
mind putting this "puts RUBY_VERSION" at the top of your posts_controller? I'm curious if the right version is getting picked up. When you start the Rails server it should output the version number to the console.
Rails is definitely 1.9.3 friendly. 1.9.3 doesn't break anything that I'm aware of and since Rails is 1.8 compatible it should work moving forward just fine.
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
I have installed Watir 1.7.1, Ruby 1.9.2, ci_reporter 1.6.4, test unit 2.2.0.
Since testunit donot come with Ruby 1.9.2, I installed the testunit seperately.
When I run the script, ci_reporter donot create 'test/reports' folder in the directory iam running the tests. When i execute the script, script runs fine but the folder is not created.
Does the folder 'test/reports' gets created by itself or the 'test/reports' folder should be as part of testunit.
Following is the simple test iam running, please look at the code snippet :
gem 'test-unit'
require 'test/unit/ui/console/testrunner.rb'
require 'ci/reporter/rake/test_unit_loader.rb'
require 'watir'
class My_Test < Test::Unit::TestCase
def test_me
browser = Watir::IE.start('http://www.google.com')
assert(browser.link(:text, 'About Google').exists?)
browser.close
end
end
Does ruby 1.9.2 support ci_reporter 1.6.4?
Can any one help me with an example as to how the reports would be created by ci_reporter and where the reports get stored?
Based on Tiffany's response and the link she gave, I think the answer to your question is 'NO. it is not supported at this time'
I'd also echo the recommendation to use 1.8.7 that's what I've been using for a while now and it is working good with watir.
I think most folks are still using ruby 1.8.7 with Watir. I'm still on 1.8.7, and I use ci_reporter with Watir every day without any problems.
Any chance you can try your code in a 1.8.7 environment? I just found this blog post that indicates that ci_reporter has not been updated to work with ruby 1.9.2: http://www.larkware.com/posts/fix-ci-reporter-for-test-unit-2-dot-0