Forum Discussion

blbdt36's avatar
blbdt36
Contributor
9 years ago
Solved

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" F...
  • blbdt36's avatar
    blbdt36
    9 years ago

    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
    
    }