joseph_michaud's avatar
11 years ago
Status:
Implemented

select/run test by test item using command line

In the same fashion that you can select and then run a test item or test item group while viewing the project in TestComplete, it would similarly be useful to be able to select a project test item or test item group and run it with the TestComplete or TestExecute using the command line.  So if the project items look like this:

 

project.PNG

 

So we might run some tests like this:

 

TestExecute.exe TestProject14.pjs /run /project:TestProject14 /projectitem: Group1

TestExecute.exe TestProject14.pjs /run /project:TestProject14 /projectitem: ProjectTestItem2

TestExecute.exe TestProject14.pjs /run /project:TestProject14 /projectitem: Group2

 

 

 

Perhaps overloading the /projectitem flag is not a good idea?  Then use a new flag, say, ... "/item".

 

TestExecute.exe TestProject14.pjs /run /project:TestProject14 /item: Group1

TestExecute.exe TestProject14.pjs /run /project:TestProject14 /item: ProjectTestItem2

TestExecute.exe TestProject14.pjs /run /project:TestProject14 /item: Group2

 

Should we honor or disregard the Enabled selection for the items and groups in the project?  Or perhaps honor it by default, and force execution if a "/force" flag is used?  For example, where TestItem2 is not enabled:

 

TestExecute.exe TestProject14.pjs /run /project:TestProject14 /item: ProjectTestItem2 /force

 

 

10 Comments

  • There is a way you can do this currently. See this article here:

     

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

     

    Which can then be put into a console application as well to run as a scheduled task:

     

        class Program
        {
            static void Main(string[] args)
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Expecting arguments");
                    Console.Write("Press any key to continue...");
                    Console.ReadLine();
                }
                else
                {
                    string testItemGroup = "";
                    string project = "";
    
                    for (int i = 0; i < args.Length; i++)
                    {
                      if (Regex.IsMatch(args[i], @"\/testitemgroup:", RegexOptions.IgnoreCase))
                      {
                          testItemGroup = Regex.Replace(args[i], @"\/testitemgroup:", "", RegexOptions.IgnoreCase);
                      }
                      if (Regex.IsMatch(args[i], @"\/p:", RegexOptions.IgnoreCase))
                      {
                          project = Regex.Replace(args[i], @"\/p:", "", RegexOptions.IgnoreCase);
                      }
                      if (Regex.IsMatch(args[i], @"\/project:", RegexOptions.IgnoreCase))
                      {
                          project = Regex.Replace(args[i], @"\/project:", "", RegexOptions.IgnoreCase);
                      }                
                    }
    
                    TestFunc(args[0], project, testItemGroup);
                }
                
            }
    
            private static void TestFunc(string projectSuite, string project, string testItemGroup)
            {
                const string TCProgID = "TestComplete.TestCompleteApplication.10";
                object TestCompleteObject = null;
    
                // Obtains access to TestComplete
                try
                {
                    TestCompleteObject = Marshal.GetActiveObject(TCProgID);
                }
                catch
                {
                    try
                    {
                        TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
                    }
                    catch
                    {
                    }
                }
    
                if (TestCompleteObject == null) return;
    
                // Obtains ITestCompleteCOMManager 
                TestComplete.ITestCompleteCOMManager TestCompleteManager = (TestComplete.ITestCompleteCOMManager)TestCompleteObject;
                // Obtains Integration object
                TestComplete.ItcIntegration IntegrationObject = TestCompleteManager.Integration;
    
                // We have a reference to the integration object.
                // Now we can use its methods and properties to automate TestComplete.
    
                // Loads the project suite
                IntegrationObject.OpenProjectSuite(projectSuite);
    
                // Checks whether the project suite was opened
                // If the project suite cannot be opened, closes TestComplete
                if (!IntegrationObject.IsProjectSuiteOpened())
                {
                    Console.WriteLine("Could not open the project suite.");
                    // Closes TestComplete
                    TestCompleteManager.Quit();
                    // Releases COM objects
                    Marshal.ReleaseComObject(IntegrationObject);
                    Marshal.ReleaseComObject(TestCompleteManager);
                    Marshal.ReleaseComObject(TestCompleteObject);
                    return;
                }
    
                try
                {
                    // Runs the test
                    IntegrationObject.RunProjectTestItem(project, testItemGroup);
    
                    // Waits until testing is over
                    while (IntegrationObject.IsRunning())
                        Thread.Sleep(5000);
    
                    // Check the results
                    switch (IntegrationObject.GetLastResultDescription().Status)
                    {
                        case TestComplete.TC_LOG_STATUS.lsOk:
                            Console.WriteLine("The test run finished successfully.");
                            break;
                        case TestComplete.TC_LOG_STATUS.lsWarning:
                            Console.WriteLine("Warning messages were posted to the test log.");
                            break;
                        case TestComplete.TC_LOG_STATUS.lsError:
                            Console.WriteLine("Error messages were posted to the test log.");
                            break;
                    }
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    Console.WriteLine("An exception occurred: " + ex.Message);
                }
                finally
                {
                  
                    // Closes TestComplete
                    TestCompleteManager.Quit();
                    // Releases COM objects
                    Marshal.ReleaseComObject(IntegrationObject);
                    Marshal.ReleaseComObject(TestCompleteManager);
                    Marshal.ReleaseComObject(TestCompleteObject);
                }
            }
        }