def click_and_screenshot_by_name(device_id, el_name, filename, img_device_path, target_path): el = myuiautomator.find_element_by_name(device_id, el_name) if el is not None: myuiautomator.click_element_by_name(device_id, el_name) format_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S") fname = filename + format_time screencap_cmd = 'adb shell screencap -p /sdcard/%s.png' % fname myuiautomator.shellPIPE(screencap_cmd) time.sleep(2) mylogger.debug('doing screenShot save as /sdcard/%s.png' % fname) source_path = img_device_path + fname + '.png' cmd = "adb pull %s %s" % (source_path, target_path) l = myuiautomator.shellPIPE(cmd) time.sleep(5) mylogger.debug('pull screenshot img from sdcard %s into %s' % (source_path, target_path)) if 'error' in l: print 'pull failed.' mylogger.debug('>>>>>>>>>>>>>>>>>>>>>>>>>pull screenshot failed.') else: print 'pull img success.' mylogger.debug('>>>>>>>>>>>>>>>>>>>>>pull img success.') rm_cmd = "adb shell rm -rf %s" % (source_path) myuiautomator.shellPIPE(rm_cmd) mylogger.debug('delete screenshot img from sdcard %s' % source_path) time.sleep(2) return el
def test_vpn(self): cfg = configuration.Configuration() cfg_file = "../config/common.ini" cfg.fileConfig(cfg_file) device_id = cfg.getValue('COMMON', 'device_id') vpn_btn = cfg.getValue('COMMON', 'vpn_btn') img_device_path = cfg.getValue('COMMON', 'img_device_path') target_path = cfg.getValue('COMMON', 'img_path') connect_server_btn = cfg.getValue('VPN', 'connect_server_btn') choose_server_btn = cfg.getValue('VPN', 'choose_vpnline') choose_workmode_btn = cfg.getValue('VPN', 'choose_workmode') #点击 连接标签 后截图 el = common.click_and_screenshot_by_id(device_id, vpn_btn, '01_VPNTestCase', img_device_path, target_path) self.assertIsNotNone(el, 'connect vpn button not found.') #选择流量源后,选择某一条线路 common.click_and_screenshot_by_id(device_id, choose_server_btn, '02_VPNTestCase', img_device_path, target_path) time.sleep(1) server_el = myuiautomator.find_element_by_name(device_id, u"香港") self.assertIsNotNone(server_el, 'choose server failure') common.click_and_screenshot_by_name(device_id, u"我不是路飞", '03_VPNTestCase', img_device_path, target_path) time.sleep(2) #common.click_and_screenshot_by_name(device_id, u"返回", '04_VPNTestCase', img_device_path, target_path) #time.sleep(2) key_cmd = 'adb shell input keyevent 4' myuiautomator.shellPIPE(key_cmd) time.sleep(2) vpn_el = myuiautomator.find_element_by_name(device_id, u"香港") self.assertIsNotNone(vpn_el, 'choose vpn server line failure') #点击 选择工作模式 后截图 common.click_and_screenshot_by_id(device_id, choose_workmode_btn, '05_VPNTestCase', img_device_path, target_path) workmode_el = myuiautomator.find_element_by_name(device_id, u"全局代理") self.assertIsNotNone(workmode_el, 'click choose_workmode failure') common.click_and_screenshot_by_name(device_id, u"全局代理", '06_VPNTestCase', img_device_path, target_path) time.sleep(2) common.click_and_screenshot_by_name(device_id, u"返回", '07_VPNTestCase', img_device_path, target_path) time.sleep(2) workmode_el2 = myuiautomator.find_element_by_name(device_id, u"全局代理") self.assertIsNotNone(workmode_el2, 'choose work mode failure') # 点击 连接服务器按钮 后截图 common.click_and_screenshot_by_id(device_id, connect_server_btn, '08_VPNTestCase', img_device_path, target_path) pop_el = myuiautomator.find_element_by_name(device_id, u"确定") if pop_el is not None: common.click_and_screenshot_by_name(device_id, u"确定", '09_VPNTestCase', img_device_path, target_path) time.sleep(5) el3 = myuiautomator.find_element_by_name(device_id, '00:00:00') self.assertIsNone(el3, 'start connect server failure') common.click_and_screenshot_by_id(device_id, connect_server_btn, '10_VPNTestCase', img_device_path, target_path) time.sleep(5) el4 = myuiautomator.find_element_by_name(device_id, '00:00:00') self.assertIsNotNone(el4, 'stop server failure') else: print 'can not find button...'
def start_app(package, activity, device_id, vpn_rid, login_rid, img_device_path, target_path): """ 通过包名和activity启动app,启动后判断是否首次进入,如果首次进入,则点击back键隐藏软键盘,并点击 进入 按钮 参数:包名,启动activity,设备id,首页中 连接 元素resource-id,登录页面 进入 元素resource-id,sdcard上截图存放路径, PC端截图存放路径 :return: """ start_cmd = "adb shell am start -n %s/%s" % (package, activity) myuiautomator.shellPIPE(start_cmd) time.sleep(10) mylogger.debug('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>start app screenshot.') print('start app screenshot......') format_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S") fname = 'startapp' + format_time print('>>>>>>>>>>>>>>>>fname:' + fname) screencap_cmd = 'adb shell screencap -p /sdcard/%s.png' % fname print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>screencap_cmd:' + screencap_cmd) myuiautomator.shellPIPE(screencap_cmd) time.sleep(2) mylogger.debug('doing screenShot save as /sdcard/%s.png' % fname) el = myuiautomator.find_element_by_id(device_id, vpn_rid) if el is None: mylogger.debug( '>>>>>>>>>>>>>>>>>>>>>>>>>>need to press back key to hide the soft keyboard.' ) print("need to press back key......") key_cmd = 'adb shell input keyevent 4' myuiautomator.shellPIPE(key_cmd) time.sleep(1) print("click into key......") mylogger.debug( ">>>>>>>>>>>>>>>>>>>>>>>>>>click login btn into index page.") myuiautomator.click_element_by_id(device_id, login_rid) time.sleep(10) else: print("this is index page......") source_path = img_device_path + fname + '.png' cmd = "adb pull %s %s" % (source_path, target_path) l = myuiautomator.shellPIPE(cmd) time.sleep(5) mylogger.debug('pull screenshot img from sdcard %s into %s' % (source_path, target_path)) if 'error' in l: print 'pull failed.' mylogger.debug('>>>>>>>>>>>>>>>>>>>>>>>>>pull screenshot failed.') else: print 'pull img success.' mylogger.debug('>>>>>>>>>>>>>>>>>>>>>pull img success.') rm_cmd = "adb shell rm -rf %s" % (source_path) myuiautomator.shellPIPE(rm_cmd) mylogger.debug('delete screenshot img from sdcard %s' % source_path) time.sleep(2)
def setUp(self): cfg = configuration.Configuration() cfg_file = "../config/common.ini" cfg.fileConfig(cfg_file) device_id = cfg.getValue('COMMON', 'device_id') app_package = cfg.getValue('COMMON', 'app_package') app_activity = cfg.getValue('COMMON', 'start_activity') login_btn = cfg.getValue('LOGIN', 'login_btn') img_path = cfg.getValue('COMMON', 'img_path') vpn_btn = cfg.getValue('INDEX', 'vpn_btn') img_device_path = cfg.getValue('COMMON', 'img_device_path') mylogger = logger.Log("debug") device = adbtools.AdbTools(device_id) l = device.get_device_state() self.assertNotIn('error', l, 'device connect error.') mylogger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>start install app") common.install_app(device_id) l = myuiautomator.shellPIPE('adb shell pm list packages %s' % app_package) self.assertIn(app_package, l, 'install failure') mylogger.debug(">>>>>>>>>>>>>>>>>>>>>>>>start open app") common.start_app(app_package, app_activity, device_id, vpn_btn, login_btn, img_device_path, img_path) mylogger.debug(">>>>>>>>>>>>>>>>>>>>>screenShot after login") common.click_i_know(device_id, img_path) el = myuiautomator.find_element_by_id(device_id, vpn_btn) self.assertIsNotNone(el, 'can not find vpn btn,this is not index page.')
def tearDown(self): cfg = configuration.Configuration() cfg_file = "../config/common.ini" cfg.fileConfig(cfg_file) device_id = cfg.getValue('COMMON', 'device_id') app_package = cfg.getValue('COMMON', 'app_package') #print 'uninstall app...' l = myuiautomator.shellPIPE('adb -s %s uninstall %s' % (device_id, app_package)) self.assertIn('Success', l, 'uninstall failure')
def testMine(self): cfg = configuration.Configuration() cfg_file = "../config/common.ini" cfg.fileConfig(cfg_file) device_id = cfg.getValue('COMMON', 'device_id') mine_id = cfg.getValue('INDEX', 'mine_btn') img_device_path = cfg.getValue('COMMON', 'img_device_path') target_path = cfg.getValue('COMMON', 'img_path') mykey_id = cfg.getValue('MINE', 'see_my_key') copykey_id = cfg.getValue('MINE', 'copy_my_key') myblock_id = cfg.getValue('MINE', 'see_my_block') close_block_id = cfg.getValue('MINE', 'close_my_block') myaccount_id = cfg.getValue('MINE', 'see_my_account') myflow_share_id = cfg.getValue('MINE', 'see_my_flow_share') myflow_share_confirm_id = cfg.getValue('MINE', 'myflow_share_confirm') mysetting_id = cfg.getValue('MINE', 'see_my_setting') # 点击我的图标 el = common.click_and_screenshot_by_id(device_id, mine_id, '01_MineTestCase', img_device_path, target_path) self.assertIsNotNone(el, 'mine button not found.') time.sleep(2) mykey_el = myuiautomator.find_element_by_name(device_id, u"查看我的私钥") self.assertIsNotNone(mykey_el, 'into mine page failure.') # 点击 查看我的私钥 common.click_and_screenshot_by_id(device_id, mykey_id, '02_MineTestCase', img_device_path, target_path) copykey_el = myuiautomator.find_element_by_name(device_id, u"备份私钥") self.assertIsNotNone(copykey_el, 'see mine key failure.') common.click_and_screenshot_by_id(device_id, copykey_id, '03_MineTestCase', img_device_path, target_path) time.sleep(2) # 点击 区块高度 el1 = common.click_and_screenshot_by_id(device_id, myblock_id, '04_MineTestCase', img_device_path, target_path) self.assertIsNotNone(el1, 'block img not find.') block_el = myuiautomator.find_element_by_name(device_id, u"区块详情") self.assertIsNotNone(block_el, 'see my block failure.') common.click_and_screenshot_by_id(device_id, close_block_id, '05_MineTestCase', img_device_path, target_path) time.sleep(2) # 点击 我的账单 el2 = common.click_and_screenshot_by_id(device_id, myaccount_id, '06_MineTestCase', img_device_path, target_path) self.assertIsNotNone(el2, 'my account img not find.') myaccount_el = myuiautomator.find_element_by_name(device_id, u"待结算账单") self.assertIsNotNone(myaccount_el, 'see my account failure.') # 点击 待结算账单 common.click_and_screenshot_by_name(device_id, u"待结算账单", '07_MineTestCase', img_device_path, target_path) time.sleep(2) key_cmd = 'adb shell input keyevent 4' myuiautomator.shellPIPE(key_cmd) time.sleep(1) key_cmd = 'adb shell input keyevent 4' myuiautomator.shellPIPE(key_cmd) time.sleep(1) # 点击 转账 el3 = common.click_and_screenshot_by_id(device_id, myflow_share_id, '08_MineTestCase', img_device_path, target_path) self.assertIsNotNone(el3, 'my flow share img not find.') common.click_and_screenshot_by_id(device_id, myflow_share_confirm_id, '09_MineTestCase', img_device_path, target_path) time.sleep(2) key_cmd = 'adb shell input keyevent 4' myuiautomator.shellPIPE(key_cmd) time.sleep(1) # 点击 设置 el4 = common.click_and_screenshot_by_id(device_id, mysetting_id, '10_MineTestCase', img_device_path, target_path) self.assertIsNotNone(el4, 'setting button not find.') setting_el = myuiautomator.find_element_by_name(device_id, u"挖币设置") self.assertIsNotNone(setting_el, 'into setting page error.') key_cmd = 'adb shell input keyevent 4' myuiautomator.shellPIPE(key_cmd) time.sleep(1)
fname = 'install' + format_time proc_process = threading.Thread(target=myuiautomator.do_popup_windows, args=(10, find_text, device_id, fname)) threads.append(install_app_process) threads.append(proc_process) for t in threads: t.setDaemon(True) t.start() time.sleep(2) t.join() except Exception, ex: print ex source_path = img_device_path + fname + '.png' cmd = "adb pull %s %s" % (source_path, img_path) l = myuiautomator.shellPIPE(cmd) time.sleep(5) mylogger.debug('pull screenshot img from sdcard %s into %s' % (source_path, img_path)) if 'error' in l: print 'pull failed.' mylogger.debug('pull screenshot failed.') else: print 'pull img success.' rm_cmd = "adb shell rm -rf %s" % (source_path) myuiautomator.shellPIPE(rm_cmd) time.sleep(2) mylogger.debug('delete screenshot img from sdcard %s' % source_path) def start_app(package, activity, device_id, vpn_rid, login_rid,
def test_dig(self): cfg = configuration.Configuration() cfg_file = "../config/common.ini" cfg.fileConfig(cfg_file) device_id = cfg.getValue('COMMON', 'device_id') dig_id = cfg.getValue('INDEX', 'dug_btn') img_device_path = cfg.getValue('COMMON', 'img_device_path') target_path = cfg.getValue('COMMON', 'img_path') invite_friends_id = cfg.getValue('DIG', 'invite_friends_btn') evaluation_id = cfg.getValue('DIG', 'evaluation_btn') start_invite_id = cfg.getValue('DIG', 'start_invite_btn') cancel_invite_id = cfg.getValue('DIG', 'invite_cancel_btn') share_invite_id = cfg.getValue('DIG', 'share_invite_img') back_id = cfg.getValue('DIG', 'back_btn') start_dig_id = cfg.getValue('DIG', 'start_dig_btn') # 点击挖币图标 el = common.click_and_screenshot_by_id(device_id, dig_id, '01_DigTestCase', img_device_path, target_path) self.assertIsNotNone(el, 'dig button not found.') time.sleep(2) # 点击邀请好友图标 el1 = common.click_and_screenshot_by_id(device_id, invite_friends_id, '02_DigTestCase', img_device_path, target_path) self.assertIsNotNone(el1, 'invite friends button not found.') invite_el = myuiautomator.find_element_by_name(device_id, u"我的邀请码") self.assertIsNotNone(invite_el, 'invite friends failure.') # 点击立即邀请 common.click_and_screenshot_by_id(device_id, start_invite_id, '03_DigTestCase', img_device_path, target_path) invite_el1 = myuiautomator.find_element_by_name(device_id, u"信息") self.assertIsNotNone(invite_el1, 'invite friends failure.') # 关闭邀请页面 common.click_and_screenshot_by_id(device_id, cancel_invite_id, '04_DigTestCase', img_device_path, target_path) cancel_invite_el = myuiautomator.find_element_by_id( device_id, cancel_invite_id) self.assertIsNone(cancel_invite_el, 'cancel invite failure.') # 点击分享邀请页面 el2 = common.click_and_screenshot_by_id(device_id, share_invite_id, '05_DigTestCase', img_device_path, target_path) self.assertIsNotNone(el2, 'share invite not find.') time.sleep(2) invite_el2 = myuiautomator.find_element_by_name(device_id, u"信息") self.assertIsNotNone(invite_el2, 'share invite failure.') # 关闭邀请页面 common.click_and_screenshot_by_id(device_id, cancel_invite_id, '06_DigTestCase', img_device_path, target_path) cancel_invite_el1 = myuiautomator.find_element_by_id( device_id, cancel_invite_id) self.assertIsNone(cancel_invite_el1, 'cancel invite failure.') time.sleep(1) # 返回 #el3 = common.click_and_screenshot_by_id(device_id, back_id, 'backdig', img_device_path, target_path) #self.assertIsNotNone(el3, 'back button not find.') key_cmd = 'adb shell input keyevent 4' myuiautomator.shellPIPE(key_cmd) time.sleep(2) back_el = myuiautomator.find_element_by_name(device_id, u"挖币") self.assertIsNotNone(back_el, 'back dig page failure.') # 点击能力评估 el3 = common.click_and_screenshot_by_id(device_id, evaluation_id, '07_DigTestCase', img_device_path, target_path) self.assertIsNotNone(el3, 'evaluation button not find.') evaluation_el = myuiautomator.find_element_by_name( device_id, u"挖币评分解读") self.assertIsNotNone(evaluation_el, 'show evaluation info failure.') # 点击签到 el4 = common.click_and_screenshot_by_name(device_id, u"签到", '08_DigTestCase', img_device_path, target_path) if el4 is not None: time.sleep(1) signin_el = myuiautomator.find_element_by_name(device_id, u"已签") self.assertIsNotNone(signin_el, 'sign in failure.') else: signin_el = myuiautomator.find_element_by_name(device_id, u"已签") self.assertIsNotNone(signin_el, 'sign in failure.') # 返回 key_cmd = 'adb shell input keyevent 4' myuiautomator.shellPIPE(key_cmd) time.sleep(2) back_el2 = myuiautomator.find_element_by_name(device_id, u"挖币") self.assertIsNotNone(back_el2, 'back dig page failure.') time.sleep(2) # 点击开始按钮 common.click_and_screenshot_by_id(device_id, start_dig_id, '10_DigTestCase', img_device_path, target_path) time.sleep(2) key_cmd = 'adb shell input keyevent 3' myuiautomator.shellPIPE(key_cmd) time.sleep(1)