Forum Discussion

rmnrdi's avatar
rmnrdi
Contributor
6 years ago
Solved

Handling errors in DDT

I've created a DDT "framework" that I use to pass data into a test template.

This is the function that controls the whole thing:

// Start Here
function Main()
{ 
  aqPerformance.Start();
  //Used as the master test id 
  var csvPath = "C:\\TestData\\JobEntryData\\TestID.csv";
  let JEDriver = DDT.CSVDriver(csvPath);
  var i = 1;
  ih.RunInnovationsProgram("JobEntry.exe");
  ih.LoginToInnovations("JobEntry","Ocuco","");
      
    while (!JEDriver.EOF())
    {  
      Log.Message("******************** Test run number " + i + " has Started... ********************************")
    
      iv.LoadUIVariables(i);
      SetUIVariables(); 
      PopulateIDPage();
      PopulateFramePage();    
      PopulateLensesPage();
      PopulateRxPage();
      PopulateExtrasPage();
      //PopulateBlanksPage();
      PopulateInvoicePage();
          
      Log.Message("^^^^^^^^^^^^^^^^^^^^^^^^^^^ Test run number " + i + " has finished. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^");  
      //Indexes to next line of data sources
      i++;
      //Indexes to next line in id file
     JEDriver.Next();       
    }
      DDT.CloseDriver(JEDriver.Name);

   var testTime = aqConvert.FloatToStr(((aqPerformance.Value()/1000)/60));
   Log.Message(aqString.Format("Minutes to complete tests: %.2f", testTime));
}

In each of the "populatexxx" functions are connections to external data csv's as data sources. 

 

Since many tests can be run through this one script, with the data deciding how the UI acts, this is a single point of failure. If I were to make 20 tests, and one failed, I could do a cleanup and start on the next test.

 

It doesn't seem like I can do that here, because if the test fails, the test loses it's state and reports the error.

 

How can I handle errors using this technique?

 

Is my test setup fundementally flawed?

 

How does one create "individual" tests using DDT?

 

Thanks

  • Hi,

     

    Not sure if I completely got your question... Also I am not quite sure what state you are talking about here: "if the test fails, the test loses it's state".

    However, maybe this will help:

    -- Your test project must be set up to not stop on error;

    -- Each PopulateXXX() test function must return boolean as an indicator of whether or not the execution of the whole test can be continued;

    -- Transform your main code to something like that:

      var bResult;
        while (!JEDriver.EOF())
        {  
          Log.Message("******************** Test run number " + i + " has Started... ********************************")
        
          bResult = iv.LoadUIVariables(i);
          if (bResult)
            bResult = SetUIVariables(); 
          if (bResult)
            bResult = PopulateIDPage();
          ...
              
          Log.Message("^^^^^^^^^^^^^^^^^^^^^^^^^^^ Test run number " + i + " has finished. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^");  
    
          // you may consider whether or not to continue with the next data loop
          if (!bResult)
            break;
    
          //Indexes to next line of data sources
          i++;
          //Indexes to next line in id file
         JEDriver.Next();       
        }
    ...

    Does this help?

     

     

3 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Not sure if I completely got your question... Also I am not quite sure what state you are talking about here: "if the test fails, the test loses it's state".

    However, maybe this will help:

    -- Your test project must be set up to not stop on error;

    -- Each PopulateXXX() test function must return boolean as an indicator of whether or not the execution of the whole test can be continued;

    -- Transform your main code to something like that:

      var bResult;
        while (!JEDriver.EOF())
        {  
          Log.Message("******************** Test run number " + i + " has Started... ********************************")
        
          bResult = iv.LoadUIVariables(i);
          if (bResult)
            bResult = SetUIVariables(); 
          if (bResult)
            bResult = PopulateIDPage();
          ...
              
          Log.Message("^^^^^^^^^^^^^^^^^^^^^^^^^^^ Test run number " + i + " has finished. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^");  
    
          // you may consider whether or not to continue with the next data loop
          if (!bResult)
            break;
    
          //Indexes to next line of data sources
          i++;
          //Indexes to next line in id file
         JEDriver.Next();       
        }
    ...

    Does this help?

     

     

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      What AlexKaras said.  Generally, you've constructed a similar framework to what I've used in the past (Great minds....).  What I've done in addition to what has already been said is the judicial use of try/catch/finally groupings around critical code and frequently using "throw" to exit out of a test case if a critical fail point is reached.  This allows me to "bubble" up a status to the main driver routine as a "false" result so that, if a test case returns "false", we log it as a problem and move on to the next.