Forum Discussion

qian's avatar
qian
Occasional Contributor
14 years ago

How to run a set of selected test items repeatly from tc8 script in tc8

Hi, i can repeatly run (using for loop) a set of selected test items in tc5 by call testsuite.run() in a for loop script after adding some .dll file for tc3 compatiblity in tc5. but after updated to tc8, all failed. i caheck help file and it seems no such support in tc8. of course, i knew tc8 project can be call/run externally, say, from msbuild or whatever. but this is not what i want to do.



is there any way i can run a set of test items repeatly (by using run project or any other ways) in tc8? this is very good for run something overnight form tc itself.



thanks in advance for any help.

Qian

3 Replies


  • Hi,





    Unfortunately, there is no way to run test items from scripts, but you can create batch test runs and launch test items the needed number of times.





    If this is unacceptable, please clarify your task so we can try to suggest a suitable solution.
  • stref's avatar
    stref
    Occasional Contributor

    It can be done. You have access to the test items from Script like this:



      var testcaption = Project.TestItems.TestItem(0).ElementToBeRun.Caption;



    The test item caption will look something like "Script\Unit1 - Dlg"



    That tells you it's a script, the unit name and function name to execute. From there you could use the eval method (JScript) and call the function after parsing out the name:



    eval(ParseElementToBeRun(testcaption));



    Of course, ParseElementToBeRun is left as an exercise for the reader.  :)



    Good luck,

    -Steve

    Get Trained!  http://www.automatedqa.com/support/training/





  • Hi Steve,





    Thanks for the correction. You are right, with one correction from my side though: your approach is applicable to those Test Items that are linked to script routines only.

    This is not always the case in TestComplete.





    Anyway, below, is a sample script implementing the suggested idea. The sample script iterates through all Test Items and runs those that are enabled and linked to a script routine:







    function Test()

    {

      var curTestItem = new Array(Project.TestItems.ItemCount - 1);

      var counter = 0;

      Log.Message("Executing the enabled test items");

      for (i = 0; i < Project.TestItems.ItemCount; i++)

        if (Project.TestItems.TestItem(i).Enabled) {

          curTestItem[counter] = Project.TestItems.TestItem(i);

          counter++;

       }

      for (i = 0; i < counter; i++)

        Log.Message(curTestItem.ElementToBeRun.Caption);

      for (i = 0; i < counter; i++)

        runTestItemRoutine(curTestItem);

    }





    function runTestItemRoutine(testItemObject)

    {

      var caption = testItemObject.ElementToBeRun.Caption.split("\\");

      if (caption[0] == "Script") {

        var script = caption[1].split(" - ");

        Runner.CallMethod(script[0] + "." + script[1]);

     }

    }