cancel
Showing results for 
Search instead for 
Did you mean: 

how to continue to next Data-Driven loop item on error

SOLVED
Highlighted
Occasional Contributor

how to continue to next Data-Driven loop item on error

Now i am testing a windows application, record the create new customer operation, need to read data from excel and enter the input fields. And i am using the Data Driven Loop to run multiple test cases, TestComplete will stop on error if there exists error, so i want to know how to continue to next Data-Driven Loop item.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: how to continue to next Data-Driven loop item on error

I'm not pythonic 🙂 but i just tried

 

def Main():
  Driver = DDT.ExcelDriver("../../../TestBook.xlsx", "TestSheet", True)
  TestedApps.RunAll()
  orders = Aliases.Orders
  mainForm = orders.MainForm
  while not Driver.EOF():
try:
    OpenForm()
    orderForm = orders.OrderForm
    groupBox = orderForm.Group
    PopulateForm()
    Checkpoint()
    CloseForm()
except:
Log.Error("An error occurred.")

    Driver.Next()
  CloseApplication()

Referred here: 

https://support.smartbear.com/testcomplete/docs/testing-with/data-driven/tutorials/script/modifying-...

https://docs.python.org/3/tutorial/errors.html


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

View solution in original post

9 REPLIES 9
Highlighted
Community Hero

Re: how to continue to next Data-Driven loop item on error

Under the 'Tools > Current Project Properties' menu,

click on 'Playback' in the left navigation

uncheck the 'Stop on Error' checkbox under the 'Runtime' section. 

 

Then it will display the error in Log and will move to next test item.


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

Highlighted
Occasional Contributor

Re: how to continue to next Data-Driven loop item on error

Hi Shankar R,

 

Thanks for your reply, but my question is how to move to next Data-Driven Loop item, if there any one step under Data-Driven Loop failure, i want to skip the rest steps and move to next Data-Driven Loop item.

 

Thanks

Highlighted
Community Hero

Re: how to continue to next Data-Driven loop item on error

If you are using Script data-driven loop then you can use try catch to ignore the current iteration error like below,

 

For example:

 

function Main()
{
    Driver = DDT.ExcelDriver("../../TestBook.xlsx", "TestSheet", true)
    TestedApps.RunAll(); 
    orders = Aliases.Orders;
    mainForm = orders.MainForm;
    while(!Driver.EOF())
    {
      try
      {
      OpenForm();
      orderForm = orders.OrderForm;
      groupBox = orderForm.Group;
      PopulateForm();
      Checkpoint();
      CloseForm();
      }
     catch(ex)
     {
      Log.Error("Error in loop");
     }

      Driver.Next();
    }
    CloseApplication();
}

Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

Highlighted
Occasional Contributor

Re: how to continue to next Data-Driven loop item on error

I am not using Script data-driven loop, if there any method to resolve data-driven loop. By the way, because i just using python, can you change the Script to Python. Thanks a lot.

Highlighted
Community Hero

Re: how to continue to next Data-Driven loop item on error

I'm not pythonic 🙂 but i just tried

 

def Main():
  Driver = DDT.ExcelDriver("../../../TestBook.xlsx", "TestSheet", True)
  TestedApps.RunAll()
  orders = Aliases.Orders
  mainForm = orders.MainForm
  while not Driver.EOF():
try:
    OpenForm()
    orderForm = orders.OrderForm
    groupBox = orderForm.Group
    PopulateForm()
    Checkpoint()
    CloseForm()
except:
Log.Error("An error occurred.")

    Driver.Next()
  CloseApplication()

Referred here: 

https://support.smartbear.com/testcomplete/docs/testing-with/data-driven/tutorials/script/modifying-...

https://docs.python.org/3/tutorial/errors.html


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”


Extension Available

View solution in original post

Highlighted
Occasional Contributor

Re: how to continue to next Data-Driven loop item on error

Hi there,

I'm trying the same thing as Hardy but my script won't continue with the next loop item. I tried it with the "stop on error" setting enabled or disabled, but in both cases my script doesn't execute the keyword test I'd like to run in the except.

 

I'd appreciate any help

 

Regards, David

 

My script:

 

def VA_Test():
    Project.Variables.VA_Test_Parameter.Reset()
    while not Project.Variables.VA_Test_Parameter.IsEOF():
      try:
        KeywordTests.Login.Run()
        KeywordTests.MMS100_VerteilauftragErstellen.Run()
        Delay(40000, "wait")
        KeywordTests.MMS100_VARuestrueckmeldung.Run()
        KeywordTests.MMS100_VA_RuestenKorrigieren.Run()
        KeywordTests.Logoff.Run()
      except:
        KeywordTests.CleanUp.Run()
      finally:
        Project.Variables.VA_Test_Parameter.Next()

 

Highlighted
Community Hero

Re: how to continue to next Data-Driven loop item on error

Keep in mind that try/except/finally logic will only catch actual raised exception errors like Python syntax, etc.  If the keyword tests within your try block simply generate an error like "Log.Error" or a checkpoint that fails with an error message, these won't be trapped by try/except logic.  What you should do, in order to utilize the logic as you have, is to raise exceptions (in JavaScript it's "throw Error(<message>)") instead of simply logging errors.  That will then trigger your try catch logic.


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
Highlighted
Occasional Contributor

Re: how to continue to next Data-Driven loop item on error

Thanks for your answer.

 

On the one hand I understand now why it didn't work the way I tried to do it, but on the other hand I still can't make it work.

 

I think I understood the concept of what your're trying to explain, but I don't really know how to throw/raise the error.

Would it be possible to use an OnLogError-EventHandler in order to raise the python exception? Could I catch such an exception with the script I posted above? 

 

Regards, David

Highlighted
Occasional Visitor

Re: how to continue to next Data-Driven loop item on error

The with statement in Python simplifies exception handling by encapsulating common preparation and clean-up tasks in so-called context managers. This allows common try..except..finally usage patterns to be encapsulated for convenient reuse and reduce the amount of code you need to write for handling different kinds of exceptions. The with statement creates resources within a block . You write your code using the resources within the block. When the block exits the resources are cleanly released regardless of the outcome of the code in the block (that is whether the block exits normally or because of an exception). 

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to pass custom command-line arguments as a test parameter for the TechCorner tag!

Will you dare to take the challenge?


Top Kudoed Authors