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

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.

3 comments:

  1. Hello Hemanth,
    The Article on Automation give detail information about it. Thanks for Sharing the information about Cucumber automation testing. Software Testing Services

    ReplyDelete
  2. Hey informative blog..

    If you are looking for SELENIUM TRAINING IN CHENNAI here is the link

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact +91-08122241286

    ReplyDelete
  3. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Visit here for Penetration testing services

    ReplyDelete