Skip to main content

Content Starts Here

Run the specified group of test items via TestComplete's command line

Article
The sample below shows how to run the specified group of test items via TestComplete's command line.
  • 1. Create a RunTestItemGroup.js (or RunTestItemGroup.vbs) file with the following contents.
  • 2. To open a TestComplete project and run a group of test items, run the RunTestItemGroup.js (or RunTestItemGroup.vbs) script with the appropriate command-line arguments, e.g. the following command line will open the TestProjectTestForRunFromCommandLine.pjs project suite in TestComplete 9 and execute the Group1 test items group in the TestProject81 project:

    "<PathTORunTestItemGroupjs>\RunTestItemGroup.js" "<PathToTestProjectTestForRunFromCommandLine>\TestProjectTestForRunFromCommandLine.pjs" /p:TestProjectTestForRunFromCommandLine /testitemgroup:ProjectTestItem

    or

    "<PathTORunTestItemGroupvbs>\RunTestItemGroup.vbs" "<PathToTestProjectTestForRunFromCommandLine>\TestProjectTestForRunFromCommandLine.pjs" /p:TestProjectTestForRunFromCommandLine /testitemgroup:ProjectTestItem

VBScript


' RunTestItemGroup.vbs

Dim testItemGroup, project, objArgs, projectSuite

Set objArgs = WScript.Arguments
projectSuite = objArgs(0)

Set objRegExp = New RegExp

For i = 1 To objArgs.length-1
  
  objRegExp.Pattern = "/testitemgroup:(\w+)"
  If (objRegExp.Test(objArgs(i)) = True) Then
    testItemGroup = objRegExp.Replace(objArgs(i), "$1")
  End If
  
  objRegExp.Pattern = "/project:(\w+)"
  If (objRegExp.Test(objArgs(i)) = True) Then
     project = objRegExp.Replace(objArgs(i), "$1")
  End If
  
  objRegExp.Pattern = "/p:(\w+)"
  If (objRegExp.Test(objArgs(i)) = True) Then
    project = objRegExp.Replace(objArgs(i), "$1")
  End If
  
Next

Set objRegExp = Nothing

Dim tc, tci, ProjectTestItems
Set tc = CreateObject("TestComplete.TestCompleteApplication.9")

Set tci = tc.Integration
tc.Visible = True
tci.OpenProjectSuite(projectSuite)
Set ProjectTestItems = tci.TestSuite(project)
tci.RunProjectTestItem project, testItemGroup
  

JScript


// RunTestItemGroup.js

var testItemGroup, project;

var objArgs = WScript.Arguments;
var projectSuite = objArgs(0);

for (i = 1; i < objArgs.length; i++)
{
  if (objArgs(i).search(/\/testitemgroup:/i) != -1)
  {
    testItemGroup = objArgs(i).replace(/\/testitemgroup:/i, "");
  }
  if (objArgs(i).search(/\/p:/i) != -1)
  {
    project = objArgs(i).replace(/\/p:/i, "");
  }
  if (objArgs(i).search(/\/project:/i) != -1)
  {
    project = objArgs(i).replace(/\/project:/i, "");
  }
  if (objArgs(i).search(/\/project:/i) != -1)
  {
    project = objArgs(i).replace(/\/project:/i, "");
  }
}

var tc = new ActiveXObject("TestComplete.TestCompleteApplication.9");

var tci = tc.Integration;
tc.Visible = true;
tci.OpenProjectSuite(projectSuite);
ProjectTestItems = tci.TestSuite(project);
tci.RunProjectTestItem(project, testItemGroup);
  

Python


#RunTestItemGroup.js
import re #The module re provides full support for Perl-like regular expressions in Python
def test():
  objArgs = WScript.Arguments
  projectSuite = objArgs(0)
  
  for i in range(len(objArgs)):
    if re.search('/testitemgroup:/i',objArgs(i)) != -1 :
      testItemGroup = re.sub('/testitemgroup:/i',"",objArgs(i))
    if re.search('/p:/i',objArgs(i)) != -1:
      project = re.sub('/p:/i',"",objArgs(i))
    if re.search('/project:/i',objArgs(i)) != -1:
      project = re.sub('/project:/i',"",objArgs(i))
    if re.search('/project:/i',objArgs(i)) != -1:
      project = re.sub('/project:/i',"",objArgs(i))
  tc = Sys.OleObject["TestComplete.TestCompleteApplication.9"]
  tci = tc.Integration
  tc.Visible = True
  tci.OpenProjectSuite(projectSuite)
  ProjectTestItems = tci.TestSuite(project)
  tci.RunProjectTestItem(project, testItemGroup)
  
Downloads:
TestProjectTestForRunFromCommandLine.zip
Previous MonthNext Month
SunMonTueWedThuFriSat