follow me icons

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