def speak(): if listened == 1: pass else: device.startActivity( component="com.ibaby/com.ibaby.Ui.Login.LoginMainActivity") mr.sleep(5) mr.alert(u'如果已经看到监控画面,请点击确定按钮,测试将继续进行。否则,请等待。。。', u'温馨提示', u'确定') speak_x = 408 speak_y = 1795 mr.sleep(1) for i in range(1, 5): device.touch(speak_x, speak_y, 'DOWN_AND_UP') #listen print 'Speaking...' mr.sleep(2) result1 = device.takeSnapshot() result1.writeToFile('d:\demo\ibaby\snapshot\speaking %d.png' % i, 'png') mr.sleep(8) device.touch(speak_x, speak_y, 'DOWN_AND_UP') #close print 'Speak Closeing...' mr.sleep(2) result2 = device.takeSnapshot() result2.writeToFile('d:\demo\ibaby\snapshot\speakingClose %d.png' % i, 'png') mr.sleep(2) print 'Total test', i, 'times'
def WaitforelementPresent(Value, count=8, element_bak=''): isPresent = assert_pic(Value) if not isPresent: print str(isPresent) + "\t" + Value # n = 1 for i in range(1, count, 1): print "wait 2s ..." time.sleep(2) # 等待时间固定模式 isPresent = assert_pic(Value) if isPresent: break if i > 6: # if str(element_bak) != '': # # self.element_bak_isPresent = str(self.driver.find_element_by_id(self.element_bak).is_displayed()) # error # element_bak_isPresent = assert_pic(element_bak) # print str(element_bak_isPresent) + "\t" + element_bak # if element_bak_isPresent: # # self.driver.find_element_by_id(self.element_bak).click() # print "click " + element_bak + " " + str(n) +" time(s)" # n += 1 # start_bwzq() MonkeyRunner.alert(u'页面异常', 'fail', u'确定') break # element_bak = Value print str(isPresent) + "\t" + Value return isPresent
def listen(): if installed == 1: mr.alert(u'如果已经看到监控画面,请点击确定按钮,测试将继续进行。否则,请等待。。。', u'温馨提示', u'确定') else: device.startActivity( component="com.ibaby/com.ibaby.Ui.Login.LoginMainActivity") mr.sleep(5) mr.alert(u'如果已经看到监控画面,请点击确定按钮,测试将继续进行。否则,请等待。。。', u'温馨提示', u'确定') listen_x = 135 listen_y = 1795 mr.sleep(1) for i in range(1, 5): device.touch(listen_x, listen_y, 'DOWN_AND_UP') #listen print 'Listening...' mr.sleep(2) result1 = device.takeSnapshot() result1.writeToFile('d:\demo\ibaby\snapshot\listening %d.png' % i, 'png') mr.sleep(8) device.touch(listen_x, listen_y, 'DOWN_AND_UP') #close print 'closeing...' mr.sleep(2) result2 = device.takeSnapshot() result2.writeToFile('d:\demo\ibaby\snapshot\listenClose %d.png' % i, 'png') mr.sleep(2) print 'Total test', i, 'times' return 1
def AlertDialog(msg): if msg: print"> ERROR: " + msg + " \n Exiting..." MonkeyRunner.alert(msg) sys.exit(1) else: print">ERROR: empty message" sys.exit(1)
def main(): global k; global num; global flag2; global total; global title; global files; f = open(logPath,'w') l = f.writelines("") f.close(); file = files[0] filelist = file.split('|') k = len(filelist) outputLog("Script Path :\n"); for n in range(k): #print filelist[n]; outputLog(filelist[n]+'\n'); #print k; total = num*k; m = 0; for ffile in filelist: #print ffile for i in range(num): title = 'img' + `m + 1`+'_'+`i + 1`; flag2 = '\n' + '************************************* Script ' + `m + 1`+' _ '+`i + 1` + ' times ***************' + '\n'; outputLog(flag2); print flag2; createDirectory(path,title); fp = open(ffile, 'r'); process_file(fp, device); # screenShot(); fp.close(); global flag; flag = 'img1'; global j; j = j + 1; m = m + 1; if j >= total: mr.alert('the case is finishing','Result','OK')
def main(): global k global num global flag2 global total global title global files f = open(logPath, 'w') l = f.writelines("") f.close() file = files[0] filelist = file.split('|') k = len(filelist) outputLog("Script Path :\n") for n in range(k): #print filelist[n]; outputLog(filelist[n] + '\n') #print k; total = num * k m = 0 for ffile in filelist: #print ffile for i in range(num): title = 'img' + ` m + 1 ` + '_' + ` i + 1 ` flag2 = '\n' + '************************************* Script ' + ` m + 1 ` + ' _ ' + ` i + 1 ` + ' times ***************' + '\n' outputLog(flag2) print flag2 createDirectory(path, title) fp = open(ffile, 'r') process_file(fp, device) # screenShot(); fp.close() global flag flag = 'img1' global j j = j + 1 m = m + 1 if j >= total: mr.alert('the case is finishing', 'Result', 'OK')
from com.android.monkeyrunner import MonkeyRunner as mr from com.android.monkeyrunner import MonkeyDevice as md from com.android.monkeyrunner import MonkeyImage as mi device=mr.waitForConnection() #device.installPackage("../samples/android-14/ApiDemos/bin/ApiDemos.apk") device.startActivity(component='com.example.android.apis/.ApiDemos') result=device.takeSnapshot() result.writeToFile('./snapshotbegin.png','png') mr.sleep(5) device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP') device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP') device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP') device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP') device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP') '''mr.sleep(2) device.touch(0.0,2.0,'DOWN_AND_UP') mr.sleep(2) device.touch(0.6,2.0,'DOWN_AND_UP') ''' result=device.takeSnapshot() result.writeToFile('./snapshotend.png','png') imageTrue=mr.loadImageFromFile('./snapshotbegin.png') test=imageTrue.sameAs(result) mr.alert('%s'%test)
# -*- coding: utf-8 -*- # Imports the monkeyrunner modules used by this program from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice import commands import sys import os # Connects to the current device, returning a MonkeyDevice object devices = commands.getoutput('../platform-tools/adb devices').strip().split( '\n')[1:] if len(devices) == 0: MonkeyRunner.alert("Select device to connect.", "No devices found", "Exit") sys.exit(1) # Select Any One Device And Ask User's Choice. Select Actual Device To Execute device = None choice = MonkeyRunner.choice('select device', devices, 'Choice') device = devices[choice].split('\t')[0] if device is None: MonkeyRunner.alert("Select device to connect.", "No 192.devices found", "Exit") sys.exit(1) path = 'monkey/screen_shot' files = os.listdir(path) for f in files: os.remove(path + '/' + f) device = MonkeyRunner.waitForConnection(5, device) size = (device.getProperty('display.width'),
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice message = 'Please input bugen QQ:' initialValue = '1971629467' title = 'Bugben' okTitle = 'save' cancelTitle = 'cancel' bugbenQQ = MonkeyRunner.input(message, initialValue, title, cancelTitle, okTitle) MonkeyRunner.alert(bugbenQQ, title, okTitle)
# Imports the monkeyrunner modules from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage # Alert the user a MonkeyRunner script is about to execute MonkeyRunner.alert("Monkeyrunner about to execute", "Monkeyrunner", "OK") # Connects to the current emulator emulator = MonkeyRunner.waitForConnection() # Install the Android app package and test package emulator.installPackage('./app/build/outputs/apk/app-debug-unaligned.apk') emulator.installPackage( './app/build/outputs/apk/app-debug-androidTest-unaligned.apk') # sets a variable with the package's internal name package = 'in.ravidsrk.sample' # sets a variable with the name of an Activity in the package activity = 'in.ravidsrk.sample.MainActivity' # sets the name of the component to start runComponent = package + '/' + activity # Runs the component emulator.startActivity(runComponent) # wait for the screen to fully come up MonkeyRunner.sleep(2.0) # Takes a screenshot snapshot = emulator.takeSnapshot()
from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice device=MonkeyRunner.waitForConnection() device.startActivity(component="cn.dbyl.young.tianqi/cn.dbyl.young.tianqi.activity.StartActivity") device.touch(300,300,'DOWN_AND_UP') MonkeyRunner.sleep(3) image=device.takeSnapshot() image.writeToFile('./test.png','png') MonkeyRunner.alert("Monkey Runner","title name","OK") device.press('KEYCODE_HOME',MonkeyDevice.DOWN_AND_UP) device.type('Monkey Runner') #device.reboot()
# -*- coding:utf-8 -*- import traceback from com.android.monkeyrunner import MonkeyRunner as mr from com.android.monkeyrunner import MonkeyDevice as de from com.android.monkeyrunner import MonkeyImage as mi import sys device = mr.waitForConnection() try: for i in range(10): if i == 3: # sys.exit(0) 作用是退出程序引发SystemExit异常, 可以捕获异常执行些清理工作. n默认值为0, 表示正常退出. 其他都是非正常退出. continue device.startActivity( component="com.tencent.mobileqq/.activity.SplashActivity") mr.alert('prepare to reboot') print i except Exception, e: traceback.print_exc() else: print('the end!!!') # device.reboot() #设备重启
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice from com.manning.aip.monkeyrunner import MonkeyHelper import commands import sys print hello devices = commands.getoutput('adb devices').strip().split('\n')[1:] if len(devices) == 0: MonkeyRunner.alert("No devices found. Start an emulator or connect a device.", "No devices found", "Exit") sys.exit(1) elif len(devices) == 1: choice = 0 else: choice = MonkeyRunner.choice("More than one device found. Please select target device.", devices, "Select target device") device_id = devices[choice].split('\t')[0] device = MonkeyRunner.waitForConnection(5, device_id) apk_path = device.shell('pm path com.manning.aip.dealdroid') if apk_path.startswith('package:'): print "DealDroid already installed." else: print "DealDroid not installed, installing APKs..." device.installPackage('../DealDroid/bin/DealDroid.apk') print "Starting DealDroid..." device.startActivity(component='com.manning.aip.dealdroid/.DealList') MonkeyRunner.sleep(7)
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage, MonkeyRect, MonkeyView from com.android.monkeyrunner.easy import EasyMonkeyDevice, By mr = MonkeyRunner() print "al->", mr.alert("alert message") print "ch->", mr.choice("choice message", ["first", "second", "third"]) print "in->", mr.input("input something", "dfl", "input", "oktit", "cantit") # print mr.help() dev = MonkeyRunner.waitForConnection(99, '159ef44f') hv = dev.getHierarchyViewer()
(8, "ru_RU"), # (9, 'ko_KR'), (10, "zh_01"), (11, "zh_02"), (12, "jp_JP"), ] def getNewLocale(device, index): device.startActivity(component="com.android.settings/.LocalePicker") time.sleep(1) for i in range(index): device.press("KEYCODE_DPAD_DOWN", MonkeyDevice.DOWN_AND_UP) device.press("KEYCODE_ENTER", MonkeyDevice.DOWN_AND_UP) def snapshot(device, locale): sshot = device.takeSnapshot() sshot.writeToFile("snapshots/" + locale + ".png", "png") dev = MonkeyRunner.waitForConnection(10, deviceID) MonkeyRunner.alert("Configure the device now") for l in locales: getNewLocale(dev, l[0]) print(l[1]) dev.startActivity(component=startComponent) time.sleep(1) snapshot(dev, l[1])
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice message = 'Bugben QQ:12312421' title = 'Bugben is a man' okTitle = 'Contact Me' MonkeyRunner.alert(message, title, okTitle)
from com.android.monkeyrunner import MonkeyRunner MonkeyRunner.alert("Hello mook friends", "This is title", "ok")
print "========> installed and started application\n" device.type("test1") device.press("DPAD_DOWN", MonkeyDevice.DOWN_AND_UP) MonkeyRunner.sleep(0.5) device.type("111111") print "========> input test accound\n" #find setting button and press findByButtonAndPress("show_setting") MonkeyRunner.sleep(1) device.type("211.157.170.57") device.press("DPAD_DOWN", MonkeyDevice.DOWN_AND_UP) device.type("5123") findByButtonAndPress('ip_setting_save') MonkeyRunner.sleep(0.5) MonkeyRunner.alert("start to login", "login", "ok") MonkeyRunner.sleep(1) findByButtonAndPress("sign_in_button") MonkeyRunner.sleep(5)
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-03-13 14:57:43 # @Author : why ([email protected]) # @Link : https://github.com/rorschachwhy # @Version : $Id$ from com.android.monkeyrunner import MonkeyRunner MonkeyRunner.alert('Hello frends', 'This is title', 'OK')
# Imports the monkeyrunner modules used by this program from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage # Connects to the current device, returning a MonkeyDevice object device = MonkeyRunner.waitForConnection() device.wake() MonkeyRunner.alert('alert', 'title', 'okTitle') # Takes a screenshot result = device.takeSnapshot() # Writes the screenshot to a file result.writeToFile('E:/mywork/shotbegin.png','png') # Presses the Down button device.press('KEYCODE_VOLUME_UP','DOWN_AND_UP') device.press('KEYCODE_VOLUME_UP','DOWN_AND_UP') device.press('KEYCODE_VOLUME_UP','DOWN_AND_UP') device.press('KEYCODE_VOLUME_DOWN','DOWN_AND_UP') device.press('KEYCODE_VOLUME_DOWN','DOWN_AND_UP') # Takes a screenshot result = device.takeSnapshot() # Writes the screenshot to a file result.writeToFile('E:/mywork/shotend.png','png')