Forum Discussion

sjwalter's avatar
sjwalter
New Contributor
15 years ago

DDT with Project Test items

I've watched the DDT webinar, but have trouble seeing how I can solve my problem with my script based tests. Everything I find talks mainly about running DDT loops against Keyword tests, whereas all my tests are scripts.



Basically I have a slew of tests, written in TC8.1, arranged on the Test Items tab for the (one) project in the suite. See attachment 1. These run fine and are driven by several Project.Variables. I have to run these tests for different values of those project variables. At the moment I have routines that set those variables for one or other of the test cases I wish to run, which I run manually, and then I hit F5 to run the tests that I've selected.



What I would like to do is to describe those different parameter sets in, say, an Excel spreadsheet and then to run Platform Iteration as many times as I have rows in the sheet. That is, I would like to have something like I've mocked up in attachment #2 - a head "test" perhaps (just a script function) that is akin to a driven DDT function as described for the keyword tests, and which represents one iteration of the tests and which sets up the variables so that the underlying tests run. Is this do-able? Or am I going about it the wrong way? Or am I being as clear as mud?  :-)



Any help gratefully received



Stephen

14 Replies

  • Thanks a lot for your help Jaycon :-). Now the main script seems to work fine, but I have another problem.



    I'm using two variables Project.Variables.user and Project.Variables.password which need to  be passed between tests. No matter if I define them in the main() or the recursiveTraverse(Level)  before the first iteration, I get a printout that they are initialized but once I try to use them from a test in the recursion they are always empty  :-(






    function main()

    {

      var Driver;

      Driver = DDT.ExcelDriver("c:\\logon.xlsx", "MKD", true);  

      RecNo = 0;

      Project.Variables.user = DDT.CurrentDriver.Value('user');

      Log.Message(Project.Variables.user);

      Project.Variables.password = DDT.CurrentDriver.Value('password');

      Log.Message(Project.Variables.password);


      while (!Driver.EOF())

      { 

        recursiveTraverse(Project.TestItems); 

        Driver.Next(); 

      } 

      DDT.CloseDriver(Driver.Name); 








    function recursiveTraverse(Level) 

    {

      var Items = Level.ItemCount;  

      Project.Variables.user = DDT.CurrentDriver.Value('user');

      Log.Message(Project.Variables.user);

      Project.Variables.password = DDT.CurrentDriver.Value('password');

      Log.Message(Project.Variables.password); 

      var accounts = Database.getAccounts(Project.Variables.user);

      for(var i = 0; i <=(Items-1); i++)

      { 

        runTestItemRoutine(Level.TestItem(i)); 

        recursiveTraverse(Level.TestItem(i)); 

      }






    It doesn't make any difference if they are defined as temporary or persistent either. This really defeats the whole purpose of using project variables for holding data between tests, so i assume I'm doing something wrong this time as well.



    Best Regards,

       Ilija


  • I assume it has to do something with the dafult and local value, after cheking it the default value is " " and local value has the right values, but cannot figure it out ...
  • Further investigation has shown that no matter if the variables are of Object type and initialized in main() or any other script in the recursion, they are becoming empty once passed to another test. I moved the initialization code to unit Init as on the screenshot without success.



    Because of the above it can be concluded that the error is in the recursion script:






    //USEUNIT Database





    function Main()

    {

      var Driver;

      Driver = DDT.ExcelDriver("c:\\logon.xlsx", "MKD", true);  

      RecNo = 0;

      Database.resetPass();

      while (!Driver.EOF())

      { 

        recursiveTraverse(Project.TestItems); 

        Driver.Next(); 

      } 

      DDT.CloseDriver(Driver.Name); 



      

    function recursiveTraverse(Level) 

    {

      var Items = Level.ItemCount;  





      for(var i = 0; i <=(Items-1); i++)

      { 

        runTestItemRoutine(Level.TestItem(i)); 

        recursiveTraverse(Level.TestItem(i)); 

      }







    function runTestItemRoutine(TestItemLevel)



      if (TestItemLevel.ElementToBeRun != null)

      {            

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

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

        {

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

          if (script[1] != "Main") 

          {

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

          }

        }

      }

    }



      

    function recursiveTraverse(Level) 

    {

      var Items = Level.ItemCount;  





      for(var i = 0; i <=(Items-1); i++)

      { 

        runTestItemRoutine(Level.TestItem(i)); 

        recursiveTraverse(Level.TestItem(i)); 

      }







    function runTestItemRoutine(TestItemLevel)



      if (TestItemLevel.ElementToBeRun != null)

      {            

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

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

        {

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

          if (script[1] != "Main") 

          {

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

          }

        }

      }

    }





    and Init contains:




    function Init()

    {  

        user = DDT.CurrentDriver.Value('user');

        Log.Message(user);

        password = DDT.CurrentDriver.Value('password'); 

        Log.Message(password);

        accounts = Database.getAccounts(user);

        Log.Message(accounts);

    }



    If anyone has managed to recursively run Test Items with a DDT driver and use project variables at the same time, help will be greatly appreciated



    Thanks in Advance,

           Ilija

       
  • Here is the solution:




    function runTestItemRoutine(TestItemLevel)



      if (TestItemLevel.ElementToBeRun != null)

      {            

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

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

        {

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

          if (script[1] != "Main") 

            Runner.CallMethod(script[0] + "." + script[1], user, password, accounts); 

        }

      }

    }



    You need to pass all project variables( Ex, user, password, accounts) used in the some of the recursive scripts as parameters to the Runner.CallMethod (Value, param1, param2 , ...) as in the above example.



    Hope this helps if someone has the same issue.



    Best Regards,

      Ilija