Data Driven Test for Selenium tests

I just finished the first prototype of the data driven Selenium test. A new DdDslContext is created and it extends the DslContext..

We provide the following functions at this point::

1) Define Input file data format for each line using DSL including name, description, type, and data validations.

2) Users can define custom data types and their type handlers in DSL,
i.,e., how to convert data as String from a file to more complicated

Java type and do some conversion.

3) Add data provider to read data from a file line by line. Right now,
we only support Pipe format flat file.

4) Add Dsl to bind variables to data reading from the input file.

5) Add one flow control, i.e., “driven”, which will read data from the
input file line by line and run the test script until it reaches the
end of the file.

The code is on the trunk and the example data driven dsl file is
provided in aost.example.datadrivengoogle.dsl and the input file is
aost.example.googlesearchinput.txt.

After you check out the project from the trunk, run ant tasks to
compile code and compile test as follows:

ant clean
ant dist
ant compile-test

then run

./rundsl.sh src/example/dsl/datadrivengoogle.dsl

on windows, you need to use windows path syntax.

Or you can run the functional test
“example.aost.GoogleDdDslContext_FT” directly and it does the same
thing.

The sample data driven dsl looks as follows:

———————————————————
//define google start page
ui.Container(uid: “google_start_page”, clocator: [tag: "td"], group: “true”){
InputBox(uid: “searchbox”, clocator: [title: "Google Search"])
SubmitButton(uid: “googlesearch”, clocator: [name: "btnG", value: "Google Search"])
SubmitButton(uid: “Imfeelinglucky”, clocator: [value: "I'm Feeling Lucky"])

}

//AOST has already provided default type handlers for regular Java type
//The users can also define custom data types and their type handlers so that they
//can read and process special types of data

defineTypeHandler “phoneNumber”, “example.aost.PhoneNumberTypeHandler”

//define file data format for each line, always start with “fs.”
fs.FieldSet(id: “fs4googlesearch”, description: “example field set for google search”){
//define fields for each line
Field(name: “regularSearch”, type: “boolean”, description: “whether we should use regular search or use I’m feeling lucky”)
Field(name: “phoneNumber”, type: “phoneNumber”, description: “Phone number”)
Field(name: “input”, description: “input variable”)

}

//load file
loadData “src/example/dsl/googlesearchinput.txt”

//data driven test assuming the input data format is defined in FieldSet “fs4googlesearch”
driven(“fs4googlesearch”){
//bind variables
//Since there is only one FieldSet, the fieldSet Id can be omitted
boolean regularSearch = bind(“regularSearch”)
//But if you have more than one FieldSets, you must specify the FieldSet Id as follows
def phoneNumber = bind(“fs4googlesearch.phoneNumber”)
String input = bind(“input”)

openUrl “http://www.google.com
type “google_start_page.searchbox”, input
pause 500

if(regularSearch)
click “google_start_page.googlesearch”
else
click “google_start_page.Imfeelinglucky”

pause 1000

openUrl “http://www.google.com
type “google_start_page.searchbox”, phoneNumber
click “google_start_page.Imfeelinglucky”

pause 1000

}

//close file
closeData()

———————————————————————–

And the data input file is
———————————————————————–
true | 865-692-6000 | aost
false| 865-123-4444 | aost selenium test
———————————————————————–

Please feel free to provide us any comments and suggestions. Please check our project page

http://code.google.com/p/aost/

and AOST user group

http://groups.google.com/group/aost-users

for any updates.

Thanks in advance,

Jian

Leave a Reply