Forum Discussion

obaid_shirwani's avatar
obaid_shirwani
Contributor
11 years ago
Solved

Executing Test Group using command prompt

Hi folks,

 

I am facing an issue while executing a Test Group using command prompt.

 

I have a project which has three Test Groups having sub-folders with TestSteps in it. View image: TestGroups.png

 

I have to launch TestComplete using command prompt and execute anyone of these Test Groups at a time.

 

I am using the following two approaches:

 

1. Using command prompt directly and executing the following command to launch and execute the SECOND Test Group:

 

"C:\Program Files (x86)\SmartBear\TestComplete 10\Bin\TestComplete.exe" "D:\GitShared\qatestautomation\eWorkspace\IbexAutomation\IBEXGlobal\IBEXGlobal.pjs" /r /project:Portal /testitemgroup:"USPayroll"

 

This launches TestComplete successfully. However, it executes the first Test Group instead of the mentioned Second Test Group. I have to manually disable the first Test Group in order to launch the second Test Group. 

 

What am I missing here?

 

2. Using ActiveX to do the same as above:

 

The second approach is about launching TestComplete using ActiveX and executing the above, using a JS file. However, I am getting an message.

 

The JS file contents are:

http://support.smartbear.com/viewarticle/54654/

 

// 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.10");

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

 

//End of File

 

I am using the following command to launch this JS file:

 

"D:\GitShared\qatestautomation\eWorkspace\IbexAutomation\IBEXGlobal\RunTestItemGroup.js" "D:\GitShared\qatestautomation\eWorkspace\IbexAutomation\IBEXGlobal\IBEXGlobal.pjs" /p:Portal /testitemgroup:"USPayroll"

 

Executing this is giving me the following error message: View image: Error.png

 

What is missing here.

 

Help needed.

 

Regards,

 

OS

 

 

 

 

 

  • Hi Anne,



    I think wmic chokes on the parentheses in the WHERE clause. Writing it like where (X and Y or M and Q) should work, because AND has higher priority than OR.

    A few notes:

    - There is no need to wrap the command into the powershell call - wmic is a standard Windows command.

    - I wouldn't recommend attempting to terminate TestComplete from a TestComplete script. :) I changed that to AnotherApp.



    var oShell = Sys.OleObject("WScript.Shell");

    var strCmd = "wmic process where" +

      " (CommandLine like '%Higgens%' and name like '%Higgens%'" +

      " or CommandLine like '%AnotherApp%' and name like '%AnotherApp%')" +

      " call terminate";



    // Run the command and get the exit code

    var res = oShell.Run(strCmd, 0 /* run in background */, true /* wait for completion */);

    if (res != 0) {

      Log.Message("WMIC command failed; exit code " + res);

    }



    Just for completeness: here's a version that uses WMI scripting objects. It's a bit longer, but may be more convenient to use for handling errors and troubleshooting.



    var oWMI = GetObject("winmgmts://./root/cimv2");

    var colItems = oWMI.ExecQuery(

      "SELECT * FROM Win32_Process WHERE"

      + " CommandLine LIKE '%Higgens%' AND Name LIKE '%Higgens%'"

      + " OR CommandLine LIKE '%AnotherApp%' AND Name LIKE '%AnotherApp%'");

    var enumProcesses = new Enumerator(colItems);



    var p;

    while (!enumProcesses.atEnd()) {

      p = enumProcesses.item();

      try {

        p.Terminate();

      }

      catch (e) {

        Log.Message(

          aqString.Format("Failed to terminate the process '%s' with handle %d. Error %d: %s.", p.Name, p.Handle, e.number, e.message),

          p.GetObjectText_()

        );

      }

      enumProcesses.moveNext();

    }