Ask a Question

Passing Test Parameters via Command Line won't work

SOLVED
OV
Frequent Contributor

Passing Test Parameters via Command Line won't work

Hi,

I'm trying to launch test complete and pass a parameter via command line but, following the instructions from here - https://support.smartbear.com/testcomplete/docs/working-with/automating/command-line-and-exit-codes/... it fails

This is my command line - TestComplete.exe "C:\Testcomplete\DA_Automation_Test_Framework.pjs" /r /p:PlayGroundProject /u:Unit1 /rt:Main /LatestSprintVersionNumber=ppp

I also tried /arg: (As I work with sessioncreator), I tried pv and psv. nothing is working. 

In TC report I can see all the parameters except the one I want which is /LatestSprintVersionNumber=ppp

 

We are triggering TE to execute the code via jenkins file and I'm not sure what should I put in the command line. the parameter I want to transfer is being retrieved by jenkins, I want to take it and pass it to the executable code via the command line.

 

If anyone knows why please let me know?

 

Cheers,

 

Ofer

4 REPLIES 4
Marsha_R
Community Hero

You didn't say how it fails?  Is there an error message?

 

Here's a reference on passing parameters:

https://support.smartbear.com/testcomplete/docs/working-with/automating/command-line-and-exit-codes/...

 


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
OV
Frequent Contributor

Hi Marsha,

 

I managed to figure out what was the problem. in the examples on the URL you sent they count the number of parameters and then for loop through them. it looks like the loop should go 0 to ParamCount() + 1 and not 0 to ParamCount(), if I use ParamCount() + 1 I get to see the desired value

 

def processCommandLineArguments():
for i in range (0, BuiltIn.ParamCount() + 1):
Log.Message(BuiltIn.ParamStr(i))
#processCommandLineArgument(BuiltIn.ParamStr(i))
processCommandLineArgument("/arg:LatestSprintVersionNumber=6.3")

def processCommandLineArgument(arg):
items = arg.split("=")
Log.Message(items[0])
Log.Message(items[1])

OV
Frequent Contributor

Now when running this code on the Jenkins pipeline I get an error:

13:21:15  The TestExecute process has exited with the following code: 2.
13:21:15  IndexError: list index out of range

this is my code and I can't understand why it is going out of range:

 

This is my command line, the argument I am passing is in bold

 

bat "SessionCreator.exe RunTest /UserName:%USERNAME% /UseActiveSession /Password:%PASSWORD% /ProjectPath:${env.WORKSPACE}\\DA_Automation_Test_Framework.pjs /p:AutomationSharedResources /arg:LatestSprintVersionNumber=$LatestSprintVersionNumber /ExportLog:${env.WORKSPACE}\\reports\\HTML\\report.html /ExportSummary:${env.WORKSPACE}\\reports\\report.xml"

 

And this is the code I am trying to use when running the TE

 

def processCommandLineArgument():

  for i in range (0, BuiltIn.ParamCount() + 1):

    items = BuiltIn.ParamStr(i).split(":")     

    items = items[1].split("=")

    if items[0] == "LatestSprintVersionNumber":     

      Log.Message("The latest sprint version passed via the command line is " + items[1]) 

      return items[1]

 

Can you please tell me where do I go wrong?

 

Any idea what is the problem?

 

Thanks,

 

Ofer

OV
Frequent Contributor

Hi,

 

Just for the sake of anyone else get into this problem, here is the solution:

 

def processCommandLineArgument(VersionFromTheApp):
#iterate through all parameters sent via command line set in Jenkins file
  for i in range (0, BuiltIn.ParamCount()):
    #verify any of tha parameters contain a string called LatestSprintVersionNumber
    if "LatestSprintVersionNumber" in aqConvert.VarToStr(BuiltIn.ParamStr(i)):
      #split the /LatestSprintVersionNumber=x.x.xxxx.xx parameter into 2 bits ('/' 'and LatestSprintVersionNumber=x.x.xxxx.xx')
      items = aqConvert.VarToStr(BuiltIn.ParamStr(i)).split("/")
      #split the LatestSprintVersionNumber=x.x.xxxx.xx parameter into 2 bits ('LatestSprintVersionNumber and 'x.x.xxxx.xx')
      items = aqConvert.VarToStr(items[1]).split("=")
      #check if the first item in position [0] in items array equals to 'LatestSprintVersionNumber'
      if aqConvert.VarToStr(items[0]) == "LatestSprintVersionNumber":
         #check if the value appears in the app in the help-->about window equals to the second item in position [1] in items array
         if VersionFromTheApp == aqConvert.VarToStr(items[1]):
           Log.Message("The latest sprint version passed via the command line is " + aqConvert.VarToStr(items[1]))
           Log.Message("The installed version is " + VersionFromTheApp)
           Log.Message("Both, latest sprint build version and the installed one are the same")
        else:
           Log.Message("The latest sprint version passed via the command line is " + aqConvert.VarToStr(items[1]))
           Log.Message("The installed version is " + VersionFromTheApp)
           Log.Message("The latest sprint build version and the installed one are not the same")

cancel
Showing results for 
Search instead for 
Did you mean: