Although True python script should loop endlessly, it only runs once - Monkeyrunner

I created a simple python script to make an endless loop to test my Android application, however it only runs once and stops.

# Imports the monkeyrunner modules used by this program from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice # Connects to the current device, returning a MonkeyDevice object device = MonkeyRunner.waitForConnection('66b6cc0e') while True: device.touch (300, 1750, 'DOWN_AND_UP') MonkeyRunner.sleep(3) device.touch(742, 1213, 'DOWN_AND_UP') MonkeyRunner.sleep(10) device.touch(554, 1613, 'DOWN_AND_UP') MonkeyRunner.sleep(10) # Push SEND MESSAGE device.touch(300, 1750, 'DOWN_AND_UP') MonkeyRunner.sleep(3) device.touch(742, 1213, 'DOWN_AND_UP') MonkeyRunner.sleep(10) device.touch(554, 1613, 'DOWN_AND_UP') MonkeyRunner.sleep(10) 
+5
source share
2 answers

You should have each of the commands in try ( https://docs.python.org/3/tutorial/errors.html ). It is not preferable to have bare except (i.e. an exception for everyone), but you can try it for debugging.

0
source

You can use AndroidViewClient / culebra , which is almost a replacement for monkeyruner , but it is pure python.

I made changes to the script to show that

 #! /usr/bin/env python # Imports the monkeyrunner modules used by this program #from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice import re import sys import os from com.dtmilano.android.viewclient import ViewClient # Connects to the current device, returning a MonkeyDevice object #device = MonkeyRunner.waitForConnection('66b6cc0e') kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) while True: print "loop" device.touch (300, 1750, 'DOWN_AND_UP') ViewClient.sleep(3) device.touch(742, 1213, 'DOWN_AND_UP') ViewClient.sleep(10) device.touch(554, 1613, 'DOWN_AND_UP') ViewClient.sleep(10) # Push SEND MESSAGE device.touch(300, 1750, 'DOWN_AND_UP') ViewClient.sleep(3) device.touch(742, 1213, 'DOWN_AND_UP') ViewClient.sleep(10) device.touch(554, 1613, 'DOWN_AND_UP') ViewClient.sleep(10) 

In addition, you can use the Culebra GUI and automatically generate such scripts (or even unittests) point by point and by clicking on the user interface.

0
source

Source: https://habr.com/ru/post/1258909/


All Articles