Forum Discussion

ilkoTest's avatar
ilkoTest
Occasional Contributor
27 days ago

Running the Execution Plan enabled items via script within TestComplete

Hi,

I have a huge test project that contains hundreds of test items. Unfortunately, TestComplete does not provide a progress indicator for the test execution. The entire project runs for many hours, and it would be great to see how many test items were executed.

I am trying to write a JavaScript script that can execute the enabled test items in the Execution Plan one after another and show me the execution progress.

I am stuck at the point where I am trying to execute the following command block:

if (itemSelected.Enabled)
{
  Log.Message("The selected item is enabled");
  var progress = Math.round((i / count) * 100);
  Log.Message("The progress value is: " + progress);
  
  Indicator.PushText("Running: " + itemSelected.Name + " (" + progress + "% Complete)" + "out of " + count);
  
  try {
    itemSelected.Run();
  }
  catch(e){
    Log.Error("Error executing " + itemSelected.Name + ": " + e.message);

  }
  Indicator.PopText();
}
else
{
  Log.Message("The current item is disabled in the Execution Plan");
}

TestComplete throws the error saying that 

Error executing <itemSelectedName>: itemSelected.Run is not a function

If I remove the brackets after Run, TestComplete ignores this command and iterates to the next item.

 I was wondering if anybody has any idea how to overcome this and run the selected test items via script.

Thanks

11 Replies

    • ilkoTest's avatar
      ilkoTest
      Occasional Contributor

      Thank you for your reply. While the TestComplete Command Line seems a good solution for running the tests, I don't think it will support the progress indicator, which is my primary focus of why am I doing all of this

      • rraghvani's avatar
        rraghvani
        Icon for Champion Level 3 rankChampion Level 3

        PowerShell can display a progress bar via Write-Progress

        For unattended automation, I would recommend a combination of progress/status + logging + failure notification. A progress bar alone isn't sufficient because it can't tell you whether a job has silently failed.

  • eykxas's avatar
    eykxas
    Frequent Contributor

    Hi !

    How do you initialize "itemSelected" ? I think the problem is here. I'm pretty sure "ItemSelected" does not expose a Run() function.

    • ilkoTest's avatar
      ilkoTest
      Occasional Contributor

      This is JavaScript code. The initialization is done by assigning a value to the itemSelected:

      for (var i = 0; i < count; i++)
        {
          var itemSelected = testItems.TestItem(i);

      And you're right; it does not expose the Run() function, which I am getting an error for. 

  • AlexKaras's avatar
    AlexKaras
    Community Hero

    Hi,

    TestItem object does not expose .Run() method. That is why you are getting the error.

    Somewhere in time when I've implemented similar functionality, I parsed ElementToBeRun property to get names for corresponding script unit and function to be called and executed corresponding code via Runner.CallMethod() call.

    Hope this will help...

     

  • MW_Didata's avatar
    MW_Didata
    Frequent Contributor

    The Executionplan is saved in your {ProjectName}.mds file.
    its in xml so you could have Testcomplete count all items and calculate that to a percentage.

    Then with Indicator.PushText() you can display it on your screen.

    But it sounds like more trouble than its worth.

    • AlexKaras's avatar
      AlexKaras
      Community Hero

      Hi,

      Actually, one can get a number of test items in the project plan via Project.TestItems.ItemCount property. Then one can iterate over project plan, count the number of enabled test items (see code example in the help topic for the Project.TestItems.ItemCount property), convert to percentage and visualize the result via Indicator object as it was suggested by MW_Didata.

      The case here (if nothing changed during past several years since the time when I implemented something similar) was that groups in project plan look pretty much as test items and it is not that easy to distinguish group from actual test item. And this resulted in somewhat 'strange and visually unclear' behavior of the tests run progress displayed by the Indicator object.

       

    • ilkoTest's avatar
      ilkoTest
      Occasional Contributor

      Thank you for your suggestion.

      I believe this solution will create a lot of trouble by dynamically opening and reading the .mds file, which is used by the same project. I'd rather manually monitor the progress by comparing the test name with a table of all test cases.