Archive

Archive for the ‘selenium’ Category

Cucumber: Passing Test Data as Table from Scenario

January 20, 2016 Leave a comment

While we can pass test data as table from the feature file through Scenario Outline:

Scenario Outline: User updates user information
 Given I login to application
 And I go to user profile page
 And I enter "<gender>" into field of "gender_element";
 And I enter "<age>" into field of "age_element";
 And I enter "<location>" into field of "location_element";
 Then I verify user updates are saved
Examples:
 | gender | age | location |
 | Female | 20 | Singapore |

Here’s another option to pass your data in table format through your step definition.

Scenario: User updates user information
 Given I login to application
 And I go to user profile page
 When I update user information with options:
  | Gender | Female |
  | Age | 20 |
  | Location | Singapore |
 Then I verify user updates are saved

#Step Definitions File

#step definition to populate textfields
Then /^I enter "(.*)" into field of "(.*)"$/ do |value, field|
 textfield(I18n.translate!(field)).click
 textfield(I18n.translate!(field)).send_keys value
end

#step definition that accepts test data from the feature file as table
When /^I update user information(?: with options:)?$/ do |table|

 options = table.rows_hash
 step %Q[I enter "#{options['Gender']}" into field of "gender_element"]
 step %Q[I enter "#{options['Age']}" into field of "age_element"]
 step %Q[I enter "#{options['Location']}" into field of "location_element"]
 step %Q[I press button labelled "bt_address_suggestion_use_this"] 

#step definition that accepts test data from the feature file as table with default value
When /^I update user information(?: with options:)?$/ do |table|
 default_value = {
 'Age' = "18",
 'Location' = "United States"
 }
 options = default_value.merge(table.rows_hash)
 step %Q[I enter "#{options['Gender']}" into field of "gender_element"]
 step %Q[I enter "#{options['Age']}" into field of "age_element"]
 step %Q[I enter "#{options['Location']}" into field of "location_element"]
 step %Q[I press button labelled "bt_address_suggestion_use_this"]
Categories: cucumber, ruby, selenium

Cucumber: Read from File

November 1, 2012 1 comment

As your automated testing mature, you don’t want to limit users hard coding their application under test or browser driver all in the ENVironment file(env.rb). You can customized your environment by creating a configuration file where you can define variables like applications URL, timeout, database configurations and the like.

From the basic folder structure discussed in Automated Testing with Cucumber + Capybara post, add two more files:

config > environments.yml
support > custom_config.rb
where:

environments.yml – contains all the environment variables that you can use


google:
 app_host: http://www.google.com

bing:
 app_host: http://www.bing.com

custom_config.rb – ruby code where you configure your code to read from a specific file


require "erb"

module CustomConfig
 unless defined? @@env_config
 puts "loading environments.yml..."
 env = (ENV['ENVIRONMENT'] && ENV['ENVIRONMENT'].to_sym) || :google
 environments = YAML.load(ERB.new(File.read(File.expand_path('../../../config/environments.yml', __FILE__))).result)
 @@env_config = environments[env.to_s]
 raise "No config found for environment: #{env}" unless @@env_config
 end

def env_config
 @@env_config
 end

end

World(CustomConfig)

Your base folder should look like these by now:

Revised Base Folder

Then edit your env.rb by adding the following lines to your environment file.

require File.expand_path(‘../custom_config’, __FILE__)
include CustomConfig

Also update Capybara.app_host definition to look up to @@env_config. Your env.rb file should be edited to something like this:

env.rb


require 'capybara'
require 'capybara/cucumber'
require File.expand_path('../custom_config', __FILE__)
include CustomConfig

Capybara.default_driver = :selenium
Capybara.app_host = env_config['app_host']
Capybara.default_wait_time = 20

World(Capybara)

Notice in line #07 of your env.rb you are basically pointing app host to whatever environment you set in your custom_config.rbenv variable, (see line #06) for this example :google

From here on you should still be able to run your simple_search.feature file without error, the only difference is your code reads now from a specific file – environments.yml, through custom_config.rb.

Improve Writing your Cukes

November 1, 2012 Leave a comment

Based from the simple_search.feature that we have in Automated Testing with Cucumber + Capybara, we don’t want to limit users by writing element locators like id, css or xpaths, hardcoding search strings and validations in our Cucumber scenarios:

Simple search scenario


Scenario: A simple google search scenario
Given I am on the main google search
When I fill in "q" with "Cucumber test"
And I click "gbqfb" button
And I click on the first result
Then I should see "Cucumber lets software development teams describe how software should behave in plain text."

We can improve this 5-liner scenario by creating new step definition that accepts variable and reusing the previous step definitions in the new step.

Better search scenario


Scenario: The better way to do google search
Given I am on the main google search
When I search for "Cucumber test"
Then I verify first search result have "Cucumber lets software development teams describe how software should behave in plain text."

In order to make this new scenario running, we need to define the new step definitions:


Given /^I search for "([^\"]*)"$/ do |query|
 step %{I fill in "q" with "#{query}"}
 step %{I click "gbqfb" button}
end

Then /^I verify first search result have "([^\"]*)"$/ do |text|
 step %{I click on the first result}
 step %{I should see "#{text}"}
end

But wait, there’s even a better approach to present this scenario where we will use one of the Gherkin keyword “Scenario Outline.” Outline allows us to parameterized our test data by passing it to Examples.

Best search scenario

Scenario Outline: The best way to do google search
 Given I am on the main google search
 When I search for "<String>"
 Then I verify first search result have "<Search criteria>"

Examples:
 | String         | Search criteria   |
 | Cucumber tests | Cucumber          |
 | Selenium       | What is Selenium? |

Hope you had a great time, just like me. Happy Cuking!

Categories: cucumber, selenium Tags: , ,

Automated Testing with Cucumber + Capybara

October 29, 2012 10 comments

In this post we will introduce another gem called Capybara.

Capybara is an acceptance testing framework with a higher level API and support for multiple backends, supports Selenium and runs in different browsers.

Others may ask, “Why would I use capybara if selenium could also drive the browser the way I want it?”  Well, one advantage I appreciate is Capybara’s higher-level API compared to selenium.

Let’s take for example a simple scenario of typing strings to an input textbox:

Selenium-webdriver snippet


require 'selenium-webdriver'

element = driver.find_element :name => "q"
element.send_keys "Cucumber tests"

Capybara snippet

require 'capybara'

fill_in "q", "Cucumber tests"

You can obviously see from this example that Capybara enforces easier writing scripts ability. For a complete documentation on Capybara you can check this link from Github which I found very helpful.

After installation setup discussed in my previous post Introduction to Cucumber, you need to have the following folder structure and files:

I. Base Folder

Base Folder Structure

where:

features – folder to host all your feature files

step_definitions – folder to host all your step definition Ruby files

support – folder to host your configuration files (env.rb)

Gemfile – defines the top-level gems to be used in your project

II. Features

– describes the features that a user will be able to use in the program

Sample: simple_search.feature


Feature: As a user I should be able to perform simple google search

Scenario: A simple google search scenario
 Given I am on the main google search
 When I fill in "q" with "Cucumber test"
 And I click "gbqfb" button
 And I click on the first result
 Then I should see "Cucumber lets software development teams describe how software should behave in plain text."

III. Step Definition

– describes the actions that user will do for each step.

Sample: search_step.rb

Given /^I am on the main google search$/ do
 visit ('/')
end

When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
 fill_in(field, :with => value)
end

Then /^I click "([^"]*)" button$/ do |button|
 click_button(button)
end

Then /^I click on the first result$/ do
 find(:xpath, "//html/body/div[3]/div[2]/div/div[5]/div[2]/div[2]/div/div[2]/div/ol/li/div/h3/a").click
end

Then /^I should see "([^"]*)"$/ do |text|
 page.should have_content(text)
end

IV. Support

– hosts all configuration files

Sample: env.rb

require 'capybara'
require 'capybara/cucumber'

Capybara.default_driver = :selenium
Capybara.app_host = "http://www.google.com"
Capybara.default_wait_time = 20

World(Capybara)

V. Gemfile

– a format for describing gem dependencies required to execute Ruby codes

Sample: Gemfile


source "http://rubygems.org"

group(:test) do
 gem 'cucumber'
 gem 'capybara'
 gem 'rspec'
end

VI. Run

Using terminal go to your root project folder and type: cucumber or bundle exec cucumber

After the run, you should be able to see the results like this:

1 scenario (1 passed)
5 steps (5 passed)
0m9.461s

This example runs smoothly in Windows 7. Let me know if it works for you as well.

Resolving “Couldn’t open app window; is the pop-up blocker enabled?” Selenium error in IE 10

June 20, 2012 Leave a comment

Need to setup my Linux machine(master) to remotely access a Windows 8 machine(slave) with Internet Exporer 10 browser that will run my Selenium scripts.

master – machine where Selenium scripts, browser configurations are saved; one that will be sending requests to run the scripts

slave – machine where Selenium scripts will be run using a different platform (OS and browser); one that will accept the request to run the scripts

To do this, I configure the browser file from the master machine:

# for Internet Explorer
our $sel = Test::WWW::Selenium->new( host => "Windows Machine IP", port => 4445, browser => "*iexplore", browser_url => "application URL" );

From the slave machine, I needed to install the following:

– Java SE Runtime  Environment 1.7

– download latest Selenium Server from SeleniumHQ

To prepare the slave machine to accept the request, launch selenium server from the terminal using the same port set in the master machine:

java -jar selenium-server-standalone-2.23.1 -port 4445

To send request from the master machine, you may use “spec”, “rake” command depending on how you organized your test files. However after executing the command to run the scripts from the master machine, an error was encountered in the slave machine – “Couldn’t open app window; is the pop-up blocker enabled?”

IE 10 – Selenium error

Solution:
From the master machine, update browser configuration from “*iexplore” to “iexploreproxy”
# for Internet Explorer
our $sel = Test::WWW::Selenium->new( host => "Windows Machine IP", port => 4445, browser => "*iexploreproxy", browser_url => "application URL" );

Perl-Selenium Helpful String Manipulations

November 28, 2011 Leave a comment

Below are the string functions I found helpful during scripting in my current project using Selenium in Perl language:

Split(/PATTERN/,EXPR)
– Splits the string EXPR into a list of strings based on given PATTERN and returns that list.

# Scenario: Clicking Email link opens new window. Verify new location/URL displayed is correct
# Email element: <a onclick=”window.open(‘http:test.url’,’EMAIL’,’width=730,height=450,status=yes,toolbar=no,menubar=no,location=no’);” style=”color: rgb(38, 6, 2); font-size: 11px; text-decoration: underline;” href=”javascript: void(0);”>Email</a>

my $href = $sel->get_attribute("xpath=//html/body/div[2]/div[2]/div[2]/table/tbody/tr/td[2]/div[3]/a/\@onclick");
# $href = "window.open('http:test.url','EMAIL','width=730,height=450,status=yes,toolbar=no,menubar=no,location=no');"
my @url = split(/'+/, $href);
# @url = ['window.open(' , 'http:test.url' , ',' , 'EMAIL' , ',' , 'width=730,height=450,status=yes,toolbar=no,menubar=no,location=no' , ');' ]

Substr(EXPR,OFFSET,LENGTH)
– Extracts a substring out of EXPR and returns it based on defined OFFSET and LENGTH

# Scenario: Get the numeric value from the Total distance string element

my $str = $sel->get_text("css=div.olPopupContent>div.mainbubblecontent>div.mainbubbletabcontent>div.activetabcontent>div:nth-child(5)");
# $str = "Total distance: 100.25 miles";
my $distance = substr($str,16,5);
# $distance = '100.25';

Match (m/PATTERN/)
– match a string with a regular expression pattern

my $str = "Total distance: 100.25 miles";
 if ($str =~  m/ \d*.\d* miles/) {
   print "Pass";}
 else{
   print "Fail";}

Cmp_ok( $got, $op, $expected, $test_name )
– Test::More function that allows you to compare two arguments using any binary perl operator.

my $str = $sel->get_text("css=#panel > #collection_maneuvers > thead > tr > th");
# $str = "Total distance\: 100.25 miles"
cmp_ok($str, "=~", m/Total distance\: \d*.\d* miles/, "Verify estimated mileage is displayed");

Like( $got, qr/expected/, $test_name )
– Another Test::More function that evaluates any expression against a regular expression

my $str = $sel->get_text("css=#panel > #collection_poi > thead > tr.poi > th");
# $str = "5 locations found in your area"
like($str, qr/\d* locations found in your area/, "Verify number of locations is displayed");

Also came across this Perl documentation link (http://perldoc.perl.org) which is direct and comprehensive.

Selenium RC to test unsecured connection HTTPS

November 9, 2011 Leave a comment

It’s inevitable for software testers to run test in an environment with self-signed SSL certificates. This became one of my dilemma when trying to run my Selenium scripts in an HTTPS environment and was always prompted with “This Connection is Untrusted” error.

I have an existing Firefox Profile solely for Selenium, if you don’t have one, you can check this post.  Was able to resolve this issue by doing the following:

  1. Launch Profile Manager by typing “firefox -ProfileManager -no-remote” in your terminal (Linux user)
  2. Select Selenium profile then Start Firefox
  3. Access your web application URL in HTTPS
  4. Accept the SSL Certification:
      • Click “I Understand the Risks”
      • Click “Add Exception”
      • Click “Get Certificate”
      • Make sure “Permanently store this exception” tickbox is checked
      • Click “Confirm Security Exception”
  5. After successfully directed to the web application page, close Firefox
  6. Go to Selenium Profile folder ( in my case /home/girlie/.mozilla/firefox/selenium )
  7. Delete all files except for cert_override.txt and cert8.db files.

From here on, I rerun my Selenium scripts and didn’t encountered the “This Connection is Untrusted” error anymore 😀

Selenium-Ruby Installations in Linux

March 30, 2011 Leave a comment

In relation to my previous post on Selenium and Ruby setup in Windows, here’s an installation guide for Linux peeps:

1. Install JRE

– In your terminal type: sudo apt-get install sun-java6-jre

– To verify type: java -version

Note: Java version should be 1.5 or higher versions

2. Install Ruby

– In your terminal, type: sudo apt-get install ruby

– To verify type: ruby –version

Note: ruby 1.8.7 works with rspec version <= 1.3.1

3. Install Rubygems

– From the terminal, type: sudo apt-get install rubygems OR you can follow this tutorial Installing RubyGems

– To verify type:  gem –version

4. Install other useful gems

  • Rake ( to create a task that runs set of tests )

– Type: sudo gem install rake

– To verify type:  rake –version

  • Selenium-client ( API to drive Selenium tests from Ruby )

– Type: sudo gem install selenium-client -v 1.2.18

– To verify type: gem list selenium-client

Note: selenium-client 1.2.18 works with rspec version 1.2.8

  • Rspec ( to define executable examples of the expected behaviour of your code )

– Type: sudo gem install rspec -v 1.2.8

– To verify type: spec –version

  • Faker ( to easily generate fake data: names, addresses, phone numbers, etc. )

– Type: sudo gem install faker

– To verify type: gem list faker

Categories: ruby, selenium, ubuntu Tags: , , ,

Basic CSS Locators

January 6, 2011 1 comment

Sample HTML chunk:

<div id=”page”>

<ul id=”index”>

<li>

<div class=”actions”>

<h3>Test 01</h3>

<a class=”1″>

<a class=”2″>

</div>

<li>

<div class=”actions”>

<h3>Test 02</h3>

<a class=”1″>

<a class=”2″>

</div>

Sample CSS Locators:

Element Locators
1 Page css=div#page
css=div[id=page]
id=page
2 Index css=div#page>ul#index
css=div[id=page] ul[id=index]
css=ul#index
3 Actions css=div.actions
css=div[class=actions]
4 First a child of first li element css=ul#index>li>div.actions>a:first-child
css=ul[id=index] li div[class=action] a:first-child
css=ul#index>li>div.actions>a
5 Last/Second a child of second li element css=ul#index>li:nth-child(2)>div.actions>a:last-child
css=ul#index>li:nth-child(2)>div.actions>a:nth-child(2)
6 Heading containing text css=h3:contains(‘Test 01’)

For a comprehensive list of CSS Selector Syntax, check this link:  http://www.w3.org/TR/css3-selectors/

<ul id=”index”>
<li>
<div class=”action_buttons”><a title=”Show Arthur C. Ortiz” href=”/people/arthur-c-ortiz” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Arthur C. Ortiz” href=”/people/arthur-c-ortiz/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Arthur C. Ortiz” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Arthur C. Ortiz?” href=”/people/arthur-c-ortiz” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Arthur C. Ortiz</h3></li>
<li>
<div class=”action_buttons”><a title=”Show Carlos Tucker” href=”/people/carlos-tucker” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Carlos Tucker” href=”/people/carlos-tucker/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Carlos Tucker” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Carlos Tucker?” href=”/people/carlos-tucker” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Carlos Tucker</h3></li>
<li>
<div class=”action_buttons”><a title=”Show Catherine Rose” href=”/people/catherine-rose” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Catherine Rose” href=”/people/catherine-rose/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Catherine Rose” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Catherine Rose?” href=”/people/catherine-rose” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Catherine Rose</h3> 

</li>
<li>
<div class=”action_buttons”><a title=”Show Christina Sims” href=”/people/christina-sims” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Christina Sims” href=”/people/christina-sims/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Christina Sims” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Christina Sims?” href=”/people/christina-sims” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Christina Sims</h3>

</li>
<li>
<div class=”action_buttons”><a title=”Show Christopher R. Young” href=”/people/christopher-r-young” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Christopher R. Young” href=”/people/christopher-r-young/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Christopher R. Young” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Christopher R. Young?” href=”/people/christopher-r-young” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Christopher R. Young</h3>

</li>
<li>
<div class=”action_buttons”><a title=”Show Cynthia Fuller” href=”/people/cynthia-fuller” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Cynthia Fuller” href=”/people/cynthia-fuller/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Cynthia Fuller” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Cynthia Fuller?” href=”/people/cynthia-fuller” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Cynthia Fuller</h3>

</li>
<li>
<div class=”action_buttons”><a title=”Show Debra Wagner” href=”/people/debra-wagner” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Debra Wagner” href=”/people/debra-wagner/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Debra Wagner” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Debra Wagner?” href=”/people/debra-wagner” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Debra Wagner</h3>

</li>
<li>
<div class=”action_buttons”><a title=”Show Dennis Matthews” href=”/people/dennis-matthews” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Dennis Matthews” href=”/people/dennis-matthews/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Dennis Matthews” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Dennis Matthews?” href=”/people/dennis-matthews” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Dennis Matthews</h3>

</li>
<li>
<div class=”action_buttons”><a title=”Show Diana Burton” href=”/people/diana-burton” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Diana Burton” href=”/people/diana-burton/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Diana Burton” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Diana Burton?” href=”/people/diana-burton” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Diana Burton</h3>

</li>
<li>
<div class=”action_buttons”><a title=”Show Edward Torres” href=”/people/edward-torres” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-document”></span><span class=”ui-button-text”>Show</span></a><a title=”Edit Edward Torres” href=”/people/edward-torres/edit” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-pencil”></span><span class=”ui-button-text”>Edit</span></a><a title=”Delete Edward Torres” rel=”nofollow” data-method=”delete” data-confirm=”Are you sure you want to delete Edward Torres?” href=”/people/edward-torres” class=”ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary” role=”button”><span class=”ui-button-icon-primary ui-icon ui-icon-trash”></span><span class=”ui-button-text”>Delete</span></a></div>
<h3>Edward Torres</h3>

</li>
</ul>

Categories: selenium Tags: , ,

Run your RC server via Rakefile

September 8, 2009 1 comment

Gone tired of starting your selenium server by typing,

java -jar selenium-server.jar"

from your console or if you’re luckier create a batch file then run it to start your server...

Here’s a more powerful tool to do it. Utilizing the selenium-client ruby gem, first you need to create a rakefile and define the tasks that you want to do. For instance we want to tell our rake to do the following tasks:

1. Start selenium server,

2. Stop selenium server, and

3. Restart selenium server

require ‘rubygems’
require ‘selenium/rake/tasks’ # use selenium rc rake tasks that are bundled with the selenium-client gem

SELENIUM_RC_JAR = Dir[File.dirname(__FILE__) + “/selenium-server*.jar”].first

# Start selenium server task
Selenium::Rake::RemoteControlStartTask.new(:’rc:start’) do |rc|
rc.port = 4444
rc.timeout_in_seconds = 3 * 60
rc.background = true
rc.wait_until_up_and_running = true
rc.jar_file = SELENIUM_RC_JAR
rc.additional_args << " -multiWindow -firefoxProfileTemplate FirefoxProfile" end # Stop selenium server task Selenium::Rake::RemoteControlStopTask.new(:'rc:stop') do |rc| rc.host = "localhost" rc.port = 4444 rc.timeout_in_seconds = 3 * 60 end # Restart selenium server task desc "Restart Selenium Remote Control" task :'rc:restart' do Rake::Task[:"rc:stop"].execute [] rescue nil Rake::Task[:"rc:start"].execute [] end [/sourcecode] In your console go to the root folder where your rake file is saved, type "rake -T" or "rake --task"

D:\Projects>rake -T

Console will list all available tasks defined in the rake:

(in D:/Projects)
rake rc:restart  # Restart Selenium Remote Control
rake rc:start    # Launch Selenium Remote Control
rake rc:stop     # Stop Selenium Remote Control running

From this list you can restart/start/close the server by simply invoking the commands  e.g. rake rc:start

Categories: selenium Tags: ,