follow me icons

Monday, July 18, 2011

cucumber - undefined method `line' for nil:NilClass (NoMethodError)

This error occurs when I run my cucumber test using the tag:

e.g
/test>bundle exec cucumber features\regression\simple_test -t @test

undefined method `line' for nil:NilClass (NoMethodError)
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/formatter/filter_formatter.rb:64:in `examples'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/formatter/tag_count_formatter.rb:30:in `examples'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/listener/formatter_listener.rb:107:in `replay_step_or_examp
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/listener/formatter_listener.rb:41:in `scenario_outline'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/parser/parser.rb:46:in `__send__'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/parser/parser.rb:46:in `method_missing'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/lexer/i18n_lexer.rb:23:in `scan'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/lexer/i18n_lexer.rb:23:in `scan'
/test/vendor/ruby/1.8/gems/gherkin-2.3.6-x86-mingw32/lib/gherkin/parser/parser.rb:31:in `parse'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/feature_file.rb:35:in `parse'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime/features_loader.rb:28:in `load'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime/features_loader.rb:26:in `each'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime/features_loader.rb:26:in `load'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime/features_loader.rb:14:in `features'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime.rb:132:in `features'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/runtime.rb:45:in `run!'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/cli/main.rb:43:in `execute!'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/../lib/cucumber/cli/main.rb:20:in `execute'
/test/vendor/ruby/1.8/gems/cucumber-0.10.0/bin/cucumber:14
/test/vendor/ruby/1.8/bin/cucumber:19:in `load'
/test/vendor/ruby/1.8/bin/cucumber:19

It turns out that cucumber (0.10) is not able to handle an empty scenario outline.
e.g

@test
Scenario Outline: An Empty scenario outline example - Add Two Number
Given I have entered <num_1> into the calculator
And I press add
And I have entered <num_2> into the calculator
When I press add
Then the result <result> should be on the screen
Examples:
|num_1 | num_2 | result |

The reason I have an empty scenario outline is for a placeholder.

If you run the cucumber without using the tag (e.g bundle exec cucumber features\regression\simple_test), then cucumber will run just fine.

The fix is to just add examples into scenario outline or to comment out the scenarios.

Friday, March 18, 2011

SOAP request in Cucumber using Savon Ruby Gems

Here is how I use Savon for my project:

To install/configure Savon:
1. gem install savon
2. add "require 'savon'" in your env.rb files

soap_example.feature

Scenario: Example of sending a soap request using Savon Gems
Given the user creates a new wsdl client

When the user sends a "findGeocodedAddress" request
|street_name | street_type | street_number | street_suffix |
|Burrows Road| S | 20/2 | UnDefined |
Then the user should get a success response
And findGeocoded response should have "11" addresses


soap_example_steps.rb

Given /^the user creates a new wsdl client$/ do
@client = Savon::Client.new do
wsdl.document = "http://service.example.com?wsdl"
end
end

When /^the user sends a "([^\"]*)" request$/ do |request, table|
xml = find_geocoded_address_xml table.hashes[0]
@soap_response = @client.request :wsdl, request do |soap|
soap.body = xml.target!
end
end

#I am using Builder to generate my xml structure
def find_geocoded_address_xml address
xml = Builder::XmlMarkup.new(:indent => 2)

xml.credentials{
xml.token(TOKEN)
xml.password(AUTH_PASS)
}
xml.address{
xml.structuredAddress{
xml.street{
xml.streetName(address["street_name"])
xml.streetType(address["street_type"])
xml.streetSuffix(address["street_suffix"])
}
xml.streetNumber(address["street_number"])
xml.suburb(address["suburb"])
xml.state(address["state"])
xml.postcode(address["postcode"])
}
}
return xml
end

Then /^the user should get a success response$/ do
@soap_response.success?.should == true
@soap_response.soap_fault?.should == false
@soap_response.http_error?.should == false
end

Then /^findGeocoded response should have "([^\"]*)" addresses$/ do |num_address|
addresses = @soap_response.to_array[0][:find_geocoded_address_response][:addresses]
@num_address_result = num_address.to_i
if addresses.class == Array
addresses.count.should == @num_address_result
else
#returns as a hash that means only one result
@num_address_result.should == 1
end
end

Wednesday, March 9, 2011

Capybara-firebug

Early this week, I installed a new gem called capybara-firebug. This is a very useful gems. I have been wanting to enable firebug when running the test. Previously, I can pause my web test but I cannot inspect the web element as firebug is not enable. This capybara-firebug gems solve my problem and is very helpful to debug my web test.

For more information about capybara-firebug, please visit https://github.com/jfirebaugh/capybara-firebug
Extract from the readme files:
"
capybara-firebug provides a dead-simple way to run scenarios with Firebug enabled under the selenium driver.

1. Install the gem
2. require 'capybara/firebug' in env.rb
3. Tag a scenario with @firebug
4. Run it
"

Please note that Capybara-firebug requires capybara version 0.4.1.2 and cucumber 0.10.0.

Wednesday, March 2, 2011

Unable to obtain stable firefox connection in 60 seconds

I recently got this error message when running my cucumber test

"
unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)
"
I have just installed Ubuntu 10 on my machine and then trying to setup my cucumber test. When I try to run my firefox from console I receive this weird errors:

None of the authentication protocols specified are supported.
**
GLib-GIO:ERROR:/build/buildd/glib2.0-2.26.0/gio/gdbusconnection.c:
2270:initable_init: assertion failed: (connection->initialization_error == NULL)


Finally, I found that I log in as a root and for some reason you can't fireup firefox as a root and therefore selenium webdriver also fails to obtain stable firefox connection.

To fix the issue, I just exit as a root and rerun my cucumber test.

Another solution is because you are running an older version of selenium webdriver and the old version does not support firefox version > 4x. To fix the issue either upgrade your selenium webdriver version or downgrade your firefox to version 3.6x