Archive for the ‘English’ Category
Testing websites in Google-Chrome using Cucumber
Howto install Chrome, Cucumber, Capybara and Selenium.
Afterwards we run a simple example test against the Chrome browser.
Install a fresh virtual machine with Ubuntu 11.10.
Make sure you install all the updates, this is needed for the latest Chrome version.
sudo apt-get update
sudo apt-get dist-upgrade
reboot
sudo apt-get install ruby
sudo apt-get install rubygems
sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
sudo apt-get install openjdk-6-jre
sudo gem install rubygems-update
sudo update_rubygems
sudo gem install rspec
sudo gem install cucumber (gives error on builder documentation, ignore)
sudo gem install capybara
install the latest version of Chrome
download the latest chromedriver
- extract chromedriver from zipfile
- sudo cp chromedriver /usr/bin
download latest selenium-server
- start the selenium-server “java -jar selenium-yourversion.jar”
download my example feature file Example.zip
- unzip my example.zip
- start cucumber from the Example directory
See my short screencast for how it should work out.
The whole process should take you about 40 minutes to a hour, depending on your computer and internet speeds.
Some cucumber basics combined with selenium
My idea is to create human readable test scripts to test a web-based application. These tests are then run automated against a browser.
First I installed Cucumber and then created some example files to demonstrate its usage with Selenium on my Ubuntu box.
Install ruby, cucumber and other extensions:
apt-get install ruby apt-get install rubygems1.8 apt-get install ruby1.8-dev apt-get install libxml2-dev libxslt1-dev
gem install gherkin gem install cucumber gem install webrat gem install rspec gem install selenium-client gem install selenium-webdriver
Then create a directory structure:
mkdir -p cucumber/features/ mkdir -p cucumber/features/step_definitions/ mkdir -p cucumber/features/support/
Create a file google.feature in the folder features containing:
Feature: Search Google Scenario: Search Google Given I have opened "http://www.google.com/" When I search for "Niels van Reijmersdal" Then I should see "My personal blog"
Create a file google_feature.rb in the folder step_definitions containing:
Given /^I have opened "([^"]*)"$/ do |url|
visit url
end
When /^I search for "([^"]*)"$/ do |search|
fill_in "q", :with => search
sleep 3
end
Then /^I should see "([^"]*)"$/ do |text|
response.should contain(text)
end
Create a file env.rb in the folder support containing:
require 'webrat/selenium' require 'webrat/core/matchers' require 'rspec' Webrat.configure do |config| config.mode = :selenium config.application_framework = :external config.selenium_server_address = '127.0.0.1' config.selenium_browser_startup_timeout = 60 end World do session = Webrat::Session.new session.extend(Webrat::Methods) session.extend(Webrat::Selenium::Methods) session.extend(Webrat::Selenium::Matchers) session end
Download the latest version of Selenium Server and run it:
java -jar selenium-server-standalone-2.8.0.jar
Start the cucumber from within the cucumber directory:
/var/lib/gems/1.8/bin/cucumber
This should start cucumber and run all its feature files, this should make the selenium server start firefox and execute the commands. The sleep command is pretty ugly, but i am just starting with this selenium, cucumber and ruby combination. When i figured out a good way to check if elements are present with this selenium interface i will update this howto. (Update: Its easier using Capybara, see this blog post for the same example.)
Next steps are to create a dedicated cucumber and selenium machine to keep the test running all the time.
Most stuff here I learned from this blog post (great post about using cucumber with webrat for webtesting). The selenium stuff was scattered around on the web. Also be sure to read the nicely written e-book “The secret ninja cucumber scrolls” for more info on cucumber, gherkin and automated testing. You should be able to read it within two-three hours.
Xfce shortcut key troubles
In Netbeans the default shortcut key to run tests for the current file is CTRL+F6. For some odd reason this wasn’t working on my recently installed Linux Mint Xfce operating system…?!?
At first i thought maybe its just broken in Netbeans. But now it seems that the window manager (xfwm4) of Xfce uses CTRL+F# to switch workspaces. After some searching I figured out howto disable this feature. Look for it under the shortcut settings of the window manager and not at the keyboard or workspaces settings. Doh!
Back to my Test-Driven Development training examples…

