Monday, November 22, 2010
Wednesday, November 3, 2010
Cucumber Automation
What is Cucumber actually?
- Behavior driven development testing tool.
- Bunch of behaviors in the form of scenarios.
- Written mainly by non-technical people
- Written in plain English.
What should you do actually?
- Write a behavior in the form of scenarios in a feature files.
- Write the code in order to satisfy the scenario.
- Run the feature file.
- Watch it fail
- Write the automation scripts with the template provided by the cucumber.
- The behavior of the application is satisfied by the test script.
Cucumber Installation on Windows Platform:
1. Ruby Installation.
· First, go to Ruby site and download the latest version of Ruby installer. Click on Rube installer exe file and then install the ruby.
· Set up the classpath for Ruby by adding home directory path of the ruby into the Classpath variable.
· Setup the Path system variable for Ruby by add the path string of the ruby bin dir into the path system variable.
· Make sure ruby installed properly by open the command prompt and type the command ‘gem update --system’.
Note: More details about Ruby http://www.sapphiresteel.com/IMG/pdf/LittleBookOfRuby.pdf
Note: More details about Ruby http://www.sapphiresteel.com/IMG/pdf/LittleBookOfRuby.pdf
2. Install Cucumber:
· Make sure Ruby installed properly by doing the steps of the Ruby installation.
· Open command prompt and execute the command “gem install cucumber win32console” and wait for some time for installation.
· Once installation is done and make sure cucumber installed or not by the command “cucumber --version”.
3. Install Rspec gem:
· RSpec Cucumber is an engine that lets you map English statements (or any language actually) to executable code in order to validate software specifications written as scenarios with the code written to fulfill them.
· Install Rspec by the command “gem install rspec”
4. Install watir gem:
· Watir is an open-source family of Ruby libraries for automating web browsers. It allows you to write tests that are easy to read and maintain. It is simple and flexible.
· Install watir by the command “gem install watir”
Demo Project:
Demo in windows platform (Please refer “Cucumber Installation on Windows Platform” section for installations before starting the project).
Let’s consider the test case, search some word in Google search home page).
1. First, create a sample project (i.e. create any directory) and then create a sub directory “features’.
2. Create a feature file with extension ‘.feature’ inside the features directory.
3. Copy the below info into the feature file.
Feature: Google Search
In order to find out more about cucumber benefits
I need to able to search Google
Scenario: Google Search for cucumber benefits
Given that I am on the Google Homepage
When I search for cucumber benefits
Then I should see "Cucumber Benefits for Great Skin and Eyes"
Let’s consider the sample project dir structure as below
4. Now go to command prompt, run the command “cucumber features” as below
It will generate the template of the step definitions (blue text in screen shot)) for the above scenario
5. Now create a ‘step_definitions’ directory inside of the features directory and then create a ruby file and then copy the step definitions template.
6. Now, implement the logic for the step definitions by using Ruby, Watir Driver scripts.
Please find below the sample step-definitions file.
7. Finally, execute the features in command prompt as above.
Monday, November 1, 2010
Selenium with CSS locators.
XPath locator is one of the most quirky and one of the most precise locator. This disadvantage is clearly seen while running the tests under IE while Firefox works with xpath pretty well. This problem is related to internal browser features in particular to the libraries being used for elements location definition. But this is another story. The main thing is that tests which intensively use XPath work extremely slow under IE and this feature is the cause of huge variety of problems related to execution speed as well as quality of the tests itself especially during operations with dynamic content. For this reason CSS locators can be good alternative of XPath.
What can we do with CSS locators?
First of all,CSS locators also give the ability to describe object hierarchy. For instance, the XPath locator like:
First of all,
Xpath=//div//span/a
can be described via
css=div * span > a
From the sample above we may see analogy for XPath and
a) Character "/" meaning next level of
b) Character "//" meaning any object hierarchy level under current object corresponds to
Secondly, just like XPath, the
Xpath=//div[@id="some_id"]
can be described via
css=div[id=some_id]
Also there\'s abitity to check for partial attribute value matching. But
xpath=//div[contains(@title,"title")]
can be expressed via
css=div[@title~=title]
Both the locators can detect the element like
<div title="some multiword title" /> while the element like <div title="my_title" />
can\'t be detected by CSS locator from above.
AlsoCSS has simplified form for some attributes. For instance, the element having the id attribute like <div id=some_id /> can be located by the following CSS :
Also
css=div#some_id
In addition to that
xpath=//div[@class="myclass"]
has the following
css=div.myclass
Such features make
So, in some cases CSS locators are the analogs of XPath locators with one serious advantage: CSS works fast no matter what the browser we use.
Of course,
Subscribe to:
Posts (Atom)