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

Monday, February 21, 2011

How to install ansicon for cucumber to get coloured output on Windows

Last week, I have just upgraded my cucumber gem from 0.6.4 into 0.10.0 as the documentation says that the new gem from 0.7 onward should be able to parse the gherkin text 50-100 times faster.

However, after I upgraded to version 0.10.0, I get the following warning

*** WARNING: You must use ANSICON 1.31 or higher 
(http://adoxa.110mb.com/ansicon) to get coloured output on Windows


I actually like the win32console better than this as you can just put the win32console gem into your gemfile so you don't have to install ansicon separately.

Anyway, here are the steps on how to install ansicon.exe:

1. Download and unzip the file from https://github.com/adoxa/ansicon/downloads
2. open cmd and navigate to the unzipped folder
3. Navigate to x64 (if you have a 64 bit machine) otherwise navigate to x86
4. Type ansicon.exe -h and you will get the following:
D:\Data\ansicon\x86>ansicon.exe -h
ANSICON by Jason Hood .
Version 1.32 (22 December, 2010).  Freeware.
http://ansicon.adoxa.cjb.net/

Process ANSI escape sequences in Win32 console programs.

ansicon -i|I | -u|U
ansicon [-m[]] [-p | -e|E string | -t|T [file(s)] | program [args]]

  -i            install - add ANSICON to the AutoRun entry (implies -p)
  -u            uninstall - remove ANSICON from the AutoRun entry
  -I -U         use local machine instead of current user
  -m            use grey on black ("monochrome") or  as default color
  -p            hook into the parent process
  -e            echo string
  -E            echo string, don't append newline
  -t            display files ("-" for stdin), combined as a single stream
  -T            display files, name first, blank line before and after
  program       run the specified program
  nothing       run a new command processor, or display stdin if redirected

 is one or two hexadecimal digits; please use "COLOR /?" for details.
5. Execute 'ansicon.exe -i' to install and add ansicon to your Windows
6. Run your cucumber 0.10.0 test and you should 
get the coloured output result on Windows