Ask a Question

Handling errors in DDT

SOLVED
rmnrdi
Contributor

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

3 REPLIES 3
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?

 

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

Here's an article I wrote a few years back that describes how I did things.  It's similar to your structure but, perhaps, it will trigger in your mind how to construct "test cases" using DDT.

https://smartbear.com/blog/test-and-monitor/automation-framework-a-new-table-driven-technique/?q=tab...


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: