Forum Discussion

akdurham's avatar
akdurham
New Contributor
14 years ago

File Checkpoints and Relative Paths

I searched for this and couldn't find it, so forgive me if this has been asked and answered elsewhere.



Is it possible to use relative paths in file checkpoints?  If so, what's the correct base directory for the relative path?  I've tried using paths relative to the project directory, relative to the tested application's executable, and relative to the tested application's working directory, all to no avail - my file checkpoint fails every time with messages like 'There is no item or file named "..\..\..\TestProject.mpj".'

  • Hello Adam,





    The File Checkpoint operation requires the full path to the file. As far as I understand, the location of the target file that is used in your checkpoint can be different depending on the location of the tested application or the TestComplete project folder. In this case, you can use a variable to specify the FileName parameter of the File Checkpoint operation. So, when the file location is changed, you will need just to modify the FilePath variable.





    To specify a variable for the checkpoint's FileName parameter, use the steps below:





    1. Create a variable (let's call it FilePath) that will contain the current full path to the target file including the file name (the TestProject.mpj file in your case).

    2. Select the File Checkpoint operation and open the Operation Parameters dialog;

    3. In the "Operation Parameters" dialog, select the FileName parameter and open the Edit Parameter Dialog

    Choose the Variable mode in the Mode field and specify the FilePath variable in the Value field.





    See also:

    Keyword Test Variables.





    Does this meet your needs?
  • akdurham's avatar
    akdurham
    New Contributor
    Could that parameter value then be defined from a TestExecute command line? I'd like to be able to set this from the command line so that it can be used in a script that will be stored in source control and operate correctly regardless of what computer it is downloaded to and run from.

  • Hello Adam,





    Yes, it is possible to pass a custom parameter to the TestExecute (TestComplete) command line. Just add an exta parameter to the TestExecute command line, for example: /FileName=something. To access command line arguments from script, use the BuiltIn.ParamCount and BuiltIn.ParamStr functions. See the CommandLineArgs sample procedure from the TestComplete Command Line help topic.
  • akdurham's avatar
    akdurham
    New Contributor
    Alex,

    Thank you, that will be very useful. Is it possible to get the command line parameter information in a keyword test, or will I have to convert it to a script first? I suspect the latter but would like to know for sure.



    Thanks,

    Adam

  • Hello Adam,





    You don't need to convert your keyword test to a script. Instead, handle the command line parameters in a separate script procedure, and call this procedure from your keyword test using the Run Script Routine operation.





    The Pass parameters via the command line "How To" article describes how to process command line parameters. As you see, the parameters are processed and posted to the Test Log within the ProcessCommandLineArgument procedure. Instead of posting the parameters to the Test Log, you can create project variables for them and initialize the variables within the ProcessCommandLineArgument procedure. For example, suppose that you have a project variable called fileName and you need to initialize it with the FileName command line parameter:







    function ProcessCommandLineArgument(arg)

    {

      var items;

      items = arg.split("=");

      if(items.length != 2) 

      {

        return;

      }





      switch(aqString.ToLower(aqString.Trim(items[0]))) 

      {

        case "FileName":

          Project.Variables.fileName = aqString.Trim(items[1]);

          break; 

      }

    }







    After that, you will be able to use the Project.Variables.fileName variable in your keyword test.