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()
class ViewClientWrapper: def __init__(self, serialno): device, serialno = ViewClient.connectToDeviceOrExit(serialno=serialno) self.viewClient = ViewClient(device, serialno) if DEBUG: print >> sys.stderr, "ViewClientWrapper: connected to", device, serialno def dump(self): """Dumps window hierarchy.""" return self.viewClient.dump() def start_activity(self, component): """Starts Activity.""" return self.viewClient.device.startActivity(component) def long_touch_button(self, text): """Long-touches the button.""" self.viewClient.findViewWithTextOrRaise(text).longTouch()
Copyright (C) 2012 Diego Torres Milano Created on Feb 3, 2012 @author: diego ''' import sys import os # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it 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 device, serialno = ViewClient.connectToDeviceOrExit(ignoresecuredevice=True) vc = ViewClient(device=device, serialno=serialno, startviewserver=False) vc.findViewWithTextOrRaise("New activity").touch()
Created on Aug 31, 2012 @author: diego ''' import re import sys import os # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it 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, View vc = ViewClient(*ViewClient.connectToDeviceOrExit()) button = vc.findViewWithTextOrRaise('Show Dialog') print "button: ", button.getClass(), button.getId(), button.getCoords()
''' import re import sys import os # This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it 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, View from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice vc = ViewClient(*ViewClient.connectToDeviceOrExit()) button = vc.findViewWithTextOrRaise('Show Dialog') print "button: ", button.getClass(), button.getId(), button.getCoords()
class contacts: ''' contacts class ''' def __init__(self, device, devID='emulator-5554', sample=False): ''' constructor @type device: MonkeyDevice @param device: The device or emulator connected @type devID: str @param serialno: the serial number of the device or emulator to connect to @type sample: boolean @param sample: whether take snapshot as an sampling ''' self.device = device self.sample = sample self.startStatus = False '''the status which indicate whether the contacts activity is started''' self.vc = ViewClient(device, devID) #use below code to remove the status bar from the snapshot width = int(device.getProperty('display.width')) height = int(device.getProperty('display.height')) density = device.getProperty('display.density') if density == .75: statusBarHeight = 19 elif density == 1.5: statusBarHeight = 38 elif density == 2.0: statusBarHeight = 50 else: statusBarHeight = 25 self.snap_rect = 0, statusBarHeight, width, height - statusBarHeight def start(self): ''' start the contacts activity and set the startStatus True if contacts is ready. ''' self.device.startActivity(component=componentName) sleep(3) self.startStatus = self.isReady() def back(self): ''' press back ''' self.device.press('KEYCODE_BACK', 'DOWN_AND_UP') def getView(self, str, cD=False, iD=False): ''' get the view with the specified text, content description or viewId @type str: str @param str: the query string @type cD: boolean @param cD: whether handle the query str as content description @type iD: boolean @param iD: whether handle the query str as viewId @return: the view found ''' self.vc.dump() sleep(3) if not cD: if not iD: return self.vc.findViewWithText(str) else: return self.vc.findViewById(str) else: return self.vc.findViewWithContentDescription(str) def isReady(self): ''' check whether the contacts is ready. ''' while True: view = self.getView( 'Contact list is being updated to reflect the change of language.' ) if not view: trace('Contacts is ready') break else: trace('Contacts is not ready, please wait!') sleep(2) return True def goEdit(self): ''' check whether the contact is empty, then select adding and go to edit view. @return: True ''' self.check() view = self.getView('Create a new contact') if view: view.touch() trace('Click "Create a new contact"') view = self.getView('Keep local') if view: view.touch() trace('Select "Keep local"') else: view = self.getView('Add Contact', True) view.touch() trace('Click "Add Contact"') return True def check(self): ''' check whether the contacts is started before other operation about contacts @return: True ''' if not self.status: trace("Wrong code! please start contacts firstly in you code") raise SyntaxError('contacts should be start firstly!') return True def snapshot(self, title): ''' take snapshot @type title: str @param title: specify the title of snapshot ''' snapName = title + '.png' snapFile = logPath + '\\' + snapName result = self.device.takeSnapshot().getSubImage(self.snap_rect) result.writeToFile(snapFile, 'png') def addContact(self, name='', phone='', email=''): #notice firstly call self.goEdit() pass def editDetails(self, phone=''): pass def search(self, str): ''' @type str: str @param str: specify the search keyword ##@return: the view of search result if search result is not null, else return None ''' trace("start searching...") trace("check contact main UI, dump, please wait...") self.vc.dump() while not self.getView("Search", True): self.device.press('KEYCODE_BACK') sleep(2) self.vc.dump() searchView = self.getView("Search", True) searchView.touch() self.device.type(str) trace("search keyword is: " + str) self.snapshot("search_result") ''' tmp=[] self.vc.dump() trace("dump, please wait...") #the id of 1st search result is always 28 for i in self.vc.findViewsContainingPoint((100,200)): tmp.append(i.getId()) result=int(tmp[len(tmp)-1][-2:]) if(result<28): trace("search result: nothing") return None else: self.snapshot("search_result") return self.vc.findViewById(tmp[len(tmp)-1]) ''' def sortAs(self, sortByFirstName=True): ''' sort contact name @type sortByFirstName: boolean @param sortByFirstName: whether sort contact name by first name ''' trace("check contact main UI, dump, please wait...") self.vc.dump() while not self.getView("Search", True): self.device.press('KEYCODE_BACK') sleep(2) self.vc.dump() trace("start sorting...") self.device.press("KEYCODE_MENU", "DOWN_AND_UP") trace("click menu, dump, please wait...") self.vc.dump() settingsView = self.getView("Settings") settingsView.touch() sleep(2) trace("click Settings, dump, please wait...") self.vc.dump() self.vc.findViewWithTextOrRaise("Sort list by").touch() trace("click Sort list by, dump, please wait...") self.vc.dump() if sortByFirstName: self.vc.findViewWithTextOrRaise("First name").touch() else: self.vc.findViewWithTextOrRaise("Last name").touch() sleep(2) #conflict with check at the begining #self.device.press("KEYCODE_BACK","DOWN_AND_UP") #sleep(2) def viewAs(self, viewAsFirstNameFirst=True): ''' view contact name @type viewAsFirstNameFirst: boolean @param viewAsFirstNameFirst: whether view contact by first name first ''' trace("check contact main UI, dump, please wait...") self.vc.dump() while not self.getView("Search", True): self.device.press('KEYCODE_BACK') sleep(2) self.vc.dump() trace("start viewing...") self.device.press("KEYCODE_MENU", "DOWN_AND_UP") trace("click menu, dump, please wait...") self.vc.dump() settingsView = self.getView("Settings") settingsView.touch() sleep(2) trace("click Settings, dump, please wait...") self.vc.dump() self.vc.findViewWithTextOrRaise("View contact names as").touch() trace("click View contact names as, dump, please wait...") self.vc.dump() if viewAsFirstNameFirst: self.vc.findViewWithTextOrRaise("First name first").touch() else: self.vc.findViewWithTextOrRaise("Last name first").touch() sleep(2) #conflict with check at the begining #self.device.press("KEYCODE_BACK","DOWN_AND_UP") #sleep(2) def favorite(self, name=''): pass
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") vc.findViewWithTextOrRaise(u'3D').touch() vc.findViewWithTextOrRaise(u'Platform').touch() vc.findViewWithTextOrRaise(u'Storage').touch() vc.findViewWithTextOrRaise(u'Memory Latency').touch() vc.findViewWithTextOrRaise(u'Memory Bandwidth').touch() vc.findViewWithTextOrRaise(u'CoreMark-HPC (Peak)').touch() vc.findViewWithTextOrRaise(u'CoreMark-HPC (Base)').touch() break except ViewNotFoundException: pass except RuntimeError: pass except ValueError: pass
class contacts: ''' contacts class ''' def __init__(self, device, devID='emulator-5554',sample = False): ''' constructor @type device: MonkeyDevice @param device: The device or emulator connected @type devID: str @param serialno: the serial number of the device or emulator to connect to @type sample: boolean @param sample: whether take snapshot as an sampling ''' self.device=device self.sample=sample self.startStatus=False '''the status which indicate whether the contacts activity is started''' self.vc=ViewClient(device, devID) #use below code to remove the status bar from the snapshot width = int(device.getProperty('display.width')) height = int(device.getProperty('display.height')) density = device.getProperty('display.density') if density == .75: statusBarHeight = 19 elif density == 1.5: statusBarHeight = 38 elif density == 2.0: statusBarHeight = 50 else: statusBarHeight = 25 self.snap_rect = 0, statusBarHeight, width, height - statusBarHeight def start(self): ''' start the contacts activity and set the startStatus True if contacts is ready. ''' self.device.startActivity(component=componentName) sleep(3) self.startStatus = self.isReady() def back(self): ''' press back ''' self.device.press('KEYCODE_BACK','DOWN_AND_UP') def getView(self,str,cD=False,iD=False): ''' get the view with the specified text, content description or viewId @type str: str @param str: the query string @type cD: boolean @param cD: whether handle the query str as content description @type iD: boolean @param iD: whether handle the query str as viewId @return: the view found ''' self.vc.dump() sleep(3) if not cD: if not iD: return self.vc.findViewWithText(str) else: return self.vc.findViewById(str) else: return self.vc.findViewWithContentDescription(str) def isReady(self): ''' check whether the contacts is ready. ''' while True: view=self.getView('Contact list is being updated to reflect the change of language.') if not view: trace('Contacts is ready') break else: trace('Contacts is not ready, please wait!') sleep(2) return True def goEdit(self): ''' check whether the contact is empty, then select adding and go to edit view. @return: True ''' self.check() view=self.getView('Create a new contact') if view: view.touch() trace('Click "Create a new contact"') view=self.getView('Keep local') if view: view.touch() trace('Select "Keep local"') else: view=self.getView('Add Contact',True) view.touch() trace('Click "Add Contact"') return True def check(self): ''' check whether the contacts is started before other operation about contacts @return: True ''' if not self.status: trace("Wrong code! please start contacts firstly in you code") raise SyntaxError('contacts should be start firstly!') return True def snapshot(self,title): ''' take snapshot @type title: str @param title: specify the title of snapshot ''' snapName = title + '.png' snapFile = logPath + '\\' + snapName result = self.device.takeSnapshot().getSubImage(self.snap_rect) result.writeToFile(snapFile,'png') def addContact(self,name='',phone='',email=''): #notice firstly call self.goEdit() pass def editDetails(self,phone=''): pass def search(self,str): ''' @type str: str @param str: specify the search keyword ##@return: the view of search result if search result is not null, else return None ''' trace("start searching...") trace("check contact main UI, dump, please wait...") self.vc.dump() while not self.getView("Search",True): self.device.press('KEYCODE_BACK') sleep(2) self.vc.dump() searchView=self.getView("Search",True) searchView.touch() self.device.type(str) trace("search keyword is: "+str) self.snapshot("search_result") ''' tmp=[] self.vc.dump() trace("dump, please wait...") #the id of 1st search result is always 28 for i in self.vc.findViewsContainingPoint((100,200)): tmp.append(i.getId()) result=int(tmp[len(tmp)-1][-2:]) if(result<28): trace("search result: nothing") return None else: self.snapshot("search_result") return self.vc.findViewById(tmp[len(tmp)-1]) ''' def sortAs(self, sortByFirstName=True): ''' sort contact name @type sortByFirstName: boolean @param sortByFirstName: whether sort contact name by first name ''' trace("check contact main UI, dump, please wait...") self.vc.dump() while not self.getView("Search",True): self.device.press('KEYCODE_BACK') sleep(2) self.vc.dump() trace("start sorting...") self.device.press("KEYCODE_MENU","DOWN_AND_UP") trace("click menu, dump, please wait...") self.vc.dump() settingsView=self.getView("Settings") settingsView.touch() sleep(2) trace("click Settings, dump, please wait...") self.vc.dump() self.vc.findViewWithTextOrRaise("Sort list by").touch() trace("click Sort list by, dump, please wait...") self.vc.dump() if sortByFirstName: self.vc.findViewWithTextOrRaise("First name").touch() else: self.vc.findViewWithTextOrRaise("Last name").touch() sleep(2) #conflict with check at the begining #self.device.press("KEYCODE_BACK","DOWN_AND_UP") #sleep(2) def viewAs(self, viewAsFirstNameFirst=True): ''' view contact name @type viewAsFirstNameFirst: boolean @param viewAsFirstNameFirst: whether view contact by first name first ''' trace("check contact main UI, dump, please wait...") self.vc.dump() while not self.getView("Search",True): self.device.press('KEYCODE_BACK') sleep(2) self.vc.dump() trace("start viewing...") self.device.press("KEYCODE_MENU","DOWN_AND_UP") trace("click menu, dump, please wait...") self.vc.dump() settingsView=self.getView("Settings") settingsView.touch() sleep(2) trace("click Settings, dump, please wait...") self.vc.dump() self.vc.findViewWithTextOrRaise("View contact names as").touch() trace("click View contact names as, dump, please wait...") self.vc.dump() if viewAsFirstNameFirst: self.vc.findViewWithTextOrRaise("First name first").touch() else: self.vc.findViewWithTextOrRaise("Last name first").touch() sleep(2) #conflict with check at the begining #self.device.press("KEYCODE_BACK","DOWN_AND_UP") #sleep(2) def favorite(self,name=''): pass
except: pass from com.dtmilano.android.viewclient import ViewClient # 01-04 18:23:42.000: I/ActivityManager(4288): Displayed com.android.development/.DevelopmentSettings: +379ms package = 'com.android.development' activity = '.DevelopmentSettings' component = package + "/" + activity device, serialno = ViewClient.connectToDeviceOrExit() device.startActivity(component=component) ViewClient.sleep(5) vc = ViewClient(device, serialno) showCpu = vc.findViewWithTextOrRaise("Show CPU usage") showLoad = vc.findViewWithTextOrRaise("Show running processes") alwaysFinish = vc.findViewWithTextOrRaise("Immediately destroy activities") if not showLoad.isChecked(): print "touching @", showLoad.getCenter() showLoad.touch() if not alwaysFinish.isChecked(): print "touching @", alwaysFinish.getCenter() alwaysFinish.touch() if not showCpu.isChecked(): # WARNING: Show CPU usage is de-activated as soon as it's activated, that's why it seems it # is never set print "touching @", showCpu.getCenter()
"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") vc.findViewWithTextOrRaise(u'3D').touch() vc.findViewWithTextOrRaise(u'Platform').touch() vc.findViewWithTextOrRaise(u'Storage').touch() vc.findViewWithTextOrRaise(u'Memory Latency').touch() vc.findViewWithTextOrRaise(u'Memory Bandwidth').touch() vc.findViewWithTextOrRaise(u'CoreMark-HPC (Peak)').touch() vc.findViewWithTextOrRaise(u'CoreMark-HPC (Base)').touch() break except ViewNotFoundException: pass except RuntimeError: pass except ValueError: pass
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"
import os import time from subprocess import call from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException 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:
if flag == 0: pass elif len(exception) > 0: step_results.append("Failed") exception_result.append(exception) exception = [] else: step_results.append("Passed") exception_result.append("None") start = int(time.time()) flag = 1 try: vc.findViewWithTextOrRaise('7').touch() vc.sleep(3) except Exception as e: exception.append(str(e)) try: vc.dump(window=-1) except Exception as e: pass try: value = pick_value('/media/gn/Work/AQM/PY_RepV2.0/logsample.xlsx', 'Data', 'Petal_width', [0, 5]) vc.findViewWithTextOrRaise(value).touch() vc.sleep(3) except Exception as e: exception.append(str(e))
# run the component device.startActivity(component=runComponent) vc.dump(window='-1') # find a view by id org_thoughtcrime_securesms___id_fab = vc.findViewByIdOrRaise( "org.thoughtcrime.securesms:id/fab") if org_thoughtcrime_securesms___id_fab: # click the view org_thoughtcrime_securesms___id_fab.touch() vc.dump(window='0') # find a Contact by its text org_thoughtcrime_securesms___id_name = vc.findViewWithTextOrRaise(u'Tomi') if org_thoughtcrime_securesms___id_name: org_thoughtcrime_securesms___id_name.touch() vc.dump() org_thoughtcrime_securesms___id_embedded_text_editor = vc.findViewWithTextOrRaise( u'Signal message') if org_thoughtcrime_securesms___id_embedded_text_editor: org_thoughtcrime_securesms___id_embedded_text_editor.touch() print "typing..." # type in a device device.type('Test') vc.dump() org_thoughtcrime_securesms___id_send_button = vc.findViewByIdOrRaise(
import sys import os try: sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from com.dtmilano.android.viewclient import ViewClient TAG = 'CULEBRA' _s = 5 _v = '--verbose' in sys.argv kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True} vc = ViewClient(device, serialno, **kwargs2) #vc.dump(window='-1') # FIXME: seems not needed #vc.dump(window=-1) #vc.findViewByIdOrRaise("com.example.android.apis:id/username_edit").setText(u"hello culebra!") #vc.sleep(_s) vc.dump(window=-1) vc.findViewWithTextOrRaise(u'*****@*****.**').touch() vc.dump(window=-1) vc.findViewWithTextOrRaise(u'OK').touch()
# set a variable with the package's internal name package = 'com.viber.voip' # set a variable with the name of an Activity in the package activity = '.WelcomeActivity' # set the name of the component to start 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')
def dump_always(): success = False while not success: try: vc.dump() success = True except RuntimeError: print("Got RuntimeError when call vc.dump()") time.sleep(5) except ValueError: 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())
# This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it 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 package = 'com.example.trashcan' activity = '.FullScreenActivity' component = package + "/" + activity device, serialno = ViewClient.connectToDeviceOrExit() #device.startActivity(component=component) #ViewClient.sleep(3) vc = ViewClient(device, serialno) button = vc.findViewWithTextOrRaise('Button') button.touch() toggle = vc.findViewWithTextOrRaise(re.compile('(ON)|(OFF)')) toggle.touch()
vc.findViewByIdOrRaise('com.olx.olx:id/posting_title_button').touch() # vc.sleep(_s) vc.dump(window=-1) # pantalla de ingresar el precio vc.findViewByIdOrRaise('com.olx.olx:id/posting_price').setText(price) vc.findViewByIdOrRaise('com.olx.olx:id/posting_price_button').touch() vc.sleep(_s) vc.dump(window=-1) category_window = vc.findViewById('com.olx.olx:id/category_breadcrumb') if vc.findViewById('com.olx.olx:id/category_breadcrumb'): category_selector = vc.findViewWithText(category) while not category_selector: #maybe you need to scroll... (x, y, w, h) = category_window.getPositionAndSize() start = ((x + w) / 2, y + h) end = ((x + w) / 2, y) device.drag(start, end, 30) vc.dump(window=-1) category_selector = vc.findViewWithText(category) category_selector.touch() vc.dump(window=-1) vc.findViewWithTextOrRaise(subcat).touch() vc.sleep(_s) vc.dump(window=-1) vc.findViewByIdOrRaise('com.olx.olx:id/posting_publish_button').touch() print "Test took", time.time() - start_time, "seconds"
if flag==0: pass elif len(exception) > 0: step_results.append("Failed") exception_result.append(exception) exception = [] else: step_results.append("Passed") exception_result.append("None") start = int(time.time()) flag=1 try: vc.findViewWithTextOrRaise('December 2018 arrow dropright').touch() vc.sleep(3) except Exception as e: exception.append(str(e)) try: vc.dump(window = -1) except Exception as e: pass try: vc.findViewWithTextOrRaise('2').touch() vc.sleep(3) except Exception as e: exception.append(str(e)) try: vc.dump(window = -1)
vc.findViewByIdOrRaise('com.olx.olx:id/posting_title').setText(title) vc.findViewByIdOrRaise('com.olx.olx:id/posting_title_button').touch() # vc.sleep(_s) vc.dump(window=-1) # pantalla de ingresar el precio vc.findViewByIdOrRaise('com.olx.olx:id/posting_price').setText(price) vc.findViewByIdOrRaise('com.olx.olx:id/posting_price_button').touch() # vc.sleep(_s) vc.dump(window=-1) print "elapsed", round(time.time() - start_time), "seconds" # TODO: verificar que salga la ventana de categorias if vc.findViewById('com.olx.olx:id/category_breadcrumb'): vc.findViewWithTextOrRaise(unicode(category, utf)).touch() vc.dump(window=-1) vc.findViewWithTextOrRaise(unicode(subcat, utf)).touch() vc.sleep(_s) #pre-caching fields vc.dump(window=-1) make_field = vc.findViewWithTextOrRaise("Marca / Modelo") year_field = vc.findViewWithTextOrRaise(u'Año') condition_field = vc.findViewWithTextOrRaise(u'Condición') publish_btn = vc.findViewByIdOrRaise('com.olx.olx:id/posting_publish_button') # modelo / marca make_field.touch() vc.dump(window=-1) vc.findViewWithTextOrRaise(unicode(make, utf)).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) 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:
import re import sys import os try: sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from com.dtmilano.android.viewclient import ViewClient TAG = 'CULEBRA' _s = 5 _v = '--verbose' in sys.argv kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True} vc = ViewClient(device, serialno, **kwargs2) #vc.dump(window='-1') # FIXME: seems not needed #vc.dump(window=-1) #vc.findViewByIdOrRaise("com.example.android.apis:id/username_edit").setText(u"hello culebra!") #vc.sleep(_s) vc.dump(window=-1) vc.findViewWithTextOrRaise(u'Cancel').touch()
# PyDev sets PYTHONPATH, use it 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, ViewNotFoundException vc = ViewClient(*ViewClient.connectToDeviceOrExit()) if vc.useUiAutomator: print "ViewClient: using UiAutomator backend" # Find the 3 toggle buttons, because the first 2 change their text if they are selected # we use a regex to find them. # Once found, we touch them changing their state for t in [ re.compile('Button 1 .*'), re.compile('Button 2 .*'), 'Button with ID' ]: try: vc.findViewWithTextOrRaise(t).touch() except ViewNotFoundException: print >> sys.stderr, "Couldn't find button with text=", t
ad_end_screen = ViewClient(*ViewClient.connectToDeviceOrExit()) ready_to_install = False while ready_to_install == False: try: install_btn = ad_end_screen.findViewByIdOrRaise("GEC CTA Button") ready_to_install = True install_btn.touch() except ViewNotFoundException: print 'ad not ended' time.sleep(1) time.sleep(2) play_store_screen = ViewClient(*ViewClient.connectToDeviceOrExit()) play_store_install_btn = play_store_screen.findViewWithTextOrRaise("INSTALL") play_store_install_btn.touch() time.sleep(10) ready_to_open = False while ready_to_open == False: try: app_installed_screen = ViewClient(*ViewClient.connectToDeviceOrExit()) open_btn = app_installed_screen.findViewWithTextOrRaise("OPEN") ready_to_open = True open_btn.touch() except ViewNotFoundException: print 'still installing' time.sleep(10)
# otherwise the import fails. # PyDev sets PYTHONPATH, use it 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 package = 'com.example.trashcan' activity = '.FullScreenActivity' component = package + "/" + activity device, serialno = ViewClient.connectToDeviceOrExit() #device.startActivity(component=component) #ViewClient.sleep(3) vc = ViewClient(device, serialno) button = vc.findViewWithTextOrRaise('Button') button.touch() toggle = vc.findViewWithTextOrRaise(re.compile('(ON)|(OFF)')) toggle.touch()
# This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. # PyDev sets PYTHONPATH, use it 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, ViewNotFoundException vc = ViewClient(*ViewClient.connectToDeviceOrExit()) if vc.useUiAutomator: print "ViewClient: using UiAutomator backend" # Find the 3 toggle buttons, because the first 2 change their text if they are selected # we use a regex to find them. # Once found, we touch them changing their state for t in [re.compile('Button 1 .*'), re.compile('Button 2 .*'), 'Button with ID']: try: vc.findViewWithTextOrRaise(t).touch() except ViewNotFoundException: print >>sys.stderr, "Couldn't find button with text=", t
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 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
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") chapters = ['Browser', 'Multicore', 'Metal'] for chapter in chapters: choose_chapter(vc, chapter) # Start benchmark vc_dump(vc) btn_start = vc.findViewByIdOrRaise("com.quicinc.vellamo:id/main_toolbar_operation_button") btn_start.touch() # Wait while Vellamo is running benchmark
try: vc.dump(window=-1) except Exception as e: pass try: vc.findViewByIdOrRaise('id/no_id/29').setText('aaa') except Exception as e: exception.append(str(e)) try: vc.dump(window=-1) except Exception as e: pass try: vc.findViewWithTextOrRaise('LOG IN').touch() vc.sleep(3) except Exception as e: exception.append(str(e)) try: vc.dump(window=-1) except Exception as e: pass end = int(time.time()) try: total = end - start time_result.append(total) except NameError as e:
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") chapters = ["Browser", "Multicore", "Metal"] for chapter in chapters: choose_chapter(vc, chapter) # Start benchmark vc_dump(vc) btn_start = vc.findViewByIdOrRaise("com.quicinc.vellamo:id/main_toolbar_operation_button") btn_start.touch() # Wait while Vellamo is running benchmark
success = False while not success: try: vc.dump() success = True except RuntimeError: print("Got RuntimeError when call vc.dump()") time.sleep(5) except ValueError: 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"):
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()) vc.dump() no_id7 = vc.findViewWithContentDescriptionOrRaise( u'''Photo''') no_id7.touch() logger.info('select photo', extra=get_extra_data()) #ViewClient.sleep(10) vc.dump() ViewClient.sleep(5) com_whatsapp___id_send = vc.findViewByIdOrRaise( "com.whatsapp:id/send") com_whatsapp___id_send.touch()
prop_type = config.get(section, "prop_type") sellr_type = unicode( config.get(section, "sellr_type"), 'utf-8' ) kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True} vc = ViewClient(device, serialno, **kwargs2) device.startActivity( main_activity ) vc.sleep(_s) ## STARTUP # pantalla principal vc.dump(window=-1) vc.findViewWithTextOrRaise(u'Vender').touch() vc.sleep(_s) vc.dump(window=-1) if vc.findViewById('com.olx.olx:id/retry_catalog'): print "connection fail modal appears, fff" vc.findViewByIdOrRaise('com.olx.olx:id/retry_catalog').touch() ## pantalla de elegir foto vc.dump(window=-1) vc.findViewByIdOrRaise('id/no_id/11').touch() #primer elemento de la grilla vc.dump(window=-1) vc.findViewWithTextOrRaise(u'Usar fotos').touch() # vc.sleep(_s) vc.dump(window=-1)