Saturday, May 14, 2011

What is Data-Driven Tests in Watir ? How do I use Excel with Watir for data-driven tests?

Data-Driven Tests
How do I use Excel with Watir for data-driven tests?
require 'win32ole'

excel = WIN32OLE::new("excel.Application")
workbook = excel.Workbooks.Open("c:\\examples\\example_sheet.xls")

worksheet = workbook.WorkSheets(1) # get first workbook
worksheet.Select # just to make sure macros are executed, if your sheet doesn't have macros you can skip this step.

value = worksheet.Range("a12").Value # get the value at cell a12 in worksheet.

data = worksheet.Range("a1:c12").Value # returns 2D array with values starting from cell a1 to cell c12

1 comment:

  1. Assalamu alaikum shahadath khan bhai,

    I am a newbie for watir. Cann u please explain Watir Data driven technique with an example??
    Thank u

    ReplyDelete