cancel
Showing results for 
Search instead for 
Did you mean: 

TestComplete: enable/disable Test items list via COM Object

Contributor

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
Community Hero

Re: TestComplete: enable/disable Test items list via COM Object

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

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Contributor

Re: TestComplete: enable/disable Test items list via COM Object

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

Community Hero

Re: TestComplete: enable/disable Test items list via COM Object

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?

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Contributor

Re: TestComplete: enable/disable Test items list via COM Object

Hello Alex,

 

well my plan is to have a msdos batch file containing two TestExecute command line statements:

  • the first one command line where I specifically run that vbs script routine to set-up all the testitems I want to run
  • whereas the second TestExecute command specifies the project containing the test items.

I guess it should be possible, when exiting testExecute, that the modifications are saved into the xml project file so the second run will find that ready to be used.

Community Hero

Re: TestComplete: enable/disable Test items list via COM Object

Silvio,

 

I'm still not sure that it is clear to me:

-- Are you going to specify on the first command line just test items to be enabled without specifying the test project?

 

P.S. It looks like we had something like you want to implement in one of our projects: we had a parent 'wrapping' comand file that called several child ones. It was possible to pass to the parent file the full path to the test project file and a list of test items to be executed (if the list was empty this meant that all test items should be executed). The first child called by the parent was command file that reverted all local changes made to the test sources (this is to ensure no merging problems) and updated test sources to their latest version. Then the .js script was called that set the state of test items as required via direct modification of the test project file (see code snippet above). And, finally, the last command file triggered TestExecute that used already prepared test project file.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Contributor

Re: TestComplete: enable/disable Test items list via COM Object

Hi Alex,

 

well my goal is, with the first TextExecute call, to prepare the test items for the second call (i.e. enable/disable a subset according to a parameter I may providevia external file that the vbs will be able to read data from).

I'll give you an example:

suppose I have a test suite (mySuite.pjs) with a project (call it myTestProject.mds) having two test groups:

NOREGRESSION_TESTS, with 12 test items

and

PERFORMANCES_TESTS, with 8 test items.

Then I write a vbs (name it testsetup.vbs with a routine called "prepareTests") placed inside the myTest.mds project, that is able to enable all the NOREGRESSION_TESTS or PERFORMANCES_TESTS according to a parameter.

My first call to TestExecute could be (supposing I wrote onto a parameter.txt file the word NOREGRESSION_TESTS) :

TestExecute.exe "C:\Work\SmartBear\TestExecute\Projects\mySuite.pjs" /r  /exit /p:myTestProject /u:testsetup /rtSmiley TonguerepareTests

My second call would be:

"C:\Work\SmartBear\TestExecute\Projects\mySuite.pjs" /r  /exit /p:myTestProject

 

The prepareTest sub would read from the parameter.txt file the group of tests that must be enabled and do that accordingly. Exiting I expect that those setting would be saved (as in Testcomplete) so the second call would get those tests enabled and execute them.

 

I hope I was clear on this!

It's a bit tricky and in order to do this you need external files describing the tree of test items (for me just simply the two groups but sometimes I guess I would need to be more deeply specific with that enabled list).

 

What I wanted to avoid was just that step, that's why I wante to read all the test items via COM (of course using a hidden TestComplete instance, which performs all the COM requests) with a C# form application, let the user via a UI choose what to set/unset, save the project and close all, leaving to the TestExecute command line (just the second one) the test execution.

 

Highlighted
Community Hero

Re: TestComplete: enable/disable Test items list via COM Object

Hi Silvio,

 

Well, it is not possible to programmatically change the state of test items from within TestComplete/TestExecute according to my knowledge.

Thus, I would suggest these two options (conceptually they are pretty similair and selection of this or that one will probably depend on your personal preferences and implementation conveniences):

-- Instead of executing the code that sets the state of test items from within TestExecute, you need to create a standalone script and execute it out of TestExecute. This script will enable the required test item(s) via direct modification of the project file as discussed previously. Then you will start TestExecute with the command line parameter specifying what test item must be executed.

-- If you like to have interactivity, you may consider to create a User Form in your test project and create a code that will get the list of project test items, populate User Form with this list and display the form to end-user. End user will specify (via Ctrl-clicking) what test items must be executed. Names of the selected test items are saved then to the external file (e.g. parameter.txt) and TestComplete/TestExecute must quit. The obtained file is then processed by the above standalone script.

 

P.S. Note, that if test items in your test project are organized hierarchically, only the initial test item that test execution starts from must be enabled. Its parent item(s) may be enabled or disabled. The state of child items defines whether or will they be executed during test run.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Share Your Stories
Read Latest News
Top Kudoed Authors