Issue with Data-Driven Loop, script is not gracefully exiting on error
We have a requirement to create multiple accounts. All the test data are being passed from an excel sheet, for that a data-driven loop is used.
Each row in the Excel sheet is treated as a different test case.
If one test case failed due to test data or any other issue, the script should mark that particular test case( row of an excel sheet) as failed and should pick the next row for execution. The problem is here that if the Playback setting is set as Continue on error, then in this case script is not exiting that case and continuing with the next steps.
If we set "Stop current item" in the playback setting, its moves to the next test case but the script is not entering any values in the next case and getting failed due to the "Operation interrupted by the user" error, and all the further test cases also got failed due to similar issues.
Please suggest a way to resolve this issue. Thanks
Sample Code for reference
code is similar to below
while not dataVar.EOF():
except Exception as e:
Thanks for looking into this issue.
We are expecting all data to be worked however during execution some may fail in validation. In a failure scenario, our expectation is to fail that particular test case and pick the next in the row.
I don't know your syntax but it sounds like your Try and Next are working ok together, but when you hit the Exception, it doesn't know how to go on. I would try putting another Next under the Exception and see what happens.
I tried to use another Next in except block but no luck.
I've uploaded the code and test data file for your reference. Please change the TestDataPath variable value.
There are 3 rows in the test data file, each is treated as a different Test case.
Thank you for the information.
For security reasons, I won't open that .zip file. If you'd like to post a screenshot, I'd be happy to look further.
You are using the FindElement() method which either returns the Object that matches the search condition or returns None if condition not matched. FindElement() does not throw an error.
Hi @diwakar_sh12 ,
I am not that proficient with python, but you might want to put the try/except block inside of the while loop, that way it can continue with the next entry if an error is raised. I'm not certain of the exact syntax/format, but something like this might work:
while not ddv.EOF aqTestCase.Begin("Test Case" + ddv.Value); try: openApp() clickObject(contactUs) waitTillPageLoads() fillContactForm(ddv) except: Log.Error("Error Occured") closeBrowser(Project.Variables.browser) aqTestCase.End() ddv.Next()
I hope this helps.
Thanks for looking into this issue. Actually, I've already tried that approach however no luck. What is happening here, if there are 10 objects on a page, and an error occurred at the second object then the script marks the step as a failure but at the same time it continues to perform the action on other objects on the page, it should skip that iteration completely and pick another in a loop.
If you have any other solution to achieve this please let me know, I'll tweak my code accordingly.