follow me icons

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

Friday, February 18, 2011

Installing and configuring Gembundler for Windows

This is how I install gem bundler for my test automation suites using Windows. My test project structure is similar with the one from this cucumber setup page

1. Go to your top level directory above the 'features' directory
2. Install gem bundler from the command prompt. Gem install bundler

D:\Work\ui>gem install bundler
Temporarily enhancing PATH to include DevKit...
Successfully installed bundler-1.0.10
1 gem installed
Installing ri documentation for bundler-1.0.10...
Installing RDoc documentation for bundler-1.0.10...

D:\Work\ui>

3. Create a gemfile in your current directory
Here is what my 'gemfile' looks like

source "http://rubygems.org/"

group :test do
gem 'cucumber', '0.6.4'
gem 'rake', '0.8.7'
gem 'rspec', '1.2.8'
gem 'capybara', '0.4.0'
gem 'gizmo', '0.1.1'
gem 'win32-process', :platforms => [:mswin, :mingw]
gem 'win32console', :platforms => [:mswin, :mingw]
gem 'ruby-debug', '0.10.3' :platforms => [:ruby]
end

4. execute "bundle install --path vendor/bundle"

D:\Work\ui>bundle install --path vendor/bundle
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using activesupport (2.3.11)
Using builder (3.0.0)
Using celerity (0.8.8)
Using culerity (0.2.15)
Using mime-types (1.16)
Using nokogiri (1.4.4.1)
Using rack (1.2.1)
Using rack-test (0.5.7)
Using ffi (0.6.3)
Using childprocess (0.1.7)
Using json_pure (1.5.1)
Using rubyzip (0.9.4)
Using selenium-webdriver (0.1.3)
Using xpath (0.1.3)
Using capybara (0.4.0)
Using diff-lcs (1.1.2)
Using polyglot (0.3.1)
Using term-ansicolor (1.0.5)
Using treetop (1.4.9)
Using cucumber (0.6.4)
Using tilt (1.2.2)
Using gizmo (0.1.1)
Using rspec (1.2.8)
Installing win32-api (1.4.8) Temporarily enhancing PATH to include DevKit...

Installing windows-api (0.4.0)
Installing windows-pr (1.1.3)
Installing win32-process (0.6.5)
Installing win32console (1.3.0)
Using bundler (1.0.10)
Your bundle is complete! It was installed into ./vendor/bundle

5. Execute 'bundle exec cucumber features\whatever.feature' files

After installing gem bundler, you would need to run it using 'bundle exec' command. This ensure that cucumber will use the local gem file that you install under the vendor/bundler directories.

How to configure gemfile for windows platform

I use gem bundler for my test and in the past I only run it on Mac and therefore I didn't have to configure it to run in Windows. However, now I need to be able to run gem bundler in Windows, Ubuntu and Mac. This is because there are some gems that I specifically need to install only for Windows.

To configure your gemfile for windows platform, simply use the following syntax in your gemfile:


### windows specific gems ###
gem 'win32-process', :platforms => [:mswin, :mingw]
gem 'win32console', :platforms => [:mswin, :mingw]


or


### windows specific gems ###
platforms :mswin, :mingw do
gem 'win32console', '1.3.0'
gem 'wind32-process'
end


The documentation in gembundler.com says that mswin is for Windows but when I try just using "platform :mswin", it does not seem to work on my machine. That's why I add the "platform :mswin, :mingw".

Tuesday, February 8, 2011

Refresh Issue in Gizmo

I have been forced to use the 'sleep' method to wait for my page to load before I can check elements on the page as a temporary solution to my problem. The tests that I have been running somehow cannot get the element that I wanted. If I use the sleep method and wait for 1 - 2 seconds, then the test will be able to find that element. This is not an ideal solution. The automation test should be able to wait automatically until it can find the element on the page and we should not specify the time to wait.

I am currently using Gizmo, a page model testing framework, to dry up my testing assertion.


on_page_with :seo do |page|
page.seo_result_lists.should =~ /#{title}.*/
end


And inside the seo page I have the following code:


def seo_result_lists
@document.css("#navigation_listings").inner_text
end


The code above turns out to not give me the latest html content. The reason is because Gizmo is using Nokogiri to get the HTML content. When the page is initialized it will grab whatever html content it is currently loading. That is why my "@document.css("#navigation_listings").inner_text" returns nill instead of the text that I want.

One solution is to always 'Refresh' the page by assigning @document with the latest html content again "@document = Nokogiri::HTML(body)". However, this is not ideal because you have to refresh every time you want to get the value.

Another solution is to just not use the @document variable but to just use the capybara find method which will automatically wait until it finds the element to appear on the page. I eventually use this Capybara 'find' method over the @document.

After

def seo_result_lists
find(:css,"#navigation_listings").text
end