Forum Discussion

shankar_r's avatar
shankar_r
Community Hero
8 years ago
Solved

Running a a function with parameter in Command line

From Smartbear help document:

    The following command runs TestExecute, loads the specified project suite (MySuite.pjs) and tells TestExecute to run the Main script routine located in the Unit1 unit of the MyProj project.

    "C:\Work\SmartBear\TestExecute\Bin\TestExecute.exe" "C:\Work\SmartBear\TestExecute\Projects\My\My.pjs" /r /p:MyProj /u:Unit1 /rt:Main

Based on the above I can run a function without parameter using /rt:Main

But  i want to know, Is there any possibility to run a function with parameter /rt:Main("parameter1")

 

  • shankar_r's avatar
    shankar_r
    8 years ago

    So, Instead of calling function with parameter in Command line. I changed my aspect to get it done my requirement.

     

    Here is the function which i used and it's working fine.

     

    function InitiateExecution()
    {
          var count_CL_Parameters = BuiltIn.ParamCount(); 
          
          var static_String_TC_NameAndEnv = "TestCaseName=";
          var currentTestCasenameAndEnv = "",arr_TC_Parameter = null;
          
          try
          {
                if(count_CL_Parameters > 3)//This part is for running from Test Complete/Execute Commandline
                {
                      for(var a = 0 ; a <= count_CL_Parameters ; a++)
                      {
                            if(aqString.Find(BuiltIn.ParamStr(a),static_String_TC_NameAndEnv,0,true) != -1)
                            {
                                  currentTestCasenameAndEnv = BuiltIn.ParamStr(a);
                                  arr_TC_Parameter = currentTestCasenameAndEnv.split("=");
                                  if((arr_TC_Parameter != null) && (arr_TC_Parameter.length == 2))
                                  {
                                        //CL_TestCaseName, CL_Environment are global variables
                                        CL_TestCaseName = GetCellValue.getNameFromValue(arr_TC_Parameter[1]);
                                        CL_Environment = GetCellValue.getCountFromValue(arr_TC_Parameter[1]);
                                        isCommandLine = true;
                                        driverscript();
                                        break;
                                  }
                                  else
                                  {
                                        throw "TestCaseName not found"  
                                  }                   
                            }
                      }
                }
                else//This part is for running from Test Complete/Execute manually
                {
                      isCommandLine = false;
                      driverscript();
                }
          }
          catch(ex)
          {
                ShowMessage("Error Occured: \n Parameters are missing : Format should be <Test Compelte/Execute Path> <Project Suite path> /r /e [TestCaseName=<value>[EnvironmentName]] \n Or Unkown error : " + ex.stack);
          }
    }

     It is may not be understandable since this function is part of Customized Data-driven framework which we are having in place.

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    From the same help:

    "TestComplete Command Line

      • /project:project_name  /unit:unit_name  /routine:routine_name

        TestComplete will run the specified script routine. Project_name specifies the name of the project to which the routine belongs. Unit_name specifies the name of the unit holding the desired routine. Routine_name is the name of the script routine to be called. The routine to be called must not use parameters or return any values. Project_name and unit_name should be the same as the project and unit names shown in the Project Explorer.

    So... at this time, no. You would actually have to write some sort of code into your TestComplete project to read parameters from the command line and pass them to the routine.  You would use the ParamStr and ParamCount count methods on the BuiltIn object to get the parameters from the command line.  You can then add parameters to the command line, parse them out using these tools, and then utilize them internally... but there's no native way of doing that directly from the commandline

    • shankar_r's avatar
      shankar_r
      Community Hero

      See this is what your experience :), I did't read fully. Thanks tristaanogre.

       

      Can you please provide some sort of documents or examples for the same if possible.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        I haven't implemented anything like that... yet... I might have need to do so in some other work I'm doing.

         

         

        In the meantime, the following code is from TestComplete's help that shows generally grabbing information from the command line

        function CommandLineArgs()
        {
          var i;
          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 (i = 1; i <= nArgs ; i++)
            Log.Message("Arg " + i + ": " + BuiltIn.ParamStr(i));
        }

        The theory I have is that you could use something like this to get parameters to pass to other methods.  So, if you use a standard command line string for exectuing with /rt for a routine name (5 parameters), you could set up a function to put strings starting at parameter 6 into an array that you can then put into some sort of global variable.  You could then set up something like the following, assuming you're using JavaScript/JScript (as those have the support for the arguments array):

         

        function foo(param1, param2, param3) {
           if (arguments.length = 0) {
               if (Project.Variables.CommandLineParameters.length != 0) {
        arguments.length = Project.Variables.CommandLineParameters.length;
        for (var i=0;i < arguments.length; i++) {
        arguments[i] = Project.Variables.CommandLineParameters[i]'
        } } }
        //Execute your function code }

        Mind you, this is TOTALLY untested and TOTALLY theoretical... but I THINK something like this could work.  Let me know if you try it and if it works.