March 28, 2012

Fetching the Data from CSV file using ruby

Currently I am trying to create a Selenium Framework using ruby language. I am new to creating a framework.
We can create framework with the help of the following methods

Framework:
Data Driven Framework
Keyword Driven Framework
Hybrid Driven Framework

I selected the Data Driven Framework because this provides you lots of information without touching the script.

Data Driven Framework:  My Understanding.
We need to provide the Input values, Expected Values and the accessing element ID are all mentioned in the    External file support.
Hence I tried to provide the information using CSV file.


Why to use CSV
CSV file provides better performance.
 It supports different OS.

Hence For Data driven Framework I choose 'CSV' File.

My Current Ruby version: 1.9.2
In ruby 1.9.2 version, CSV gem is inbuilt. Hence we donot need to install gems like (Faster CSV)
Herewith I given the script below, which I tried to Fetch data from excel and displaying it.

Code:


In excel File fill the row[1]=login/Case2/Case3= A2 B1

----------------------------------------------------------------------------
require 'rubygems'
require 'csv'

CSV.foreach("F:\\framework\\Input.csv") do|row|
case row [1]
when row[1] = 'login'
p row[0]
p row[1]
p row[2]
p row[3]
p row[4]
      p row
when row[1] = 'Case2'
p 22222222222222
when row[1] ='Case3'
p row[1]
when row[1]='print'
p row
end
end
----------------------------------------------------------------------------



Before Creating a framework, I  asked others, so many queries. And came to know about
What is framework?
How to use it?
Why we need to create it?
How to reuse it?
Where to Start creating a framework?
 But still not that much clear. Hence I gather much more information and you can view in upcoming posts.