Forum Discussion

SaravanaKumar_N's avatar
SaravanaKumar_N
Contributor
8 years ago
Solved

Do we have access for BuiltIn object at Script Extensions

Hi All,

My aim is to have a method at our Script Extensions file, that would return the array of command line variables.

But it looks like we do not have access for 'BuiltIn' objects at Script Extensions, which can be used to get command line variables.

Just want to be sure about it. Also is there any other way to get the command line variables, such that it would be a global method (i.e., at Script Extensions).

 

Thanks,

Saravana

 

Update about Solution[30/3/2017]:

Too many inputs, really confused to Accept what as a solution.

Thank you so much HKosovatristaanogre and shankar_r.

 

I would accept HKosova idea as a solution because he has given the insight which is what I asked for. Special thanks to tristaanogre for sharing your utilities and also to shankar_r for showing another way to deal the issue.

 

  • HKosova's avatar
    HKosova
    8 years ago

    BuiltIn.ParamCount and .ParamStr are wrappers over Sys.Process("TestComplete").CommandLine, so you can try parsing the CommandLine string yourself. Just be aware that spaces can be part of an argument value -- if that argument is enclosed in quotes.

     

    If you use both TestComplete and TestExecute, you'll also need to find out what the current test runner is. Maybe try Sys.WaitProcess("TestExecute") first and fall back to TestComplete.

     

    Or go with tristaanogre's suggestion and use config files instead.

12 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    I used below function store to my command line arguments into a variable.

     

    function Store_CommandLine_Parameters()
    {
          var count_CL_Parameters = BuiltIn.ParamCount(); 
          var pv_ColumnName = "CL_Parameter";
          Project.Variables.CommandLineParameters.RowCount = count_CL_Parameters + 1;
           
          try
          {
                for(var a = 0 ; a <= count_CL_Parameters ; a++)
                {
                      Project.Variables.CommandLineParameters.$set(pv_ColumnName,a,aqConvert.VarToStr(BuiltIn.ParamStr(a)));
                }
                return true;      
          }
          catch(ex)
          {
                Log.Warning("Error while processing Commandline parameter(s). Error: " + ex.stack);
                return false;
          }         
    }

     you can edit and do a formative or conversion in-order to meet your requirement.

    • SaravanaKumar_N's avatar
      SaravanaKumar_N
      Contributor

      Hi shankar_r,

       

      I do have a similar method to gather the command line variables. Since we have multiple project-suites, I thought of having that method in our CommonUtils - Script Extensions.

      Any ideas?

       

      Anyway thanks for your input.

       

      Regards.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      shankar_r wrote:

      I used below function store to my command line arguments into a variable.

       

      function Store_CommandLine_Parameters()
      {
            var count_CL_Parameters = BuiltIn.ParamCount(); 
            var pv_ColumnName = "CL_Parameter";
            Project.Variables.CommandLineParameters.RowCount = count_CL_Parameters + 1;
             
            try
            {
                  for(var a = 0 ; a <= count_CL_Parameters ; a++)
                  {
                        Project.Variables.CommandLineParameters.$set(pv_ColumnName,a,aqConvert.VarToStr(BuiltIn.ParamStr(a)));
                  }
                  return true;      
            }
            catch(ex)
            {
                  Log.Warning("Error while processing Commandline parameter(s). Error: " + ex.stack);
                  return false;
            }         
      }

       you can edit and do a formative or conversion in-order to meet your requirement.


      The problem is, as the OP notes, the BuiltIn object is not available to be used within a Script extension (reference https://support.smartbear.com/testcomplete/docs/working-with/extending/script/objects-reference/index.html).

       

      I'm not sure how else to get commandline parameters for the TestComplete commandline.  I guess the question is, what are you using those commandline parameters for?  One thing you could do is find some other way of  passing that information into TestComplete.  For example, an INI file or XML file that is read as part of the initialization process of a test run using methods in aqFile, aqString, etc.

       

       

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        BuiltIn.ParamCount and .ParamStr are wrappers over Sys.Process("TestComplete").CommandLine, so you can try parsing the CommandLine string yourself. Just be aware that spaces can be part of an argument value -- if that argument is enclosed in quotes.

         

        If you use both TestComplete and TestExecute, you'll also need to find out what the current test runner is. Maybe try Sys.WaitProcess("TestExecute") first and fall back to TestComplete.

         

        Or go with tristaanogre's suggestion and use config files instead.