Using Text files for testing data in a script
Is there any way to use a text file for testing data in a script? For example, I want to have a file that will show the following:
Field Name, Testing Area, Expected Value
Field 1, value, "foo"
Field 2, value, "bar"
Field 3, value, "baz"
In a specific function, I want to find the corresponding field name and load the data to run the test. So, when I run field2Validation(testingarea, expected), I want to be able to pass the second line in the file. I don't want to specify a line number, either.
Can this be done? Can anyone direct me to any information on how to do this? I did a search myself, but I can only find how to dump the whole file, not line by line.
I am thinking an array or possibly a new object might be the best, but I can't figure out how to get the information out of the file.
This is what I ended up doing (with a little help from a developer). I created a function that will read the file all in one go (with some help from the KeyWord Test to Script translations. As it reads the file, it uses an array to hold each line as an object. The first column was the object name and the others were data values I want to check.
When I call the array object variable, I just need to name the correct object to get the data I need for that test case. And make sure that all the functions include //USEUNIT and my parsing function
What I did is below:
Example file:
FieldName Value Color
name 190 green
amount 0 red
Run the file through the following function in the main script:
var testcases =[]; var fieldname = ''; function parseInputFile() { Project.Variables.inputfile.Reset() ; for(; !Project.Variables.inputfile.IsEOF() ; ) { fieldname = Project.Variables.inputfile.Value("FieldName") ; testcases[fieldname]={Value: Project.Variables.inputfile.Value("Value"), Color: Project.Variables.inputfile.Value("Color") }; Project.Variables.inputfile.Next() ; } }
Then, I just reference the object I want in my function
//USEUNIT ParseFile function testName() { Log.Message(testcases['name'].Value); //this will equal 190 }