Forum Discussion

scambias's avatar
scambias
Contributor
6 years ago

TestComplete: enable/disable Test items list via COM Object

Hi all,

 

I recently started building an external C# application to drive TestComplete (it would be better to do this with TestExecute though) to run some specific test items.

I need to get (via COM) the list of test items of a project, enable/disable part of them, and then run them.

I open the suite (according to the code in the help file) but actually don't know how to get the test items list starting from the

TestComplete.ItcIntegration IntegrationObject

or from 

TestComplete.ItcProjectIntegration project = IntegrationObject.get_Project("DBW_test_environment");

 

Can anybody help me?

Is there a sort of documentation of the COM model of TestComplete/TestExecute?

 

Many thanks in advance

Silvio

7 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Silvio,

     

    I am far not sure if it is possible to modify state of test items via TestComplete COM if test project is opened in TestComplete.

    What I did, was to enable all/required test items via direct modification of the project file with the help of standalone .js script and then open project in TestComplete.

    Note 1: Provided code sample worked in TC 12.

    Note 2: Obviously, the same code might not work in subsequent versions of TC.

      var oXml = GetDefaultXMLObj();
      var xmlDoc = loadXML(oXml, projectFile);
    
    //WScript.Echo("Test Items : '" + testItems + "'");
      if ("" == testItems)
      {
        testItemXPath = "//*/testItems/children//testItem";
        testItems = xmlDoc.selectNodes(testItemXPath);
    
        for (testItemIdx = 0; testItemIdx < testItems.length; testItemIdx++)
        {
          element = testItems[testItemIdx];
    
          if (null != element)
          {
            if ("False" == element.getAttribute("enabled"))
            {
              element.setAttribute("enabled", "True");
    //          WScript.Echo("'" + element.getAttribute("name") + "' test item was enabled");
            }
          }
        }
        WScript.Echo("All test items for the project were enabled");
      }
      else
      {
        testItems = testItems.split('~');
        for (testItemIdx in testItems)
        {
          testItem = testItems[testItemIdx];
    //WScript.Echo(testItem);
          testItemXPath = "//*/testItems/children//testItem[@name='" + testItem + "']";
          element = xmlDoc.selectSingleNode(testItemXPath);
    
          if (null != element)
          {
            if ("False" == element.getAttribute("enabled"))
            {
              element.setAttribute("enabled", "True");
              WScript.Echo("'" + testItem + "' test item was enabled");
            }
          }
          else
            WScript.Echo("'" + testItem + "' test item was not found");
        }
      }
      xmlDoc.save(projectFile);
    

     

    • scambias's avatar
      scambias
      Contributor

      Hello Alex,

       

      first of all thank you for your reply.

      I will try then to parse the xml file using that code you suggested.

      I had another idea I want to share with you:

      1. suppose I create a vbs script inside TC that can get the test items collection, enable/disable them according to a provided parameter and that's it.

      2. I then could run TextExecute with that routine to setup the test items accordingly and then

      3. run Testexecute with the entire project, expecting to run just the test items selected by the point 2.

      How do you see this?

      If that works, it could be easier to maintain because it would be inside TestComplite IDE as the tests themselves.

       

      Thanks in advance,

      Silvio

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi Silvio,

         

        I am not sure that I got your idea with point #1...

        If you are inside TestComplete, then just set state of test items as required, save the project and open it with TestExecute.

        If you execute script that changes state of test items while the project is opened in TestComplete, then you should get a warning from TC that project file was changed and whether or not you like to reload it. If you reload, then you will have to save it and again, I don't see the purpose of opening project in TC. If you choose not to reload, then you must be very careful to not save project occasionally, because if you save the project in TC, this will overwrite changes made by the script.

         

        Did I miss something in your idea?