def setUpClass(self): self.device = adbtools.AdbTools(DEVICE_NAME) common.unlock_screen(DEVICE_NAME) width, height = self.device.get_screen_normal_size() self.width = int(width) self.height = int(height)
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 install_app(device_id): """ 安装app,如果已安装,则不再进行安装,否则安装app,并同时开启一个线程来实现对安装页面进行截图,并点击 安装 按钮 参数:设备id :return: """ device = adbtools.AdbTools(device_id) cfg_file = "../config/common.ini" app_path = get_ini_value(cfg_file, 'COMMON', 'app_path') app_package = get_ini_value(cfg_file, 'COMMON', 'app_package') img_path = get_ini_value(cfg_file, 'COMMON', 'img_path') img_device_path = get_ini_value(cfg_file, 'COMMON', 'img_device_path') find_text = [u"好", u"安装", u"允许"] #copy apk into sdcard try: threads = [] install_app_process = threading.Thread(target=device.install, args=(app_path, app_package)) format_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S") 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
def setUp(self): cfg = configuration.Configuration() cfg_file = "../config/common.ini" cfg.fileConfig(cfg_file) device_id = cfg.getValue('COMMON', 'device_id') device = adbtools.AdbTools(device_id) l = device.get_device_state() self.assertNotIn('error', l, 'device connect error.')
def click_i_know(device_id, img_path): device = adbtools.AdbTools(device_id) mylogger.debug(">>>>>>>>>>>>>>>>>>>>>screenShot after login") img_name = device.screenshot('index', img_path) target_path = img_path + "\\" + img_name + ".png" findstr = u"我知道了" left_pos, top_pos = get_position_font(target_path, findstr) if left_pos != 0 and top_pos != 0: print('click the button of i know') mylogger.debug(">>>>>>>>>>>>>>>>>>>>>clicking the button of i know") device.click_by_position(left_pos, top_pos) time.sleep(2) print('the button of i know has clicked') mylogger.debug( ">>>>>>>>>>>>>>>>>>>>the button of i know has clicked......") else: print('the button of i know did not find') mylogger.debug( ">>>>>>>>>>>>>>>>>>>the button of i know didn't finded,this is index page......" )
# run custom ui scripts else: if isinstance(app_name, unicode): app_name = app_name.encode('gbk') full_path = os.path.join(test_file_dir, "test_" + app_name + ".py") if os.path.isfile(full_path): pytest.main('-q ' + full_path) else: print 'test file {0} is not found!!!!!'.format( full_path) else: print 'theme name {0} is not found!!!!!!!!'.format( theme.encode('gbk')) device = adbtools.AdbTools(uid) device.send_keyevent(adbtools.KeyCode.KEYCODE_BACK) time.sleep(2) device.send_keyevent(adbtools.KeyCode.KEYCODE_HOME) time.sleep(2) time.sleep(2) # zip image files after finishing test. common.zip_files(rid) querydb.update_run_status(rid, "Success") except Exception, ex: querydb.update_run_status(rid, "Failed") # close appium if style == "random": common.kill_child_processes(appium.pid)