tuan dat nguyen
tuan dat nguyen

Reputation: 21

Androidviewclient dump() hangs on transition screen

I use the latest AndroidViewClient version on Windows. After the script clicks on the button next the application connects to the remote server and waiting for a response, during this time there is a like "waiting progress bar" on the screen. The problem is the waiting time is random. I use a while loop waiting for a specific view of a next page screen, similar on this post "Waiting for a specific view on androidviewclient". But if time.sleep() is too short the script hangs forever on the code line vc.dump(), precisely on the code line "received += s.recv(1024)" of this method dump() for ViewServer. There is a watchguard ViewClient.setAlarm(120) but signal.alarm does not work on Windows. Why not using s.settimeout(120) before received += s.recv(1024) and try/except block to prevent a blocking state on Windows ?

Upvotes: 1

Views: 254

Answers (1)

kyczawon
kyczawon

Reputation: 525

I avoided this problem by using timeouts on the function call and retrying in a while loop until it succeeds. See Timeout on a function call for how to use signal.

The following function for waiting for a view based on text works:

import signal

def wait_for_text(vc, text):
    while 1:
        try:
            print('vc dump for text: ' + text)
            signal.alarm(5)
            vc.dump(window=-1, sleep=0)
            signal.alarm(0)
            print('finished: ' + text)
            if vc.findViewWithText(text) is None:
                time.sleep(0.5)
            else:
                return
        except:
            exc_type, exc_value, exc_tb = sys.exc_info()
            print(''.join(trace.format_exception(exc_type, exc_value, exc_tb)))
            time.sleep(0.5)
    raise RuntimeError('Failed waiting '+str(timeout)+'s for text: ' + text)

Upvotes: 0

Related Questions