dorian's avatar
Regular Visitor
7 years ago
New Idea

Run the test hold by a TestItem



Since I am too limited by the way tests are run in the View>Organize Tests panel, I was happy to find I can code my own run logic by accessing TestItems by scripting ( ). Unfortunately, this interface seems to be for display only because there is no way to run the KeywordTest or script held in the test item.


I found a bit strange there exists a property TestItem.ElementToBeRun but no method to actually run it !

The workaround is to parse the caption string, but this is ugly and vary if it's a script or keyword test. Finally, there is no way to access arguments specified in the Organize Test panel


In brief: add a .run method to TestItem or TestItemElement which call the associated KeywordTest or script function


Bonus: add a new property which point to the KeywordTest object (or script)

Bonus 2: add a way to access arguments given to this TestItem




  • tristaanogre's avatar
    Esteemed Contributor

    Why be restricted to the Test Items anyways?  Write a script routine or a keyword test that runs all your test cases in the order you want with any execution logic you want.  Make that the sole test item in your project and run your project.

    If you're concerned about logging organization, utilize the Log.AppendFolder, PushFolder, PopFolder functions to build a collapsable tree of logging items to organize your test log.

  • dorian's avatar
    Regular Visitor

    You are right,  I can do that. But I find it much more easier/faster to organize tests items with a GUI : I can move items up/down, drag to create new tests, create new tests groups with a click, and what I use the most is enable/disable some test items to debug or select what part of tests I want to run.


    In fact, the first thought I had was : instead of TestItems and KeywordTests which are similar yet can't be used the same way, it would be much more logical and clean to have a generic Test object, which is sub-classed as KeywordTest, or ScriptTest, or TreeTest. A TreeTest being just a tree structure with enable/disable checkboxes and come with a GUI (but can also be accessed by script). See: a KeywordTest can be already a list of other KeywordTest, which can be enabled/disabled (via right click menu), we just miss the variation with a tree instead of a list.


    This way you can call a TreeTest in a KeywordTest or all kind of nesting you want, and use the checkbox GUI to enable/disable or organize any kind of object you want. But I understand this is not how TestComplete was designed and implement it now would maybe require lot of change.

  • dorian's avatar
    Regular Visitor

    FWIW here is the code I use:


    function run_test_from_testitem(testitem) {
      var caption = testitem.elementToBeRun.Caption
      var start = aqString.Find(caption, "KeywordTest");
      var tiret = aqString.Find(caption, " - ");     
      if(start == -1) {
        // script
        // caption: "Script\combinations - run_xxxxx"
        var file_name = caption.substr(7, tiret-7)
        var test_name = caption.substr(tiret+3, 200)
        var code = file_name + "[\"" + test_name + "\"]()"
        try {
        } catch(e) {
          Log.Error("Error: script unit not imported: " + file_name)
          throw e
        } else {
        // keyword test
          var test_name = aqString.SubString(caption, tiret+3,200);
          KeywordTests[ test_name ].Run();