def SetWifiConnect(vc): package = 'com.android.settings' activity = '.Settings' component_name = package + '/' + activity ap_name = "dlink-549" ap_password = "******" # Open the Settings app vc.device.startActivity(component=component_name) # Enable Wi-Fi vc.device.shell("svc wifi enable") vc.dump() wifi = vc.findViewWithTextOrRaise(u'Wi‑Fi') if wifi: wifi.touch() vc.dump() i = 0 br_ap=vc.findViewWithText(ap_name) while not br_ap and i<30: br_ap=vc.findViewWithText(ap_name) ViewClient.sleep(1) vc.dump() i += 1 if i == 30: print "Cannot enable Wi-Fi" br_ap.touch() vc.device.type(ap_password) vc.dump() connect = vc.findViewWithText(u'Connect') if connect: connect.touch() vc.sleep(3)
def __call__(self): vc = ViewClient(self.__device, self.__serialno) steps = 90 start_factor = .75 end_factor = .55 if self.__serialno == "04a38409344082e7": steps = 90 start_factor = .75 end_factor = .55 elif self.__serialno == "010e3939219f5389": steps = 155 start_factor = .70 end_factor = .45 elif self.__serialno == "22db15d035057ece": steps = 200 start_factor = .65 end_factor = .35 elif self.__serialno == "8aee2aaa": steps = 100 start_factor = .75 end_factor = .55 info = self.__device.getDisplayInfo() x = int(info['width'] * .5) start_y = int(info['height'] * start_factor) end_y = int(info['height'] * end_factor) vc.swipe(x, start_y, x, end_y, steps) vc.sleep(2) vc.swipe(x, start_y, x, end_y, steps) vc.sleep(2) vc.swipe(x, start_y, x, end_y, steps)
def SetWifiConnect(vc, ap_name, ap_password): package = 'com.android.settings' activity = '.Settings' component_name = package + '/' + activity # ap_name = "dlink-549" # ap_password = "******" # Open the Settings app vc.device.startActivity(component=component_name) # Enable Wi-Fi vc.device.shell("svc wifi enable") vc.dump() findtext_and_touch(vc, u'Wi‑Fi') i = 0 br_ap = vc.findViewWithText(ap_name) while not br_ap and i < 30: br_ap = vc.findViewWithText(ap_name) ViewClient.sleep(1) vc.dump() i += 1 if i == 30: print "Cannot enable Wi-Fi" br_ap.touch() vc.device.type(ap_password) vc.dump() findtext_and_touch(vc, u'Connect') vc.sleep(1)
def openapp(self): self.device,self.serialno = ViewClient.connectToDeviceOrExit(serialno=None) FLAG_ACTIVITY_NEW_TASK = 0x10000000 componentName = 'com.qihoo.browser/.activity.SplashActivity' self.device.startActivity(component=componentName,flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(3) self.vc = ViewClient(self.device,self.serialno,forceviewserveruse=True)
def openapp(self): self.device,self.serialno = ViewClient.connectToDeviceOrExit(serialno=None) FLAG_ACTIVITY_NEW_TASK = 0x10000000 componentName = 'com.lehai.ui/com.showself.ui.LoadingActivity' self.device.startActivity(component=componentName,flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(3) self.vc = ViewClient(self.device,self.serialno,forceviewserveruse=True)
def init_view_client(): package = 'kr.kdev.dg1s.biowiki' #activity = '.ui.posts.PostsActivity' activity = '.ui.accounts.NewBlogActivity' device, serialno = ViewClient.connectToDeviceOrExit() component = package + '/' + activity device.startActivity(component=component, flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(2) return ViewClient(device, serialno), device
def init_view_client(): package = 'org.wordpress.android' #activity = '.ui.posts.PostsActivity' activity = '.ui.accounts.NewBlogActivity' device, serialno = ViewClient.connectToDeviceOrExit() component = package + '/' + activity device.startActivity(component=component, flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(2) return ViewClient(device, serialno), device
def reactiveMobile(self): if self.device == None : self.openapp() waitViewById('id/rgBottomNav',self.vc) self.device.touch(675,95,2) ViewClient.sleep(3) self.vc.findViewById('id/game_name').touch()
def openapp(self): self.device,self.serialno = ViewClient.connectToDeviceOrExit() FLAG_ACTIVITY_NEW_TASK = 0x10000000 componentName = 'com.example.myxposed/.ParamActivity' self.device.startActivity(component=componentName,flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(2) self.vc = ViewClient(self.device,self.serialno,forceviewserveruse=True)
def waitViewById(viewId,vc): #while True: for i in range(20): vc.dump() if vc.findViewById(viewId): print 'view with id %s is appeared----'%(viewId) break else: print 'view with id %s not appear wait 1 second for a while------'%(viewId) ViewClient.sleep(3)
def waitViewByTx(text,vc): #while True: for i in range(20): vc.dump() if vc.findViewWithText(text): print 'view with text %s is appeared----'%(text) break else: print 'view with text %s not appear wait 1 second for a while------'%(text) ViewClient.sleep(3)
def test_LaunchDemoAPI(self): device, serialno = ViewClient.connectToDeviceOrExit() print("Back to home") self.device.press('KEYCODE_BACK') self.device.press('KEYCODE_HOME') self.device.press('KEYCODE_HOME') self.device.press('KEYCODE_BACK') FLAG_ACTIVITY_NEW_TASK = 0x10000000 # 09-06 01:01:34.964: I/ActivityManager(873): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.android.apis/.ApiDemos bnds=[784,346][880,442]} from pid 991 componentName = 'com.example.android.apis/.ApiDemos' print("Open DemoAPI") device.startActivity(component=componentName, flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(5) vc = ViewClient(device=device, serialno=serialno) app = vc.findViewWithText('App') if app: app.touch() ViewClient.sleep(1) # windows changed, request a new dump print("Find Alert Dialogs") vc.dump() ad = vc.findViewWithText('Alert Dialogs') if ad: ad.touch() ViewClient.sleep(1) # windows changed, request a new dump print("find List dialog") vc.dump() ld = vc.findViewWithText('List dialog') if ld: ld.touch() ViewClient.sleep(1) # windows changed, request a new dump print("Find Command three") vc.dump() c3 = vc.findViewWithText('Command three') if c3: c3.touch() ViewClient.sleep(1) device.press('KEYCODE_BACK') else: print >> sys.stderr, "Cannot find 'Command three'" else: print >> sys.stderr, "Cannot find 'List dialog'" else: print >> sys.stderr, "Cannot find 'Alert Dialogs'" else: print >> sys.stderr, "Cannot find 'App'"
def doSomeClick(self,imei,imsi=None): if self.device == None : self.openapp() #self.device.dragDip((400,400),(10,400),800,5) #ViewClient.sleep(3) #self.device.dragDip((400,400),(10,400),800,5) #ViewClient.sleep(3) #waitViewByTx('立即修复',self.vc) #self.vc.findViewWithText('立即修复').touch() ViewClient.sleep(1) self.device.drag((600,400),(10,400),2000) ViewClient.sleep(1) self.device.drag((600,400),(10,400),2000) self.vc.dump() waitViewById('id/ensure',self.vc) #self.vc.findViewById('id/ensure').touch() self.device.touch(345,1070,2) ViewClient.sleep(2) waitViewById('id/first_nav',self.vc) self.vc.findViewById('id/first_nav').touch() ViewClient.sleep(5) f = open(self.accountfilename,'a') try: f.writelines(imei+"\t"+imsi+"\r\n") finally: f.flush() f.close()
def doSomeClick(self,imei,imsi=None): if self.device == None : self.openapp() waitViewById('id/rgBottomNav',self.vc) self.device.touch(675,95,2) ViewClient.sleep(3) self.vc.findViewById('id/game_name').touch() ViewClient.sleep(5) f = open(self.accountfilename,'a') try: f.writelines(imei+"\t"+imsi+"\r\n") finally: f.flush() f.close()
def exportOneChat(container, chat, midia=True): #com.whatsapp:id/conversations_row_contact_name #com.whatsapp:id/single_msg_tv vc.findViewById('com.whatsapp:id/conversations_row_contact_name', container).touch() #ViewClient.sleep(SLEEP_BASE) try: vc.dump(window=-1) except: vc.dump(window=-1) button = vc.findViewWithAttribute("class", "android.widget.ImageView") if not button is None: button.touch() #time.sleep(SLEEP_BASE) vc.dump(window=-1) button = vc.findViewWithText(TEXT_MORE); if not button is None: button.touch() time.sleep(SLEEP_BASE) vc.dump(window=-1) button = vc.findViewWithText(TEXT_EXPORT); if not button is None: button.touch() time.sleep(SLEEP_BASE) try: time.sleep(SLEEP_2) vc.dump(window=-1) except: vc.dump(window=-1) if vc.findViewWithContentDescription('android:id/contentPanel') is None: if midia: button = vc.findViewWithText(TEXT_MIDIAS); else: button = vc.findViewWithText(TEXT_NO_MIDIAS); if not button is None: button.touch(); ViewClient.sleep(SLEEP_BASE) try: vc.dump(window=-1) except: vc.dump(window=-1) # try to open export (some times it doesnt brings out using kbnJutsu) ret = callZAPiX(chat) return ret
def __call__(self): vc = ViewClient(self.__device, self.__serialno) info = self.__device.getDisplayInfo() end_x = int(info['width'] / 4) start_y = int(info['height'] / 2) if self.__serialno == "04a38409344082e7": vc.swipe(0, start_y, end_x, start_y, 100) elif self.__serialno == "010e3939219f5389": vc.swipe(0, start_y, end_x, start_y, 150) vc.swipe(0, start_y, end_x, start_y, 100) vc.sleep(2) vc.touch(int(end_x * 4 * .9), start_y)
def activeMobile(self,imei,imsi=None): if self.device == None : self.openapp() waitViewById('id/quick_guide_viewpager',self.vc) self.device.dragDip((500,300),(30,300),200,2) self.vc.dump() self.device.touch(615,378,2) waitViewById('id/home_bottom_tab5',self.vc) self.vc.findViewById('id/home_bottom_tab5').touch() self.vc.dump() waitViewById('id/btn_login_note_left',self.vc) #self.vc.findViewById('id/btn_login_note_left').touch() self.device.touch(160,1188,2) self.vc.dump() waitViewByTx('乐嗨号注册',self.vc) self.vc.findViewWithText('乐嗨号注册').touch() self.vc.dump() name = ''.join(map(lambda xx:(hex(ord(xx))[2:]),os.urandom(5))) self.vc.findViewById('id/et_lehai_reg_account').setText(name) self.vc.findViewById('id/et_reg_password').setText('abc1234') self.vc.findViewById('id/btn_lehai_reg').touch() self.vc.dump() waitViewById('id/btn_register_finish',self.vc) self.vc.findViewById('id/btn_register_finish').touch() self.vc.dump() waitViewById('id/imageView_classify_more_recommend',self.vc) self.vc.findViewById('id/imageView_classify_more_recommend').touch() ViewClient.sleep(5) f = open(self.accountfilename,'a') try: f.writelines(name+"\t"+imei+"\t"+imsi+"\r\n") finally: f.flush() f.close()
def SimSourceInOut(device,vc): global status device.startActivity(component=component_battery) ViewClient.sleep(3) vc.dump() no_id7 = vc.findViewByIdOrRaise("id/no_id/7") print('Simulation USB Plug-in...') temp_in = vc.findViewByIdOrRaise("android:id/title").getText().split('-') for x in temp_in: if x.find(charge_charging) != -1: print('Okay, charging...') status = 'true' elif x.find(charge_full_charging) != -1: print('Okay, Full so not charging...') status = 'true' if status != 'true': print('Fail, not charging...') return -1 print('Simulation USB Plug-out...') os.system(sus_vbus_cmd) ViewClient.sleep(3) vc.dump() temp_out = vc.findViewByIdOrRaise("android:id/title").getText().split('-') for x in temp_out: if x.find(charge_not_charging) != -1: print('Okay, Not charging...') status = 'true' if status != 'true': print('Fail, charging...') return -1 ViewClient.sleep(3) os.system(nonsus_vbus_cmd) print("END")
def SimSourceInOut(device, vc): global status device.startActivity(component=component_battery) ViewClient.sleep(3) vc.dump() no_id7 = vc.findViewByIdOrRaise("id/no_id/7") print('Simulation USB Plug-in...') temp_in = vc.findViewByIdOrRaise("android:id/title").getText().split('-') for x in temp_in: if x.find(charge_charging) != -1: print('Okay, charging...') status = 'true' elif x.find(charge_full_charging) != -1: print('Okay, Full so not charging...') status = 'true' if status != 'true': print('Fail, not charging...') return -1 print('Simulation USB Plug-out...') os.system(sus_vbus_cmd) ViewClient.sleep(3) vc.dump() temp_out = vc.findViewByIdOrRaise("android:id/title").getText().split('-') for x in temp_out: if x.find(charge_not_charging) != -1: print('Okay, Not charging...') status = 'true' if status != 'true': print('Fail, charging...') return -1 ViewClient.sleep(3) os.system(nonsus_vbus_cmd) print("END")
} device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1) kwargs2 = { 'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True } vc = ViewClient(device, serialno, **kwargs2) device.shell('input keyevent KEYCODE_HOME') device.startActivity(main_activity) vc.sleep(_s) ## STARTUP # pantalla principal vc.dump(window=-1) vc.findViewByIdOrRaise('com.olx.olx:id/fab_posting_masonry_home').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(
FLAG_ACTIVITY_NEW_TASK = 0x10000000 def init_view_client(): package = 'org.wordpress.android' #activity = '.ui.posts.PostsActivity' activity = '.ui.accounts.NewBlogActivity' device, serialno = ViewClient.connectToDeviceOrExit() component = package + '/' + activity device.startActivity(component=component, flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(2) return ViewClient(device, serialno), device vc, device = init_view_client() ViewClient.sleep(1) def createABlog(name): vc.dump(0.1) settingsButton = vc.findViewWithText('Create a WordPress.com blog') while settingsButton == None: device.press('KEYCODE_DPAD_DOWN') device.press('KEYCODE_DPAD_DOWN') device.press('KEYCODE_DPAD_DOWN') device.press('KEYCODE_DPAD_DOWN') vc.dump(0.1) settingsButton = vc.findViewWithText('Create a WordPress.com blog') settingsButton.touch() vc.dump(0.5) device.type(name)
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)
# connection to the current device, and return a MonkeyDevice object device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device=device, serialno=serialno) # apk_path = device.shell('pm path com.lionhouse.vetondemand') # if apk_path.startswith('package:'): # print "myapp already installed." # else: # print "myapp not installed, installing APKs..." # device.installPackage('base.apk') print "launching myapp..." case = "TourActivity" splashActivity() vc.sleep(3) makeScreen(case) print "go to Sign Up" clickViewById(SIGN_UP_BTN_ID) vc.sleep(3) makeDump() makeScreen("SignUpActivity") print "go to LogIn" makeDump() clickViewById(LOG_IN_BTN_ID) vc.sleep(3) makeScreen("LoginDialog")
class YkspTestCase(unittest.TestCase): package = None serial = None dirRoot = None logsFilename = None screenshotFolder = None screendumpFolder = None screenCount = 0 def setUp(self): # Connnect to device self.device, self.serialno = ViewClient.connectToDeviceOrExit(serialno=YkspTestCase.serial) # Wake device self.device.wake() # Create ViewClient instance self.vc = ViewClient(self.device, self.serialno, autodump=False) def tearDown(self): # Force-stop the app self.device.shell('am force-stop %s' % YkspTestCase.package) def launchApp(self, package=None): ''' Launches an app as if from the launcher. @type package: str @param package: An optional parameter to specify an application to launch by its package name. If not provided, the application package name provided in the application manifest is used. ''' if package is None: package = YkspTestCase.package # Launch application only if the package is installed if self.device.shell('pm path %s' % package): self.device.shell('monkey -p %s -c android.intent.category.LAUNCHER 1' % package) else: self.fail('Failed to launch application. %s is not installed on this device' % package) def refreshScreen(self, sleep=1): ''' Updates the view tree. This method or saveScreen() must be called after each screen transition to keep the view tree in sync with the device screen. @type sleep: float @param sleep: An optional parameter to indicate the time to sleep before refreshing the screen. Defaults to one second. ''' self.vc.dump(window=-1, sleep=sleep) def saveScreen(self, tag=None, sleep=1): ''' Updates the view tree and saves to disk the screenshot and screendump of the device screen. This method or refreshScreen() must be called after each screen transition to keep the view tree in sync with the device screen. @type tag: str @param tag: The tag for this screen. This is appended to the filename. @type sleep: float @param sleep: An optional parameter to indicate the time to sleep before saving the screen. Defaults to one second. ''' if sleep > 0: self.vc.sleep(sleep) filename = YkspTestCase.screenCount if tag: filename = '%s-%s' % (filename, tag) # Take a screenshot and save self.device.takeSnapshot(reconnect=True).save('%s/%s/%s.png' % (YkspTestCase.dirRoot, YkspTestCase.screenshotFolder, filename), 'PNG') # Take a screendump and save screendump = self.vc.dump(window=-1, sleep=0) screendumpStream = open('%s/%s/%s.txt' % (YkspTestCase.dirRoot, YkspTestCase.screendumpFolder, filename), 'w') self.vc.traverse(transform=self.vc.TRAVERSE_CITPS, stream=screendumpStream) screendumpStream.close() YkspTestCase.screenCount += 1 @staticmethod def parseArgs(argv): try: opts, args = getopt.getopt(argv[1:], 'hp:s:r:l:m:n:', ['help', 'package=', 'serial=', 'root=', 'logs=', 'screenshots=', 'screendumps=']) except getopt.GetoptError: YkspTestCase.usage(2) for opt, arg in opts: if opt in ('-h', '--help'): YkspTestCase.usage(2) elif opt in ('-p', '--package'): YkspTestCase.package = arg argv.remove(opt) argv.remove(arg) elif opt in ('-s', '--serial'): YkspTestCase.serial = arg argv.remove(opt) argv.remove(arg) elif opt in ('-r', '--root'): YkspTestCase.dirRoot = arg argv.remove(opt) argv.remove(arg) elif opt in ('-l', '--logs'): YkspTestCase.logsFilename = arg argv.remove(opt) argv.remove(arg) elif opt in ('-m', '--screenshots'): YkspTestCase.screenshotFolder = arg argv.remove(opt) argv.remove(arg) elif opt in ('-n', '--screendumps'): YkspTestCase.screendumpFolder = arg argv.remove(opt) argv.remove(arg) if YkspTestCase.package is None: print '\nError:' print '--package must be specified' YkspTestCase.usage(2) if YkspTestCase.serial is None: print '\nError:' print '--serial must be specified' YkspTestCase.usage(2) if YkspTestCase.dirRoot is None: print '\nError:' print '--root must be specified' YkspTestCase.usage(2) if YkspTestCase.screenshotFolder is None: print '\nError:' print '--screenshots must be specified' YkspTestCase.usage(2) if YkspTestCase.screendumpFolder is None: print '\nError:' print '--screendumps must be specified' YkspTestCase.usage(2) if os.path.isdir(YkspTestCase.dirRoot) is False: print '\nError:' print '--root specifies an invalid directory' YkspTestCase.usage(2) @staticmethod def usage(exitVal=0): print '\nUsage:' print '-h, --help OPTIONAL print this help and exit' print '-p, --package <package> REQUIRED specify the package name of the application' print '-s, --serial <serial> REQUIRED specify the serial number of the device to run this test case' print '-r, --root <dir> REQUIRED specify the root directory to save the results of this test case' print '-l, --logs <dir> OPTIONAL specify the filename to save the PyUnit logs' print '-m, --screenshots <folder> REQUIRED specify the folder name to save the screenshots' print '-n, --screendumps <folder> REQUIRED specify the folder name to save the screendumps' sys.exit(exitVal) @staticmethod def main(argv): YkspTestCase.parseArgs(argv) # Create subdirectories dirScreenshot = '%s/%s' % (YkspTestCase.dirRoot, YkspTestCase.screenshotFolder) if os.path.isdir(dirScreenshot) is False: os.mkdir(dirScreenshot) dirScreendump = '%s/%s' % (YkspTestCase.dirRoot, YkspTestCase.screendumpFolder) if os.path.isdir(dirScreendump) is False: os.mkdir(dirScreendump) # Configure logging and execute test case if YkspTestCase.logsFilename: logsStream = open('%s/%s' % (YkspTestCase.dirRoot, YkspTestCase.logsFilename), 'w') runner = unittest.TextTestRunner(stream=logsStream, verbosity=2) unittest.main(testRunner=runner) else: unittest.main()
@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()
logger = logging.getLogger('WhatsApp') # set a variable with the package's internal name package = 'com.whatsapp' # set a variable with the name of an Activity in the package activity = '.Main' # set the name of the component to start runComponent = package + '/' + activity # run the component device.startActivity(component=runComponent) logger.info('open application', extra=get_extra_data()) ViewClient.sleep(10) 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()
def __call__(self): vc = ViewClient(self.__device, self.__serialno) vc.sleep(self.__waiting_time)
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) vc.findViewWithContentDescriptionOrRaise(u'''Voice Search''').touch() ViewClient.sayText("The 'poke' button on facebook is awesome...\ But I think there should be a 'stab' button...") vc.sleep(_s) vc.dump(window=-1)
try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) 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()
# otherwise the import fails. from com.dtmilano.android.viewclient import ViewClient, View, UiDevice from cts_develop import ChangeDeveloper_settings from cts_setsecurity import setSecurity from cts_settimezone import setTimezone from cts_wifisetting import SetWifiConnect,ModifyNetwork from cts_skipwizzard import skip_setupwizzard from cts_setchrome import set_chrome os.system("adb devices") # Connect to device with the IP received as a parameter device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device=device, serialno=serialno) ud = UiDevice(vc=vc) vc.sleep(1) skip_setupwizzard(vc) # Press the HOME button to start the test from the home screen device.press('KEYCODE_HOME','DOWN_AND_UP') #Change language to English (United States) ud.changeLanguage('en-rUS') ChangeDeveloper_settings(vc) setSecurity(vc) setTimezone(vc) SetWifiConnect(vc) ModifyNetwork(vc) # Press the HOME button to start the test from the home screen device.press('KEYCODE_HOME','DOWN_AND_UP') set_chrome(vc) device.press('KEYCODE_HOME','DOWN_AND_UP')
# This must be imported before MonkeyRunner and MonkeyDevice, # otherwise the import fails. from com.dtmilano.android.viewclient import ViewClient, View, UiDevice from cts_develop import ChangeDeveloper_settings from cts_setsecurity import setSecurity from cts_settimezone import setTimezone from cts_wifisetting import SetWifiConnect, ModifyNetwork from cts_skipwizzard import skip_setupwizzard from cts_setchrome import set_chrome os.system("adb devices") # Connect to device with the IP received as a parameter device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device=device, serialno=serialno) ud = UiDevice(vc=vc) vc.sleep(1) print u'Start to Skip setup wizzard' skip_setupwizzard(vc) print u'Skip setup wizzard --- Done' # Press the HOME button to start the test from the home screen device.press('KEYCODE_HOME', 'DOWN_AND_UP') #Change language to English (United States) print u'Start to Change Language to English' ud.changeLanguage('en-rUS') print u'Change Language to English --- Done' print u'Start to Change the settings in Developer' ChangeDeveloper_settings(vc) print u'Change the settings in Developer --- Done' print u'Start to Change the settings in Security' setSecurity(vc)
def callZAPiX(chat): global exportedChats ViewClient.sleep(SLEEP_BASE) try: vc.dump(window=-1) except: ViewClient.sleep(SLEEP_3) vc.dump(window=-1) #Waiting for export panel app_log.debug('Waiting Content Panel') tryCount = 0 while vc.findViewById('android:id/contentPanel') is None or vc.findViewById('android:id/progress') is not None: time.sleep(SLEEP_BASE) tryCount = tryCount + 1 try: vc.dump(window=-1) except: app_log.error('Error.<WAIT> Trying to correct.') app_log.debug('Waiting Export Aplications Panel. Tries: '+ str(tryCount)) #vc.traverse() if tryCount > 10: app_log.debug('Problem accessing "Export Applications Panel"') app_log.debug('Back to main chat screen...') try: vc.dump(window=-1) except: ViewClient.sleep(SLEEP_3) vc.dump(window=-1) return False app_log.debug('Content Panel found.') ViewClient.sleep(SLEEP_BASE) #Looking for rar button app_log.debug('Searching ZAPiX...') vc.dump(window=-1) buttonZAPIX = vc.findViewWithText('SPI_ZAPiX') if buttonZAPIX is None: ViewClient.sleep(SLEEP_BASE) device.dragDip((185.0, 600.0), (191.0, 50.0), 1000, 20) time.sleep(SLEEP_BASE) vc.dump(window=-1) buttonZAPIX = vc.findViewWithText('SPI_ZAPiX') if buttonZAPIX is None: app_log.debug('ZAPiX not found') return False else: buttonZAPIX.touch() ViewClient.sleep(SLEEP_2) else: buttonZAPIX.touch() ViewClient.sleep(SLEEP_2) app_log.debug('SPI_ZAPiX found') result = exportCurrentZAPiXChat(chat[0]) device.press('KEYCODE_BACK') return result
# connection to the current device, and return a MonkeyDevice object device, serialno = ViewClient.connectToDeviceOrExit(verbose=True) vc = ViewClient(device=device, serialno=serialno) # apk_path = device.shell('pm path com.lionhouse.vetondemand') # if apk_path.startswith('package:'): # print "myapp already installed." # else: # print "myapp not installed, installing APKs..." # device.installPackage('base.apk') print "launching myapp..." case = "TourActivity" launchTourActivity() vc.sleep(10) makeScreen(case) # print "go to Sign Up" # clickViewById(SIGN_UP_BTN_ID) # vc.sleep(3) # makeDump() # makeScreen("SignUpActivity") # # # print "go to LogIn" # makeDump() # clickViewById(LOG_IN_BTN_ID) # vc.sleep(3) # makeScreen("LoginDialog")
# connection to the current device, and return a MonkeyDevice object device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device=device, serialno=serialno) # apk_path = device.shell('pm path com.lionhouse.vetondemand') # if apk_path.startswith('package:'): # print "myapp already installed." # else: # print "myapp not installed, installing APKs..." # device.installPackage('base.apk') print "launching myapp..." case = "TourActivity" splashActivity() vc.sleep(3) makeScreen(case) print "go to Sign Up" clickViewById(SIGN_UP_BTN_ID) vc.sleep(3) makeDump() makeScreen("SignUpActivity") print "go to LogIn" makeDump() clickViewById(LOG_IN_BTN_ID) vc.sleep(3) makeScreen("LoginDialog") print "go to LogIn with email"
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) except Exception as e:
USE_BROWSER = True 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' 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)
viewclient_home = os.environ['ANDROID_VIEW_CLIENT_DIR'] sys.path.append(os.path.join(viewclient_home, 'src')) except: raise from com.dtmilano.android.viewclient import ViewClient, View package = 'com.hecorat.screenrecorder.free' activity = '.activities.MainActivity' component = package + '/' + activity device, serialno = ViewClient.connectToDeviceOrExit( serialno='0094d3075388ceb1') FLAG_ACTIVITY_NEW_TASK = 0x10000000 device.startActivity(component=component, flags=FLAG_ACTIVITY_NEW_TASK) vc = ViewClient(device=device, serialno=serialno, startviewserver=True) device.drag((100, 0), (100, 1500), 1000) vc.dump() view = vc.findViewById('com.hecorat.screenrecorder.free:id/btn_record') view.touch() ViewClient.sleep(2) os.system( 'adb shell am start -a android.intent.action.VIEW \"http://www.youtube.com/watch?v=YRhFSWz_J3I\"' ) sleep(2) subprocess.call('adb shell am force-stop com.hecorat.screenrecorder.free', shell=True) os.system( 'adb shell am force-stop android.intent.action.VIEW \"http://www.youtube.com/watch?v=YRhFSWz_J3I\"' )
logging.config.fileConfig('logging.conf') logger = logging.getLogger('WhatsApp') # set a variable with the package's internal name package = 'com.whatsapp' # set a variable with the name of an Activity in the package activity = '.Main' # set the name of the component to start runComponent = package + '/' + activity # run the component device.startActivity(component=runComponent) logger.info('open application', extra=get_extra_data()) # wait ViewClient.sleep(5) # close the app device.shell('am force-stop com.whatsapp') logger.info('stop the application', extra=get_extra_data()) # remove the app from the recent task list device.shell('input keyevent KEYCODE_APP_SWITCH') device.shell('input keyevent DEL') logger.info('remove an app from the recent list', extra=get_extra_data()) device.shell('input keyevent KEYCODE_HOME') logger.info('return HOME', extra=get_extra_data())
import sys import os import string try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass 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' package = 'com.android.browser' activity = '.BrowserActivity' else: package = 'com.android.chrome' activity = 'com.google.android.apps.chrome.Main' component = package + "/" + activity #uri = 'https://res.imtt.qq.com/schoolcode/html/index.html?ADTAG=hbxy2' uri = 'https://res.imtt.qq.com/schoolcode/html/index.html?ADTAG=hbkp' device, serialno = ViewClient.connectToDeviceOrExit(serialno=sys.argv.pop(1)) device.startActivity(component=component, uri=uri) ViewClient.sleep(6) device.touch(300,800) ViewClient.sleep(4)
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' 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')
try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from com.dtmilano.android.viewclient import ViewClient, View device, serialno = ViewClient.connectToDeviceOrExit() FLAG_ACTIVITY_NEW_TASK = 0x10000000 #09-06 01:01:34.964: I/ActivityManager(873): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.android.apis/.ApiDemos bnds=[784,346][880,442]} from pid 991 componentName = 'com.example.android.apis/.ApiDemos' device.startActivity(component=componentName, flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(10) vc = ViewClient(device=device, serialno=serialno) app = vc.findViewWithText('App') if app: app.touch() ViewClient.sleep(1) # windows changed, request a new dump vc.dump() ad = vc.findViewWithText('Alert Dialogs') if ad: ad.touch() ViewClient.sleep(1) # windows changed, request a new dump vc.dump() ld = vc.findViewWithText('List dialog') if ld:
try: sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) except: pass from com.dtmilano.android.viewclient import ViewClient, View device, serialno = ViewClient.connectToDeviceOrExit() FLAG_ACTIVITY_NEW_TASK = 0x10000000 # We are not using Settings as the bug describes because there's no WiFi dialog in emulator #componentName = 'com.android.settings/.Settings' componentName = 'com.dtmilano.android.sampleui/.MainActivity' device.startActivity(component=componentName, flags=FLAG_ACTIVITY_NEW_TASK) ViewClient.sleep(3) # Set it to True or False to decide if AndroidViewClient or plain monkeyrunner is used USE_AVC = True if USE_AVC: # AndroidViewClient vc = ViewClient(device=device, serialno=serialno) showDialogButton = vc.findViewById('id/show_dialog_button') if showDialogButton: showDialogButton.touch() vc.dump() vc.findViewById('id/0x123456').type('Donald') ok = vc.findViewWithText('OK') if ok: # 09-08 20:17:47.860: D/MonkeyStub(2033): translateCommand: tap 265 518
def loadScreenshots(): # Read all chats in list device, serialno = ViewClient.connectToDeviceOrExit() device.press('KEYCODE_HOME') device.startActivity(component=component) ViewClient.sleep(TOUCH_LONG_SLEEP) vc = ViewClient(device, serialno, autodump=True) putMainScreen(vc) toStart(vc) ##coments if necessary continue a extraction vc.dump() new_chats = True while new_chats: #check screen changes (in chat list) after dragging # track the chat list beginning. brute_chatList = vc.findViewsWithAttribute('class', 'android.view.ViewGroup') if brute_chatList[0] is None: logging.error('Cant go back to Facebook Home') quit() # capture new chats in screen list chatList = [] new_chats = False for c in brute_chatList[0].children: if len(c.getText()) > 0 and c.getText( ) != 'Online' and not c.getContentDescription() in visitedChats: print c.getContentDescription().encode('utf-8') chatList.append(c) new_chats = True print "new Chats:(", len(chatList), ")", 'total ', len(visitedChats) # process new chats for chat in chatList: print '->' + chat.getContentDescription().encode( 'utf-8'), chat.getTag(), chat.getUniqueId() path = '' if isinstance(chat.getContentDescription(), unicode): path = unicode( extraction_path + '/' + norm_unicode_filename(chat.getContentDescription())) if isinstance(chat.getContentDescription(), str): path = extraction_path + '/' + werkzeug.utils.secure_filename( chat.getContentDescription().encode('utf-8')) os.mkdir(path, 0777) device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) chat.touch() #print 'touching...' if vc.isKeyboardShown(): device.press('KEYCODE_BACK') root = vc.findViewsWithAttribute('class', 'android.view.ViewGroup') #print "Grupo:", len(root), root[0].getContentDescription(), root[0].getText() vc = ViewClient(device, serialno) # snapshot screen screenshot_count = 1 before_dump = '' strScreen = StringIO.StringIO() vc.traverse(transform=ViewClient.TRAVERSE_CITPS, stream=strScreen) after_dump = strScreen.getvalue() while before_dump != after_dump: #check screen changes (in msgs list) after dragging before_dump = after_dump print 'screenshot', screenshot_count device.takeSnapshot().save( path + '/screenshot_' + str(screenshot_count) + ".png", 'PNG') device, serialno = ViewClient.connectToDeviceOrExit() vc = ViewClient(device, serialno) #print 'connected?',device.checkConnected() device.dragDip((169.0, 297.0), (173.0, 600.0), 1000, 20, 0) attemptCount = 0 while attemptCount < 5: try: attemptCount = attemptCount + 1 vc = ViewClient(device, serialno) break except: print 'Houston...we have a problem (BEEP) - small drag tilt' device.dragDip((169.0, 297.0), (173.0, 310.0), 1000, 20, 0) if attemptCount == 5: print 'ERROR' exit(1) strScreen = StringIO.StringIO() vc.traverse(transform=ViewClient.TRAVERSE_CITPS, stream=strScreen) after_dump = strScreen.getvalue() screenshot_count = screenshot_count + 1 visitedChats.append(chat.getContentDescription()) putMainScreen(vc) #device.press('KEYCODE_BACK'); # drag chat list device.dragDip((173.0, 560.0), (169.0, 150.0), 1000, 20, 0) vc = ViewClient(device, serialno) #Am i in FBM home? print 'put main screen' putMainScreen(vc) print 'Total chats:', len(visitedChats)
# 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() print "sending....." # wait ViewClient.sleep(3) # close the app device.shell('am force-stop com.viber.voip')
from ocrCall import * from com.dtmilano.android.viewclient import ViewClient from keras.models import Sequential from keras.layers import MaxPooling2D, Conv2D, Dense, Flatten from keras.optimizers import SGD import math #---------------------connecting the phone---------------------# device, serialno = ViewClient.connectToDeviceOrExit(verbose=1) cmdl = 'input touchscreen swipe 260 700 260 700 400;' cmdr = 'input touchscreen swipe 500 700 500 700 400;' package = 'com.minigame.carracing' activity = 'com.unity3d.player.UnityPlayerNativeActivity' runComponent = package + '/' + activity device.startActivity(component=runComponent) ViewClient.sleep(3.0) device.touch(365, 780, 'DOWN_AND_UP') ViewClient.sleep(10.0) #-----------------------Environment------------------------# class Environment: max = 0 iter = 0 count = 0 def touch(self, action): if action == 1: device.shell(cmdl) elif action == 2: device.shell(cmdr)
def vcsleep(sec): print 'ViwewClient.sleep(%s)' % sec ViewClient.sleep(sec)
title = config.get(section, "title") price = config.get(section, "price") mts2 = config.get(section, "mts2") antq = unicode( config.get(section, "antq"), 'utf-8') #convert to unicode due to Ñ 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