cancel
Showing results for 
Search instead for 
Did you mean: 

Running a a function with parameter in Command line

SOLVED
Highlighted
Community Hero

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")

 


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Running a a function with parameter in Command line

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.


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

View solution in original post

7 REPLIES 7
Highlighted
Community Hero

Re: Running a a function with parameter in Command line

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


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
Community Hero

Re: Running a a function with parameter in Command line

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.


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

Highlighted
Community Hero

Re: Running a a function with parameter in Command line

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
Community Hero

Re: Running a a function with parameter in Command line

Thanks @tristaanogre for the detailed answer, I will give it try and let you know the results.

 


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

Highlighted
Community Hero

Re: Running a a function with parameter in Command line

Note I made a slight modification to assume a variable length on the array.  Again, untested and untried... let me know how it works out.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
Community Hero

Re: Running a a function with parameter in Command line

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.


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

View solution in original post

Highlighted
Community Hero

Re: Running a a function with parameter in Command line

nice!

The only thing I'd change is have your for loop start at 1 rather than zero.  Zero is the executable path for the TestComplete/TestExecute application.  Might as well skip that one. 🙂


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors