Google

WATIR : Data-Driven Testing

Data-Driven Testing means reading data from external storage sites like files, databases using script. Rather than hard coding the values in the script.

A data-driven test includes the following operations performed in a loop:
1. Retrieving input data from storage.
2. Entering data in an application form.
3. Verifying the results.
4. Continuing with the next set of input data.

Data-Driven Testing using Notepad,
1. Put the notepad(data file) in the script folder.
2. Below class contains methods to get and set data.

class Data
def text_get(textfile, row, col) # text file should be in the script folder.
data = [] # array that will hold the data
col_data = []
file = File.open(textfile) # open file with the data
file.each do line # for each line in file
@len=line.chomp.split("\t").length
data << col_data="data[row.to_i]" return @col_data[col.to_i] end # end of the method

def text_set(text)
f1=File.basename(__FILE__, ".rb")
f2=File.open(f1+".txt", 'a+') #Create/ Open the text file
f2.puts text
end # end of the method
end # end of the class


How to Use:
text_get("test.txt", 1, 1)
text_set("stated leaning")

Data-Driven Testing using Open Office,
1. Put "oohelper.rb" in the same scripts folder. Get oohelper.rb.
2. Load oohelper library file in the script by using,
require "oohelper"
include OpenOffice
3. Use methods from the file as per requirement.

No comments: