Forum Discussion

santoguya's avatar
santoguya
Contributor
15 years ago

passing in variables from command line to use in testcomplete

Hi,



So I want to be able to run one of my projects on multiple operating systems, where path/directory structures and credentials will be different. I developed my TestComplete test in Windows Xp so the TestedApps locations all point to C:\Program Files\, and for Win7 I need it to point to C:\Program Files (X86)\.



Therefore I want to modify my cmd script to call Project.pjs with some parameters that modify some type of global variable inside my test script that will be used in the pathing of my Tested Apps.



For instance, if I use a global variable PROGRAM_FILES_PATH, i want to do something like:



1. In cmd, call Project.pjs PROGRAM_FILES_PATH="C:\Program Files\"

2. In my TestComplete project, have a global variable named PROGRAM_FILES_PATH that can be modified by 1.)

3. In TestedApps for all of the applications I want to run, use the variable PROGRAM_FILES_PATH



I see that you can specify Temporary Variables and Persistent Variables when you right click on your project and edit Variables; is persistent variable a global variable?



Is this functionality possible? If possible, please provide some example code or a tutorial of some sort.



Thanks!

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    In this article ( http://smartbear.com/support/viewarticle/10998/ ), towards the end is a discussion and examples of how to get the parameters from the TestComplete command line and use them in script.  A couple of supporting articles are http://smartbear.com/support/viewarticle/11009/ and http://smartbear.com/support/viewarticle/11006/





    For myself, I don't use the command line.  Instead, I create an INI file and use the INI object to read options in and assign them to project variables.  That way I can set up INI files on a per machine basis and just run a project without having to worry about making sure the proper command line is set.
  • Hi,



    Thanks for the response.



    In that first article I see lots of examples at the bottom on how to call different tests and projects and other options but nothing about how to set/pass a variable into the test project. You talked about modifying the .ini file, is this where the project variable values are stored? I can write a script to modify any file so that might be an option. Please include some more information about how to modify the ini file or how to pass in project variables via the command line. Basically I want to modify the path of the TestedApps based on what operating system I'm running the tests on.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    You will need to write code using the Builtin.ParamStr and BuiltIn.ParamCount methods.



    I quote from the first article:



    You can determine what parameters were passed to TestComplete in its command line by using the ParamStr function. It allows you to get a TestComplete command-line argument specified by its index. To get the total number of arguments in the command line, use the ParamCount 




    Also, from that same first article, there's a code example:



    function CommandLineArgs()

    {

      var nArgs = BuiltIn.ParamCount();

      Log.Message("Total number of command-line arguments: " + nArgs);

      Log.Message("The fully-qualified name of the TestComplete executable: " + BuiltIn.ParamStr(0));



      for (var i = 1; i <= nArgs ; i++)

        Log.Message("Arg " + i + ": " + BuiltIn.ParamStr(i));

    }




    The code example is rather trivial but it shows how to retrieve the command line parameters and access them using those two methods mentioned above.
  • Hi,



    Okay that looks good, still unsure about how you would modify your TestedApp file paths and parameters using javascript or .net. I see how you are passing and retrieving those variables though.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Say I have a TestedApp object called MyApp.  I can access the path for that through



    TestedApps.MyApp.Path = MyNewPathValue




    As for the parameters, that's a little more complex, but it can be handled using the TestedApp.Params object.  There's a bit more to it than just setting the parameter.



    TestedApps.MyApp returns a TestedApp object.  You can read more about the various properties and methods available to the TestedApp object at  

    http://smartbear.com/support/viewarticle/11382/



    An example on using the TestedApp.Params object as well as links to other information can be found at



    http://smartbear.com/support/viewarticle/12353/