Forum Discussion

tobello's avatar
tobello
Contributor
11 years ago

dynanic DDT filePath for excelDriver

Hi faulks,

Newbie to TC and would need someone to share anything about this with me,
I'll really appreciate... Getting crazy with this:

Because my test input values in test file might change depending on tester desired, I want the tester to provide the testfile (full path like "C:\\TestFolder\\TestData\\TestFile.xlsx") to a test engine.

Note that the file structure remains the same but only the test values is changeable but the engine is capable of understanding and performing the correct action.

I'm trying to set an Excel DDT driver from the filePath passed from a function
but it does not work as I'm alway getting 'a type mismatch', 'file does not exists', 'excel file does not exisit' or 'property or method is not supportted' errors.

When I try the hardcoded way it's walked fine: Project.Variables.rptTestFile = DDT.ExcelDriver( "C:\\TestFolder\\TestData\\TestFile.xlsx"), "Reports", true);


Here is the function

function setTestDataDriver(testDataFile)
{
var testFile;
try
{
testFile = aqString.Replace(testDataFile, "\\", "\\\\", false);

var aFile = aqFileSystem.GetFileInfo(testFile);
if (aFile.Exists)
{
var aFilePath = aFile.Path;

Project.Variables.rptTestFile = DDT.ExcelDriver(testFile , "Reports", true);

}

}catch(e)
{
Log.Error(e.description);
}
}

Tks in advance

2 Replies

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi Ted, two things:


     


    1. The line testFile = aqString.Replace(testDataFile, "\\", "\\\\", false); is not required. Using the "\" escape character is only required when defining literal strings for compile time evaluation, e.g.


     


    var path = "C:\\TestFolder\\TestData\\TestFile.xlsx";


     


    If you pass "path" to a function, then escaping the "\" character is not required.


     


    2. You can use the aqFile::Exists() method to determine file availability instead of having to create an instance of aqFileInfo for this purpose.


     


    The following may be of use as an example:


     


    function setTestDataDriver(testDataFile) {


      var testFile;


      try {


        if(aqFile.Exists(testDataFile) ) {


          Project.Variables.rptTestFile = DDT.ExcelDriver(testDataFile , "Reports", true);


        }


      } catch(e) {


        Log.Error(e.description);


      }


    }


     


    Regards,


    Phil Baird

  • Hi Phil,

    Thanks for all.
    FYI, this one was a "no brainer": I made a mistake in the Project variable. It was a DBTable instead of an Object. The code was working fine...

    for you remarks at point 1., the function call was made directly with no variable as you've described it. Therefore I needed that little manipulation...
    e.g: setTestDataDriver("C:\\TestFolder\\TestData\\TestFile.xlsx") .

    Your point 2. is actually totally true but I was thinking of the testers who provide only the UNC path like e.g. setTestDataDriver("..\\TestFolder\\TestData\\TestFile.xlsx").
    Thus, I planned the retrieval of the file fullpath and to work with...

    But one thing i did is to change te code to this:
    [...]
    if (aFile.Exists)
    {
    Project.Variables.rptTestFile = DDT.ExcelDriver(aFile.Path, "Reports", true);
    [...]
    }

    Thanks for the help,
    Regard