joseph_michaud's avatar
9 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

  • So I stumbled across the ability to run TestComplete and TestExecute via command line.

     

    The issue I'm seeing is that I don't see an easy way to run TC and TE by group. I've attached a screen shot of what my project file looks like. I'd like the ability to run just the SmokeTest group or the Day2Tests group, but I haven't seen a way to do it.

  • 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);
                }
            }
        }

     

     

  • NisHera's avatar
    NisHera
    Valued Contributor

    Currently only Project items could be run from command line.

    If test items could be run, it would be really usefull.........

  • Ravik's avatar
    Ravik
    Super Contributor

    Try this, it may be help you and achieved your requirement partially.

     

    echo**********************************************************************
    echo                     TEST SUITE ITEMS
    echo**********************************************************************

    echo TP001_TestItem1
    echo TP002_TestItem2
    echo TP003_TestItem3
    echo TP004_TestItem4
    echo TP005_TestItem5

    echo **********************************************************************


    set /p "Input = Please select any one suite, from TEST SUITE ITEMS"
    echo %Input %
    "C:\Program Files (x86)\SmartBear\TestExecute 11\Bin\TestExecute.exe" "C:\XZY Automation\ProjectSuites\XZY_Automation\XZY_Automation.pjs" /r /p:XZY_Automation /u:TP_XZY /rt:%Input % /exit /SilentMode

      

     

    Save above code as .bat and run it. it will ask you to select a specific TestItem. when you enter your specific item, TestExecute run it.

  • td's avatar
    td
    Regular Visitor

    Hi,

     

    We solved this issue by using the following Gradle/Groovy-based code, that updates the TC12 project to enable only the wanted test items to run:

     

     

        def patchMdsFile(Project project, File mdsFile) {
            def testItemToEnable = project.properties.testItem
            if (!testItemToEnable)
                throw new GradleException('Please set the `testItem` parameter (string containing the name of the test item to enable).')
            project.logger.lifecycle("Enabling test item ${testItemToEnable} in ${mdsFile}...")
    
            def mdsRoot = new XmlParser(false, false, true).parse(mdsFile)
    
            def projectVersion = VersionNumber.parse(mdsRoot.@version.toString())
            project.logger.info("Detected project version ${projectVersion}")
    
            if (projectVersion < VersionNumber.parse('12.0.0'))
                throw new GradleException("The project file uses an unsupported TestComplete version (${projectVersion}). Please upgrade your project to version 12 or above.")
    
            mdsRoot.testItems.children.testItem.each {
                def isEnabled = it.@name == testItemToEnable
                project.logger.info("Test item '${it.@name}' enabled flag: ${isEnabled}")
    
                it.@enabled = isEnabled
            }
    
            mdsFile.write(XmlUtil.serialize(mdsRoot))
        }

     

  • Status changed:
    Selected for Development
    to
    Implemented

    Hello,

     

    This functionality has been implemented in TestComplete 12.40.