0

I have a python script that does some GUI test on a chromium application. Sometimes this application does not load up correctly and for this reason the GUI test will not pass, but a simple restart of this application can fix the problem.

What I currently have is something like this:

def test():
    ...do some settings...
    ...SystemOperator.restartController()...
    ...Login(My.PinCode)...
    ...GoToDeviceUI()...
    ...undo settings...
    ...SystemOperator.restartController()...

When doing this login, in case the app did not load correctly an exception is thrown and my test is failing.

What I want to do is something like this:

def test():
   def testBody():
      ...do some settings...
      ...SystemOperator.restartController()...
      ...Login(My.PinCode)...
      ...GoToDeviceUI()...
      ...undo settings...
      ...SystemOperator.restartController()...
   try_cnt = 3
   for i in range(try_cnt):
      try:
         testBody()
         break
      except:
         ...SystemOperator.restartController()...

But without using a for/while loop.

Thank you!

2 Answers 2

0

Doesn't this solve your task? You can just loop for a certain amount of time, if you get success just break.

def test():
   def testBody():
      ...do some settings...
      ...SystemOperator.restartController()...
      ...Login(My.PinCode)...
      ...GoToDeviceUI()...
      ...undo settings...
      ...SystemOperator.restartController()...
   try_cnt = 3
   for i in range(try_cnt):
      try:
         testBody()
         break
      except:
         ...SystemOperator.restartController()...

0
0

There is no reason to execute this code only 2 times, your problem is not in this part of your code. You have to check after 2 times, if you pass in this code, or if the exception is not raise in another part of your code after 2 times

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.