def test(): # 连接手机 device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) # 按HOME键 device.press('KEYCODE_HOME') time.sleep(3) # 找到微信图标 vc.dump() weixin_button = vc.findViewWithTextOrRaise(u'微信') # 点击微信图标 weixin_button.touch() time.sleep(10) # 找到第一个联系人/群 # 可以使用UI Automator Viewer查看到对应第一个联系人/群的resource-id为"com.tencent.mm:id/auj" vc.dump() group_button = vc.findViewByIdOrRaise("com.tencent.mm:id/auj") # 点击进群 group_button.touch() time.sleep(5) # 找到输入框并输入当前时间 vc.dump() vc.findViewByIdOrRaise("com.tencent.mm:id/aep").setText('Now:{}'.format(time.strftime('%Y-%m-%d %H:%M:%S'))) time.sleep(3) # 点击发送按钮 vc.dump() vc.findViewWithTextOrRaise(u'发送').touch()
def _run(self, device=None, serialno=None, stoptime=7200, width=1080, height=1920, isPraise=True): if device == None: device, serialno = ViewClient.connectToDeviceOrExit() elif serialno == None: serialno = device.serialno device.startActivity("com.jm.video/.ui.main.SplashActivity") time.sleep(8) device.touch(width / 2, height / 2) vc = ViewClient(device, serialno) device.touch(width / 2, height / 2) while True: vc.swipe(width / 2, height / 4 * 1, width / 2, height / 4 * 3) t = random.randint(1, 20) print t if t > stoptime - int(time.time()): t = stoptime = int(time.time()) if t % 2 == 0: time.sleep(t / 2) vc.findViewByIdOrRaise("com.jm.video:id/praise").touch() time.sleep(t / 2) else: time.sleep(t) if int(time.time()) >= stoptime: break device.shell("am force-stop com.jm.video")
def test_LaunchBrowser(self): print("Back to home") self.device.press('KEYCODE_BACK') self.device.press('KEYCODE_HOME') self.device.press('KEYCODE_HOME') self.device.press('KEYCODE_BACK') VPS = "javascript:alert(document.getElementsByTagName('html')[0].innerHTML);" USE_BROWSER = False if USE_BROWSER: package = 'com.android.browser' activity = '.BrowserActivity' _id = 'id/no_id/12' else: package = 'com.android.chrome' activity = 'com.google.android.apps.chrome.Main' _id = 'id/no_id/28' component = package + "/" + activity uri = 'http://dtmilano.blogspot.com' print("Open Browser") self.device.startActivity(component=component, uri=uri) print("Waite for 5 sec") ViewClient.sleep(5) vc = ViewClient(device=self.device, serialno=self.serialno) sdkVersion = vc.getSdkVersion() print("Get SDK Version:"+str(sdkVersion)) if sdkVersion > 10: print("Show search bar") self.device.drag((240, 180), (240, 420), 1, 20) else: for i in range(10): self.device.press('KEYCODE_DPAD_UP') ViewClient.sleep(1) print("Delete search bar") self.device.press('KEYCODE_DEL') ViewClient.sleep(1) print("Input JS and go") self.device.type(VPS) ViewClient.sleep(1) self.device.press('KEYCODE_ENTER') ViewClient.sleep(3) print("dump ViewClient data") vc.dump() print vc.findViewByIdOrRaise('com.android.chrome:id/js_modal_dialog_message' if sdkVersion >= 16 else 'id/message').getText().replace('\\n', "\n") self.device.press('KEYCODE_BACK' if sdkVersion > 10 else 'KEYCODE_ENTER') ViewClient.sleep(1)
def swith_effect_ui(device, serialno): log("switch effect") # open setting #cmp=com.android.settings/.Settings packageGM = "com.android.settings" activityGM = ".Settings" componentGM = packageGM + "/" + activityGM cmd = " ".join(["am", "force-stop", packageGM]) device.wake() log("wake") time.sleep(1) device.startActivity(componentGM) vc = ViewClient(device, serialno) vv = vc.findViewByIdOrRaise("id/no_id/1") uis = UiScrollable(vv) uis.flingBackward() uis.flingBackward() uis.flingBackward() for i in range(3): vc, key = get_boomsound_id(device, serialno) if key is None: log("scroll") uis.flingForward() continue else: break vc, key = get_boomsound_id(device, serialno) if vc is not None: log("find the boomsound") control_Btn(vc, key)
def get_fragment_list_view(device, serialno): vc = ViewClient(device, serialno) view_dict = vc.getViewsById() for key, value in view_dict.items(): strTemp = unicode(value).encode("UTF-8") if strTemp.find("id/fragment_list") > 0: view = vc.findViewByIdOrRaise(key) return view return None
try: for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from com.dtmilano.android.viewclient import ViewClient, TextView, EditText from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device=device, serialno=serialno) #send = vc.findViewWithTextOrRaise('Send') send = vc.findViewByIdOrRaise('id/send') #to = EditText(vc.findViewByIdOrRaise('id/to')) to = vc.findViewByIdOrRaise('id/to') subject = vc.findViewByIdOrRaise('id/subject') subject.touch() subject.type('AVCSample') MonkeyRunner.sleep(10) to.touch() #to.type('*****@*****.**') device.type('*****@*****.**') MonkeyRunner.sleep(10) send.touch()
#! /usr/bin/env python # -*- coding: utf-8 -*- import time from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') wait_for_id_and_touch(vc, 'com.opera.browser:id/url_field') vc.findViewByIdOrRaise('com.opera.browser:id/url_field').setText( 'https://browserbench.org/JetStream/') adb.shell('input keyevent KEYCODE_ENTER') # if can't press start test, there is a night mode overlay try: wait_for_text_and_touch(vc, 'Start Test', 15) except: wait_for_text(vc, 'Try night mode') device.touch(529, 975, 'DOWN_AND_UP') wait_for_text_and_touch(vc, 'Start Test', 15) wait_for_id(vc, 'result-summary', 1320)
import time import commands from subprocess import call from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException package = "com.android.gallery3d" testcase = "gallery" target_view = "gl_root_view" def collect_score(testcase, run_result): call(['lava-test-case', testcase, '--result', run_result]) device, serialno = ViewClient.connectToDeviceOrExit() kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) try: vc.findViewByIdOrRaise(package + ":id/" + target_view) run_result = "pass" print target_view + " found!" print testcase + " Test PASSED!" collect_score(testcase, run_result) sys.exit(0) except ViewNotFoundException: run_result = "fail" print target_view + " can not be found! Fatal!" print testcase + " Test FAILED!" collect_score(testcase, run_result) sys.exit(1)
dump = vc.dump() try: for view in dump: if view['resource-id'] == 'android:id/list': listview_unique_id = view.uniqueId() first_conversation_id = get_first_contact_unique_id( listview_unique_id) for v in dump: if v.uniqueId() == first_conversation_id: v.touch() logger.info('click first conversation', extra=get_extra_data()) vc.dump() com_whatsapp___id_input_attach_button = vc.findViewByIdOrRaise( "com.whatsapp:id/input_attach_button") com_whatsapp___id_input_attach_button.touch() logger.info('click attachment button', extra=get_extra_data()) vc.dump() com_whatsapp___id_pickfiletype_gallery = vc.findViewByIdOrRaise( "com.whatsapp:id/pickfiletype_gallery") com_whatsapp___id_pickfiletype_gallery.touch() logger.info('click Gallery', extra=get_extra_data()) vc.dump() com_whatsapp___id_title = vc.findViewWithTextOrRaise( u'Camera') com_whatsapp___id_title.touch() logger.info('click Camera folder', extra=get_extra_data())
kwargs1 = {"verbose": True, "ignoresecuredevice": False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = { "startviewserver": True, "forceviewserveruse": False, "autodump": False, "ignoreuiautomatorkilled": True, "compresseddump": False, } vc = ViewClient(device, serialno, **kwargs2) vc_dump(vc) # Accept Vellamo EULA btn_setup_1 = vc.findViewByIdOrRaise("android:id/button1") btn_setup_1.touch() vc_dump(vc) # open settings vc_dump(vc) btn_settings = vc.findViewByIdOrRaise("com.quicinc.vellamo:id/main_toolbar_wheel") btn_settings.touch() # disable animations vc_dump(vc) btn_animations = vc.findViewWithTextOrRaise(u"Make Vellamo even more beautiful") btn_animations.touch() # back to the home screen device.press("KEYCODE_BACK")
enclosing_tab = chapter_tab.getParent().getParent() for child in enclosing_tab.children: if child.getClass() == "android.widget.FrameLayout": for subchild in child.children: if subchild.getId() == "com.quicinc.vellamo:id/card_launcher_run_button": subchild.touch() kwargs1 = {'verbose': True, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) vc_dump(vc) # Accept Vellamo EULA btn_setup_1 = vc.findViewByIdOrRaise("android:id/button1") btn_setup_1.touch() vc_dump(vc) # open settings vc_dump(vc) btn_settings = vc.findViewByIdOrRaise('com.quicinc.vellamo:id/main_toolbar_wheel') btn_settings.touch() # disable animations vc_dump(vc) btn_animations = vc.findViewWithTextOrRaise(u'Make Vellamo even more beautiful') btn_animations.touch() # back to the home screen device.press("KEYCODE_BACK")
time.sleep(5) except ValueError: print("Got ValueError when call vc.dump()") time.sleep(5) def output_result(test_name, measurement): call([f_output_result, "antutu332_" + test_name, 'pass', measurement, default_unit]) # release info and upgrade dialog are not presented # if there is no connection to Internet try: time.sleep(5) dump_always() button_cancel = vc.findViewByIdOrRaise("android:id/button2") button_cancel.touch() except ViewNotFoundException: pass try: time.sleep(2) dump_always() button_ok = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/button_ok") button_ok.touch() except ViewNotFoundException: pass found_test_btn = False while not found_test_btn: try:
print("Got ValueError when call vc.dump()") time.sleep(5) time.sleep(5) dump_always() btn_java_bench = vc.findViewWithTextOrRaise(u'Java bench') btn_java_bench.touch() keys = [ "FFT (1024)", "SOR (100x100)", "Monte Carlo", \ "Sparse matmult (N=1000, nz=5000)", "LU (100x100)", "Composite Score"] finished = False while(not finished): try: time.sleep(60) dump_always() results = vc.findViewByIdOrRaise("net.danielroggen.scimark:id/textViewResult") if results.getText().find("Done") > 0: finished = True print "benchmark finished" for line in results.getText().replace(": \n", ":").split("\n"): line = str(line.strip()) key_val = line.split(":") if len(key_val) == 2: if key_val[0].strip() in keys: key = key_val[0].strip().replace(' ', '_').replace('(', '').replace(')', '').replace(',', '') call([f_output_result, "scimark_" + key, 'pass', key_val[1].strip(), 'Mflops']) except ViewNotFoundException: pass except RuntimeError: pass except ValueError:
import time from subprocess import call from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException parent_dir = os.path.realpath(os.path.dirname(__file__)) f_output_result="%s/../common/output-test-result.sh" % parent_dir kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) time.sleep(2) vc.dump(window='-1') start_single_button = vc.findViewByIdOrRaise("com.greenecomputing.linpack:id/btnsingle") start_single_button.touch() time.sleep(2) vc.dump(window='-1') start_single_button = vc.findViewById("com.greenecomputing.linpack:id/btnsingle") while not start_single_button: time.sleep(2) vc.dump(window='-1') start_single_button = vc.findViewById("com.greenecomputing.linpack:id/btnsingle") mflops_single_score = vc.findViewByIdOrRaise("com.greenecomputing.linpack:id/txtmflops_result") time_single_score = vc.findViewByIdOrRaise("com.greenecomputing.linpack:id/txttime_result") call([f_output_result, 'Linpack_MFLOPSSingleScore', 'pass', mflops_single_score.getText(), 'MFLOPS']) call([f_output_result, 'Linpack_TimeSingleScore', 'pass', time_single_score.getText(), 'seconds'])
import os import time from subprocess import call from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException parent_dir = os.path.realpath(os.path.dirname(__file__)) f_output_result="%s/../common/output-test-result.sh" % parent_dir kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) vc.dump() btn_run = vc.findViewByIdOrRaise("com.roywhet:id/startButton") btn_run.touch() time.sleep(2) finished = False key_unit_hash = { "N1": "MFLOPS", "N2": "MFLOPS", "N3": "MOPS", "N4": "MOPS", "N5": "MOPS", "N6": "MFLOPS", "N7": "MOPS", "N8": "MOPS", "MWIPS": "MFLOPS" }
endpoint_keyword = "multicore_rate" package_name = "com.primatelabs.geekbench3" # Test cases testcase_run = "geekbench_run" testcase_singlecore = "geekbench_single_core" testcase_multicore = "geekbench_multi_core" device, serialno = ViewClient.connectToDeviceOrExit() kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) try: time.sleep(2) vc.dump() trigger = vc.findViewByIdOrRaise(package_name + ":id/runBenchmarks") trigger.touch() print "Geekbench 3 Test Started!" except ViewNotFoundException: run_result = "fail" print "Can not find the start button! Please check the screen!" all_fail() sys.exit(1) time.sleep(10) vc.dump() time.sleep(2) try: vc.findViewByIdOrRaise("android:id/progress") except ViewNotFoundException:
from com.dtmilano.android.viewclient import ViewClient USE_BROWSER = True # Starting: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.android.browser/.BrowserActivity } if USE_BROWSER: package = 'com.android.browser' activity = '.BrowserActivity' else: package = 'com.android.chrome' activity = 'com.google.android.apps.chrome.Main' component = package + "/" + activity uri = 'http://dtmilano.blogspot.com' device, serialno = ViewClient.connectToDeviceOrExit() device.startActivity(component=component, uri=uri) ViewClient.sleep(5) vc = ViewClient(device, serialno) if vc.getSdkVersion() >= 16: if USE_BROWSER: url = vc.findViewByIdOrRaise("id/no_id/12").getText() else: url = vc.findViewWithContentDescription("Search or type url").getText() else: url = vc.findViewByIdOrRaise("id/url").getText() if string.find(uri, url) != -1: print "%s successfully loaded" % uri else: print "%s was not loaded, url=%s" % (uri, url)
VPS = "javascript:alert(document.getElementsByTagName('html')[0].innerHTML);" PACKAGE = 'com.android.browser' ACTIVITY = '.BrowserActivity' COMPONENT = PACKAGE + "/" + ACTIVITY URI = 'http://dtmilano.blogspot.com' device, serialno = ViewClient.connectToDeviceOrExit() device.startActivity(component=COMPONENT, uri=URI) MonkeyRunner.sleep(3) vc = ViewClient(device=device, serialno=serialno) device.drag((240, 180), (240, 420), 10, 10) url = vc.findViewByIdOrRaise('id/url') url.touch() MonkeyRunner.sleep(1) device.press('KEYCODE_DEL', MonkeyDevice.DOWN_AND_UP) for c in VPS: device.type(c) device.press('KEYCODE_ENTER', MonkeyDevice.DOWN_AND_UP) MonkeyRunner.sleep(3) vc.dump() print vc.findViewByIdOrRaise('id/message').getText().replace('\\n', "\n") device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
def get_score_with_text(vc, text, offset=1): score_view = vc.findViewWithTextOrRaise(text) score_uid = score_view.getUniqueId() uid = int(re.search("id/no_id/(?P<uid>\d+)", score_uid).group('uid')) score = vc.findViewByIdOrRaise("id/no_id/%s" % (uid + offset)) call([f_output_result, "sqlite_" + text.strip().replace(" ", "_"), 'pass', score.getText().strip(), default_unit]) kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) vc.dump('-1') btn_start = vc.findViewByIdOrRaise("com.wtsang02.sqliteutil.activities:id/btStart") btn_start.touch() finished = False btn_results = None while(not finished): try: time.sleep(5) vc.dump('-1') btn_results = vc.findViewById("com.wtsang02.sqliteutil.activities:id/btToResults") if btn_results: finished = True except RuntimeError: pass print "benchmark finished" btn_results.touch()
kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) vc.dump() view_license_btn = vc.findViewWithText("View license") if view_license_btn: ok_button = vc.findViewWithTextOrRaise("OK") ok_button.touch() vc.dump() run_full_item=vc.findViewWithTextOrRaise(u'Run full benchmark') run_full_item.touch() finished = False while(not finished): try: time.sleep(5) vc.dump() vc.findViewByIdOrRaise("com.aurorasoftworks.quadrant.ui.professional:id/chart") finished = True print "Benchmark finished" except ViewNotFoundException: pass except RuntimeError: pass except ValueError: pass
} vc = ViewClient(device, serialno, **kwargs2) time.sleep(2) vc.dump(window="-1") # Start test button start_button = vc.findViewWithTextOrRaise("Full Benchmark") start_button.touch() # Wait while cf-bench running finished = False while not finished: try: time.sleep(5) vc.dump() progress_button = vc.findViewByIdOrRaise("eu.chainfire.cfbench:id/admob_preference_layout") finished = True except ViewNotFoundException: pass except RuntimeError as e: pass except ValueError as e: pass print ("Benchmark Finished") vc.dump() result_label = vc.findViewWithTextOrRaise(u"Results") result_label.touch() device.press("DPAD_DOWN") time.sleep(2)
FLAG_ACTIVITY_NEW_TASK = 0x10000000 package = 'com.example.i2at.tc' activity = '.TemperatureConverterActivity' componentName = package + "/" + activity device.startActivity(component=componentName, flags=FLAG_ACTIVITY_NEW_TASK) MonkeyRunner.sleep(5) device.type("123") MonkeyRunner.sleep(3) vc = ViewClient(device, serialno, startviewserver=(not localViewServer)) # obtain the views by id celsius = vc.findViewByIdOrRaise("id/celsius") fahrenheit = vc.findViewByIdOrRaise("id/fahrenheit") ct = celsius.getText() if ct: c = float(ct) else: print >> sys.stderr, "Celsius is empty" sys.exit(1) ft = fahrenheit.getText() if ft: f = float(ft) else: print >> sys.stderr, "Fahrenheit is empty" sys.exit(1) print "by id: %.2f C => %.2f F" % (c, f)
device, serialno = ViewClient.connectToDeviceOrExit() print("Open Browser") device.startActivity(component=component, uri=uri) print("Waite for 5 sec") ViewClient.sleep(3) vc = ViewClient(device=device, serialno=serialno) sdkVersion = vc.getSdkVersion() print("Get SDK Version:"+str(sdkVersion)) if sdkVersion > 10: print("Show search bar") device.drag((240, 180), (240, 420), 1, 20) else: for i in range(10): device.press('KEYCODE_DPAD_UP') ViewClient.sleep(1) try: device.press('KEYCODE_DEL') device.type(VPS) ViewClient.sleep(1) device.press('KEYCODE_ENTER') ViewClient.sleep(3) vc.dump() print vc.findViewByIdOrRaise('com.android.chrome:id/js_modal_dialog_message' if sdkVersion >= 16 else 'id/message').getText().replace('\\n', "\n") device.press('KEYCODE_BACK' if sdkVersion > 10 else 'KEYCODE_ENTER') ViewClient.sleep(1) except Exception as e: print(e)
#! /usr/bin/env python # -*- coding: utf-8 -*- import time from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') component = 'free.reddit.news/reddit.news.RedditNavigation' device.startActivity(component=component) wait_for_id_and_touch(vc, 'free.reddit.news:id/subreddits') try: wait_for_id_and_touch(vc, 'free.reddit.news:id/subreddits', 6) except: pass wait_for_id(vc, 'free.reddit.news:id/edittext') vc.findViewByIdOrRaise('free.reddit.news:id/edittext').setText('energio') # press search device.touch(1033, 1730, 'DOWN_AND_UP') wait_for_text_and_touch(vc, 'energio') wait_for_text(vc, 'Energio Logo!', 15) time.sleep(2)
#select outlet skip if vc.findViewWithText('Select an Outlet'): vc.findViewWithContentDescriptionOrRaise(u'''Outlet''').touch() vc.sleep(_s) #screenshot of home screen device.takeSnapshot().save(path+'/whitelabel/WLA_database/'+appid+'/screenshots/1.png','PNG') vc.dump(window='-1') vc.sleep(_s) vc.dump(window='-1') #Theme 1 = STACK STACK if vc.findViewWithContentDescription(u'''stack_stack'''): id_scroll_view = vc.findViewByIdOrRaise("com.restwla.z"+appid+":id/scroll_view") #screenshot of information page vc.findViewByIdOrRaise('com.restwla.z'+appid+':id/home_option_information').touch() vc.sleep(_s) device.takeSnapshot().save(path+'/whitelabel/WLA_database/'+appid+'/screenshots/6.png','PNG') device.press('KEYCODE_BACK') #screenshot of photos page if vc.findViewById('com.restwla.z'+appid+':id/home_option_photos'): vc.findViewByIdOrRaise('com.restwla.z'+appid+':id/home_option_photos').touch() vc.sleep(_s) device.takeSnapshot().save(path+'/whitelabel/WLA_database/'+appid+'/screenshots/4.png','PNG') device.press('KEYCODE_BACK') #screenshot of Table Reservation if vc.findViewById('com.restwla.z'+appid+':id/home_option_table_reservation'):
runComponent = package + '/' + activity # run the component device.startActivity(component=runComponent) vc.dump(window='-1') # find a conversation by a Contact's name com_viber_voip___id_from = vc.findViewWithTextOrRaise(u'Tomi') if com_viber_voip___id_from: # click the view com_viber_voip___id_from.touch() vc.dump() com_viber_voip___id_send_text = vc.findViewByIdOrRaise( "com.viber.voip:id/send_text") if com_viber_voip___id_send_text: com_viber_voip___id_send_text.touch() print "typing..." device.type('Test') vc.dump() com_viber_voip___id_btn_send = vc.findViewByIdOrRaise( "com.viber.voip:id/btn_send") if com_viber_voip___id_btn_send: # send the text com_viber_voip___id_btn_send.touch()
ViewClient.sleep(1) device.takeSnapshot(reconnect=True).save('./screenshots/logout/logout-pre.png','png') vc = ViewClient(*ViewClient.connectToDeviceOrExit()) vc.dump() email = vc.findViewById('com.hoard.hoard:id/login_email') email.type('*****@*****.**') vc.dump() password = vc.findViewById('com.hoard.hoard:id/login_password') password.type('u1') button = vc.findViewByIdOrRaise('com.hoard.hoard:id/login_button') button.touch() vc.dump() device.takeSnapshot(reconnect=True).save('./screenshots/logout/login-pos.png','png') ViewClient.sleep(3) device.takeSnapshot(reconnect=True).save('./screenshots/logout/logout-redirect.png','png') button = vc.findViewByIdOrRaise('com.hoard.hoard:id/settings_button') button.touch() vc.dump()
#! /usr/bin/env python # -*- coding: utf-8 -*- import time from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') component = 'com.reddit.frontpage/.main.MainActivity' device.startActivity(component=component) wait_for_id_and_touch(vc, 'com.reddit.frontpage:id/search_view') wait_for_id(vc, 'com.reddit.frontpage:id/search') vc.findViewByIdOrRaise('com.reddit.frontpage:id/search').setText('energio') # press search device.touch(1033, 1730, 'DOWN_AND_UP') wait_for_text_and_touch(vc, 'Communities') time.sleep(2)
parent_dir = os.path.realpath(os.path.dirname(__file__)) f_output_result="%s/../common/output-test-result.sh" % parent_dir def collect_score(benchmark_name, run_result, score_number, score_unit): call([f_output_result, benchmark_name, run_result, score_number, score_unit]) benchmark_name = "BenchmarkPi" kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) time.sleep(2) vc.dump(window='-1') start_button = vc.findViewByIdOrRaise("gr.androiddev.BenchmarkPi:id/Button01") start_button.touch() finished = False while (not finished): time.sleep(1) try: vc.dump(window='-1') vc.findViewByIdOrRaise("android:id/message") finished = True except ViewNotFoundException: pass except RuntimeError as e: print e print "benchmark finished"
#! /usr/bin/env python # -*- coding: utf-8 -*- import time from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') component = 'com.microsoft.emmx/com.microsoft.ruby.Main' device.startActivity(component=component) wait_for_id_and_touch(vc, 'com.microsoft.emmx:id/cancel_button') wait_for_id_and_touch(vc, 'com.microsoft.emmx:id/not_now') wait_for_id_and_touch(vc, 'com.microsoft.emmx:id/fre_share_not_now') wait_for_id_and_touch(vc, 'com.microsoft.emmx:id/no') wait_for_id(vc, 'com.microsoft.emmx:id/search_box_text') vc.findViewByIdOrRaise('com.microsoft.emmx:id/search_box_text').touch() wait_for_id(vc, 'com.microsoft.emmx:id/url_bar') vc.findViewByIdOrRaise('com.microsoft.emmx:id/url_bar').setText( 'https://www.wirple.com/bmark/') adb.shell('input keyevent KEYCODE_ENTER') time.sleep(2)
item_list = [network_check, device_check, personal_check, accounts_check, system_check] checked_item = [] missing_item = [] positive_counter = 0 def collect_score(testcase, run_result): call(['lava-test-case', testcase, '--result', run_result]) device, serialno = ViewClient.connectToDeviceOrExit() kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) # Title check try: return_text = vc.findViewByIdOrRaise("android:id/action_bar_title").getText() if return_text == title_check: run_result = "pass" print title_check + " found!" testcase = title_check + "-Title" print testcase + " Test PASSED!" collect_score(testcase, run_result) else: run_result = "fail" print "Return text does not match to " + title_check + "! Please check the screen!" testcase = title_check + "-Title" print testcase + " Test FAILED!" collect_score(testcase, run_result) except ViewNotFoundException: run_result = "fail" print title_check + " can not be found! Fatal!"
device, serialno = ViewClient.connectToDeviceOrExit() device.startActivity(component=component, uri=uri) ViewClient.sleep(5) vc = ViewClient(device=device, serialno=serialno) sdkVersion = vc.getSdkVersion() if sdkVersion > 10: device.drag((240, 180), (240, 420), 1, 20) else: for i in range(10): device.press('KEYCODE_DPAD_UP') ViewClient.sleep(1) vc.findViewByIdOrRaise(_id if sdkVersion >= 16 else 'id/url' if sdkVersion > 10 else 'id/title').touch() ViewClient.sleep(1) device.press('KEYCODE_DEL') device.type(VPS) ViewClient.sleep(1) device.press('KEYCODE_ENTER') ViewClient.sleep(3) vc.dump() print vc.findViewByIdOrRaise( 'id/no_id/11' if sdkVersion >= 16 else 'id/message').getText().replace( '\\n', "\n") device.press('KEYCODE_BACK' if sdkVersion > 10 else 'KEYCODE_ENTER')
#! /usr/bin/env python # -*- coding: utf-8 -*- import time from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') component='com.microsoft.emmx/com.microsoft.ruby.Main' device.startActivity(component=component) wait_for_id_and_touch(vc, 'com.microsoft.emmx:id/cancel_button') wait_for_id_and_touch(vc, 'com.microsoft.emmx:id/not_now') wait_for_id_and_touch(vc, 'com.microsoft.emmx:id/fre_share_not_now') wait_for_id_and_touch(vc, 'com.microsoft.emmx:id/no') wait_for_id(vc, 'com.microsoft.emmx:id/search_box_text') vc.findViewByIdOrRaise('com.microsoft.emmx:id/search_box_text').touch() wait_for_id(vc, 'com.microsoft.emmx:id/url_bar')
parent_dir = os.path.realpath(os.path.dirname(__file__)) f_output_result = "%s/../common/output-test-result.sh" % parent_dir kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = { 'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False } vc = ViewClient(device, serialno, **kwargs2) vc.dump() btn_run = vc.findViewByIdOrRaise("com.roywhet:id/startButton") btn_run.touch() time.sleep(2) finished = False key_unit_hash = { "N1": "MFLOPS", "N2": "MFLOPS", "N3": "MOPS", "N4": "MOPS", "N5": "MOPS", "N6": "MFLOPS", "N7": "MOPS", "N8": "MOPS", "MWIPS": "MFLOPS" }
call(['lava-test-case', testcase, '--result', run_result]) device, serialno = ViewClient.connectToDeviceOrExit() kwargs2 = { 'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False } vc = ViewClient(device, serialno, **kwargs2) try: return_word = vc.findViewByIdOrRaise( "com.android.browser:id/title").getText() except ViewNotFoundException: run_result = "fail" print "View can not be found! Fatal!" print testcase + " Test FAILED!" collect_score(testcase, run_result) sys.exit(1) if return_word == keyword: run_result = "pass" print testcase + " Test PASSED!" collect_score(testcase, run_result) else: print "Check point text doesn't match!" run_result = "fail" print testcase + " Test FAILED!"
import sys import os import time try: sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.viewclient import View from com.dtmilano.android.viewclient import ViewNotFoundException screen_one = ViewClient(*ViewClient.connectToDeviceOrExit()) email = screen_one.findViewByIdOrRaise("m_login_email") email.touch() email.setText("*****@*****.**") screen_one = ViewClient(*ViewClient.connectToDeviceOrExit()) passwd = screen_one.findViewByIdOrRaise("m_login_password") passwd.touch() passwd.setText("aragon911119") screen_one = ViewClient(*ViewClient.connectToDeviceOrExit()) loginbtn = screen_one.findViewByIdOrRaise("u_0_5") loginbtn.touch() time.sleep(5) done = False
activity = 'com.hoard.hoard.SplashScreen' # sets the name of the component to start runComponent = package + '/' + activity # Runs the component device.startActivity(component=runComponent) ViewClient.sleep(1) device.takeSnapshot(reconnect=True).save('./screenshots/register/login-to-register.png','png') vc = ViewClient(*ViewClient.connectToDeviceOrExit()) vc.dump() button = vc.findViewByIdOrRaise('com.hoard.hoard:id/login_register_button') button.touch() vc.dump() ViewClient.sleep(3) device.takeSnapshot(reconnect=True).save('./screenshots/register/register-pre.png','png') email = vc.findViewById('com.hoard.hoard:id/register_email') email.type('*****@*****.**') vc.dump() password = vc.findViewById('com.hoard.hoard:id/register_password') password.type('u1')
device, serialno = ViewClient.connectToDeviceOrExit() device.startActivity(component=component, uri=uri) ViewClient.sleep(5) vc = ViewClient(device=device, serialno=serialno) sdkVersion = vc.getSdkVersion() if sdkVersion > 10: device.drag((240, 180), (240, 420), 1, 20) else: for i in range(10): device.press('KEYCODE_DPAD_UP') ViewClient.sleep(1) vc.findViewByIdOrRaise(_id if sdkVersion >= 16 else 'id/url' if sdkVersion > 10 else 'id/title').touch() ViewClient.sleep(1) device.press('KEYCODE_DEL') device.type(VPS) ViewClient.sleep(1) device.press('KEYCODE_ENTER') ViewClient.sleep(3) vc.dump() print vc.findViewByIdOrRaise('id/no_id/11' if sdkVersion >= 16 else 'id/message').getText().replace('\\n', "\n") device.press('KEYCODE_BACK' if sdkVersion > 10 else 'KEYCODE_ENTER')
kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) time.sleep(2) vc.dump() btn_license = vc.findViewWithText(u'I Agree') if btn_license: btn_license.touch() while True: try: time.sleep(5) vc.dump() btn_start_on = vc.findViewByIdOrRaise("com.eembc.andebench:id/s1_runall") btn_start_on.touch() break except ViewNotFoundException: pass except RuntimeError: pass except ValueError: pass while(True): try: time.sleep(30) vc.dump('-1') vc.findViewByIdOrRaise("com.eembc.andebench:id/view_web_button")
FLAG_ACTIVITY_NEW_TASK = 0x10000000 package = 'com.example.i2at.tc' activity = '.TemperatureConverterActivity' componentName = package + "/" + activity device.startActivity(component=componentName, flags=FLAG_ACTIVITY_NEW_TASK) MonkeyRunner.sleep(5) device.type("123") MonkeyRunner.sleep(3) vc = ViewClient(device, serialno, startviewserver=(not localViewServer)) # obtain the views by id celsius = vc.findViewByIdOrRaise("id/celsius") fahrenheit = vc.findViewByIdOrRaise("id/fahrenheit") ct = celsius.getText() if ct: c = float(ct) else: print >> sys.stderr, "Celsius is empty" sys.exit(1) ft = fahrenheit.getText() if ft: f = float(ft) else: print >> sys.stderr, "Fahrenheit is empty" sys.exit(1) print "by id: %.2f C => %.2f F" % (c, f)
for p in os.environ['PYTHONPATH'].split(':'): if not p in sys.path: sys.path.append(p) except: pass try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from com.dtmilano.android.viewclient import ViewClient from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice # Starting: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.android.browser/.BrowserActivity } package = 'com.android.browser' activity = '.BrowserActivity' component = package + "/" + activity uri = 'http://dtmilano.blogspot.com' device, serialno = ViewClient.connectToDeviceOrExit() device.startActivity(component=component, uri=uri) MonkeyRunner.sleep(3) vc = ViewClient(device, serialno) url = vc.findViewByIdOrRaise("id/url").getText() if string.find(url, uri) != -1: print "%s successfully loaded" % uri else: print "%s was not loaded, url=%s" % (uri, url)
benchmark_name = "BenchmarkPi" kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = { 'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False } vc = ViewClient(device, serialno, **kwargs2) time.sleep(2) vc.dump(window='-1') start_button = vc.findViewByIdOrRaise("gr.androiddev.BenchmarkPi:id/Button01") start_button.touch() finished = False while (not finished): time.sleep(1) try: vc.dump(window='-1') vc.findViewByIdOrRaise("android:id/message") finished = True except ViewNotFoundException: pass except RuntimeError as e: print e print "benchmark finished"
ViewClient.sleep(1) device.takeSnapshot(reconnect=True).save('./screenshots/favorites/favorites-pre.png','png') vc = ViewClient(*ViewClient.connectToDeviceOrExit()) vc.dump() email = vc.findViewById('com.hoard.hoard:id/login_email') email.type('*****@*****.**') vc.dump() password = vc.findViewById('com.hoard.hoard:id/login_password') password.type('u1') button = vc.findViewByIdOrRaise('com.hoard.hoard:id/login_button') button.touch() vc.dump() device.takeSnapshot(reconnect=True).save('./screenshots/favorites/login-pos.png','png') ViewClient.sleep(3) device.takeSnapshot(reconnect=True).save('./screenshots/favorites/favorites-redirect.png','png') button = vc.findViewByIdOrRaise('com.hoard.hoard:id/favorite_button') button.touch() vc.dump()
#! /usr/bin/env python # -*- coding: utf-8 -*- import time from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') wait_for_id(vc, 'com.brave.browser:id/url_bar') vc.findViewByIdOrRaise('com.brave.browser:id/url_bar').setText( 'https://browserbench.org/Speedometer2.0/') adb.shell('input keyevent KEYCODE_ENTER') wait_for_text_and_touch(vc, 'Start Test') wait_for_text_and_touch(vc, 'Details', 420)
from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException return_word = "" testcase = "calculator" positive_counter = 0 def collect_score(testcase, run_result): call(['lava-test-case', testcase, '--result', run_result]) device, serialno = ViewClient.connectToDeviceOrExit() kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) for i in range(0, 10): try: return_word = vc.findViewByIdOrRaise("com.android.calculator2:id/digit" + str(i)).getText() if return_word != str(i): run_result = "fail" print "Number " + str(i) + " can not be found in " + testcase print testcase + " Test FAILED!" collect_score(testcase, run_result) sys.exit(1) else: print "Number " + str(i) + " found!" positive_counter = positive_counter + 1 except ViewNotFoundException: run_result = "fail" print "View can not be found! Fatal!" print testcase + " Test FAILED!" collect_score(testcase, run_result) sys.exit(1)
from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') component='org.mozilla.firefox/.App' device.startActivity(component=component) wait_for_id_and_touch(vc, 'org.mozilla.firefox:id/firstrun_link') wait_for_text(vc, 'Sync your bookmarks, history, and passwords to your phone.') vc.findViewByIdOrRaise('org.mozilla.firefox:id/firstrun_link').touch() wait_for_id_and_touch(vc, 'org.mozilla.firefox:id/firstrun_browse') try: wait_for_id_and_touch(vc,'close-button') except: pass wait_for_id_and_touch(vc, 'org.mozilla.firefox:id/url_bar_title') wait_for_id(vc, 'org.mozilla.firefox:id/url_edit_text') vc.findViewByIdOrRaise('org.mozilla.firefox:id/url_edit_text').setText('https://browserbench.org/MotionMark1.1/') adb.shell('input keyevent KEYCODE_ENTER') adb.shell('settings put system accelerometer_rotation 0') adb.shell('settings put system user_rotation 1') wait_for_text(vc, u'MotionMark is a graphics benchmark that measures a browser’s capability to animate complex scenes at a target frame rate.', 15) adb.shell('input swipe 500 1000 300 300') time.sleep(2)
device, serialno = ViewClient.connectToDeviceOrExit() device.startActivity(component=COMPONENT, uri=URI) MonkeyRunner.sleep(5) vc = ViewClient(device=device, serialno=serialno) sdkVersion = vc.getSdkVersion() if sdkVersion > 10: device.drag((240, 180), (240, 420), 1, 20) else: for i in range(10): device.press("KEYCODE_DPAD_UP", MonkeyDevice.DOWN_AND_UP) MonkeyRunner.sleep(1) url = vc.findViewByIdOrRaise("id/url" if sdkVersion > 10 else "id/title") url.touch() MonkeyRunner.sleep(1) device.press("KEYCODE_DEL", MonkeyDevice.DOWN_AND_UP) for c in VPS: device.type(c) MonkeyRunner.sleep(1) device.press("KEYCODE_ENTER", MonkeyDevice.DOWN_AND_UP) MonkeyRunner.sleep(3) vc.dump() print vc.findViewByIdOrRaise("id/message").getText().replace("\\n", "\n") device.press("KEYCODE_BACK" if sdkVersion > 10 else "KEYCODE_ENTER", MonkeyDevice.DOWN_AND_UP)
collect_score(benchmark_name, run_result, score_number, score_unit) cached_result_file = "last_results_2.5.1.xml" device, serialno = ViewClient.connectToDeviceOrExit() kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) time.sleep(2) vc.dump(window='-1') test_type = vc.findViewWithText("Performance Tests") test_type.touch() time.sleep(2) # By some reason in order to select all test, a back step is required vc.dump(window='-1') test_selection = vc.findViewByIdOrRaise("com.glbenchmark.glbenchmark25:id/buttonAll") device.press('KEYCODE_BACK') time.sleep(3) test_type.touch() time.sleep(2) test_selection.touch() print "All selected!" time.sleep(3) # Disable crashed test suites vc.dump(window='-1') crashed_test_name = "C24Z24MS4" print "Test suite " + crashed_test_name + " is going to be disabled!" crashed_test = vc.findViewWithText(crashed_test_name) if crashed_test != None:
# -*- coding: utf-8 -*- import time import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') wait_for_id_and_touch(vc, 'org.mozilla.firefox:id/url_bar_title') wait_for_id(vc, 'org.mozilla.firefox:id/url_edit_text') vc.findViewByIdOrRaise('org.mozilla.firefox:id/url_edit_text').setText( 'https://browserbench.org/JetStream/') adb.shell('input keyevent KEYCODE_ENTER') wait_for_text_and_touch(vc, 'Start Test', 15) # turn off firefox running long scripts prevention try: wait_for_text_and_touch(vc, u'Don’t ask me again', 200) wait_for_text_and_touch(vc, u'CONTINUE') except: pass wait_for_id(vc, 'result-summary', 1320)
import sys import os import time from subprocess import call from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) #Wait while application loads time.sleep(2) #Start test button vc.dump(window='-1') btn_classic = vc.findViewByIdOrRaise("com.into.stability:id/button1") btn_classic.touch() print ("Start Stability Test") #Wait time.sleep(30) print ("Start Stability Finished") adsf """ time.sleep(2) detail_button = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/detail_btn") detail_button.touch() print("detail_btn")
#! /usr/bin/env python # -*- coding: utf-8 -*- import time from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') component = 'com.andrewshu.android.reddit/.MainActivity' device.startActivity(component=component) wait_for_id_and_touch(vc, 'content-denyLabel') wait_for_id(vc, 'content-closeWindowLabel') # close overlay device.touch(575, 1719, 'DOWN_AND_UP') wait_for_id_and_touch(vc, 'android:id/button1') # open drawer device.touch(100, 108, 'DOWN_AND_UP') wait_for_id(vc, 'com.andrewshu.android.reddit:id/subreddit_input') vc.findViewByIdOrRaise( 'com.andrewshu.android.reddit:id/subreddit_input').setText('energio') time.sleep(2)
@author: diego ''' import re import sys import os try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from com.dtmilano.android.viewclient import ViewClient, TextView, EditText device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device=device, serialno=serialno) #send = vc.findViewWithTextOrRaise('Send') send = vc.findViewByIdOrRaise('id/send') #to = EditText(vc.findViewByIdOrRaise('id/to')) to = vc.findViewByIdOrRaise('id/to') subject = vc.findViewByIdOrRaise('id/subject') subject.touch() subject.type('AVCSample') ViewClient.sleep(10) to.touch() #to.type('*****@*****.**') device.type('*****@*****.**') ViewClient.sleep(10) send.touch()
""" # Error Check vc.dump(window='-1') try: # vc.findViewByIdOrRaise("com.antutu.ABenchMar:id/negative_btn") attention_ok_button = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/negative_btn") attention_ok_button.touch() print ("Pass the Attention Error..") except: # print "No Attention error" pass """ #Start test button vc.dump(window='-1') start_button = vc.findViewByIdOrRaise("com.antutu.ABenchMark:id/test_btn") start_button.touch() print("Test_Btn") #Start all test button vc.dump(window='-1') start_test_button = vc.findViewByIdOrRaise( "com.antutu.ABenchMark:id/start_test_text") start_test_button.touch() print("Start_test_text") #Wait while antutu5 is running benchmark finished = False time.sleep(240)
import os import time from subprocess import call from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException parent_dir = os.path.realpath(os.path.dirname(__file__)) f_output_result="%s/../common/output-test-result.sh" % parent_dir kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) vc.dump(window=-1, sleep=5) btn_jbench = vc.findViewByIdOrRaise("it.JBench.bench:id/button1") btn_jbench.touch() time.sleep(2) finished = False while(not finished): try: time.sleep(5) vc.dump() results = vc.findViewByIdOrRaise("it.JBench.bench:id/textViewResult") if re.search('^\d+$', results.getText()): finished = True print "benchmark finished" print "%s=%s" % ("JBench", results.getText().strip()) call([f_output_result, "JBench", 'pass', results.getText().strip(), "points"]) except ViewNotFoundException:
from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') component = 'com.android.chrome/com.google.android.apps.chrome.Main' device.startActivity(component=component) wait_for_id_and_touch(vc, 'com.android.chrome:id/send_report_checkbox') vc.findViewByIdOrRaise('com.android.chrome:id/terms_accept').touch() wait_for_id_and_touch(vc, 'com.android.chrome:id/negative_button') wait_for_id_and_touch(vc, 'com.android.chrome:id/search_box_text') wait_for_id(vc, 'com.android.chrome:id/url_bar') vc.findViewByIdOrRaise('com.android.chrome:id/url_bar').setText( 'https://browserbench.org/MotionMark1.1/') adb.shell('input keyevent KEYCODE_ENTER') adb.shell('settings put system accelerometer_rotation 0') adb.shell('settings put system user_rotation 1') wait_for_text( vc, u'MotionMark is a graphics benchmark that measures a browser’s capability to animate complex scenes at a target frame rate.', 15) # device.drag(448,1368),(1000,1368),0.1,3) adb.shell('input swipe 448 1368 1000 1368')
time.sleep(0.5) else: vc.findViewByIdOrRaise(id).touch() return def wait_for_text(vc, 'text): while True: vc.dump(window=-1) if vc.findViewWithText(text) is None: time.sleep(0.5) else: return def wait_for_text_and_touch(vc, 'text): while True: vc.dump(window=-1) if vc.findViewWithText(text) is None: time.sleep(0.5) else: vc.findViewWithText(text).touch() return vc.dump(window=-1) wait_for_id(vc, 'com.microsoft.emmx:id/search_box_text') vc.findViewByIdOrRaise('com.microsoft.emmx:id/search_box_text').touch() wait_for_id(vc, 'com.microsoft.emmx:id/url_bar') vc.findViewByIdOrRaise('com.microsoft.emmx:id/url_bar').setText('https://browserbench.org/Speedometer2.0/') adb.shell('input keyevent KEYCODE_ENTER') wait_for_text_and_touch(vc, 'Start Test') wait_for_text_and_touch(vc, 'Details', 420)
from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') component = 'com.brave.browser/com.google.android.apps.chrome.Main' device.startActivity(component=component) wait_for_id_and_touch(vc, 'com.brave.browser:id/btn_next') wait_for_text(vc, 'Brave Shields') vc.findViewByIdOrRaise('com.brave.browser:id/btn_next').touch() wait_for_text(vc, 'Brave Rewards') vc.findViewByIdOrRaise('com.brave.browser:id/btn_skip').touch() wait_for_id(vc, 'com.brave.browser:id/url_bar') vc.findViewByIdOrRaise('com.brave.browser:id/url_bar').setText( 'https://browserbench.org/MotionMark1.1/') adb.shell('input keyevent KEYCODE_ENTER') adb.shell('settings put system accelerometer_rotation 0') adb.shell('settings put system user_rotation 1') wait_for_text( vc, u'MotionMark is a graphics benchmark that measures a browser’s capability to animate complex scenes at a target frame rate.', 15) adb.shell('input swipe 500 1000 300 300') time.sleep(2)
#! /usr/bin/env python # -*- coding: utf-8 -*- import time from com.dtmilano.android.viewclient import ViewClient from com.dtmilano.android.adb import adbclient import sys, os sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))) from common import * device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) adb = adbclient.AdbClient(serialno='.*') wait_for_id(vc, 'com.brave.browser:id/url_bar') vc.findViewByIdOrRaise('com.brave.browser:id/url_bar').setText('https://browserbench.org/JetStream/') adb.shell('input keyevent KEYCODE_ENTER') wait_for_text_and_touch(vc, 'Start Test', 15) wait_for_id(vc, 'result-summary', 1320)
import os import time from subprocess import call from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException parent_dir = os.path.realpath(os.path.dirname(__file__)) f_output_result="%s/../common/output-test-result.sh" % parent_dir kwargs1 = {'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True, 'compresseddump': False} vc = ViewClient(device, serialno, **kwargs2) vc.dump() btn_run = vc.findViewByIdOrRaise("com.LinpackJava:id/startButton") btn_run.touch() time.sleep(2) finished = False while(not finished): try: time.sleep(5) vc.dump() results = vc.findViewByIdOrRaise("com.LinpackJava:id/displayDetails") res_match = re.search('Speed\s+(?P<measurement>[\d\.]+)\s+MFLOPS', results.getText()) if res_match: finished = True print "benchmark finished" speed = res_match.group('measurement').strip() print "%s=%s MFLOPS" % ("LinpackJava_Speed", speed)