2016-10-27 8 views
5

私はアンドロイドアプリをテストするために無限ループを行うために単純なpythonスクリプトを作成したが、真のPythonスクリプトは無限ループするが、一度だけ実行する - Monkeyrunner

# 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) 
+0

次の繰り返しで 'sleep'のタイミングが' touch'アクションから外れていますか? – nullpointer

+0

また、 'import time 'を使って試してみてください。 time.sleep(10)' – nullpointer

+0

ループ内の例外が捕捉されない場合、ループを終了します。 – zvone

答えて

0

あなたはtryhttps://docs.python.org/3/tutorial/errors.html)内の各コマンドを持っている必要があります。裸のexcept(つまりcatch-all except)を持つことは好ましくありませんが、デバッグのために試すことができます。

0

monkeyrunerの代わりにほとんどを使用できますが、それは純粋なpythonです。

私は

#! /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) 

はまた、あなただけのUI上のポイントとクリックしてCulebra GUIを利用すると、自動的にスクリプト(あるいはユニットテスト)のこの種を生成することができることを示すために、スクリプトを変更しました。

関連する問題