def monkey_work(device_id, app_name=Res.app_name): browser = app_name device = device_id conf = Fun.get_conf_parser(Res.monkey_conf_file) Fun.assert_options_presents(conf, ['mail', 'ftp', 'apk', 'monkey_params']) sender = conf.get('mail', 'sender') mail_pwd = conf.get('mail', 'pwd') subject = conf.get('mail', 'subject') receivers = conf.get('mail', 'receivers').split(',') anr_receivers = conf.get('mail', 'anr_receivers').split(',') pkg_name = conf.get('apk', 'package_name') subject = conf.get('apk', 'name') + subject keyword = conf.get('apk', 'keyword') events = conf.get('monkey_params', 'events') throttle = conf.get('monkey_params', 'throttle') apk_path = Fun.get_abspath(Res.apk_path) android_version = Fun.get_android_version(device_id) device_info = Fun.parse_device_info(device_id) logfile = Fun.get_abspath( Fun.path_join(Res.log_path, device_info + Res.log_suffix)) package_installed_once = False Mon.push_lib_to_phone(device) while True: if not package_installed_once: try: # todo Mon.prepare_log_file_path_file(logfile) Mon.refresh_with_apk(device, apk_path, pkg_name, logfile, package_installed_once) package_installed_once = True # todo Mon.skip(device) start_monkey_and_analyze(android_version, anr_receivers, browser, device, device_info, events, keyword, logfile, mail_pwd, pkg_name, receivers, sender, subject, throttle) except Exception as e: Fun.log(e) else: # todo Fun.kill_monkey(device) # todo FunLch.start_launcher_omit_splash(device, False, False) Fun.sleep(2) start_monkey_and_analyze(android_version, anr_receivers, browser, device, device_info, events, keyword, logfile, mail_pwd, pkg_name, receivers, sender, subject, throttle)
def create_or_erase(f): f = FunCom.get_abspath(FunCom.path_join(Res.project_path, f)) FunCom.log('to parse file: ' + f) if not FunCom.exists(f): FunCom.log('not exist, creating') FunCom.create_file(f) else: FunCom.log('exist, erasing') FunCom.erase_file_content(f)
def exception_handle(device_id, logcat_to_file=False): # if logcat_to_file: FunCom.log_cat_to_file(device_id) device_info = FunCom.parse_device_info(device_id) dir_to_store_logfile = FunCom.get_abspath( FunCom.path_join( Res.log_path, device_info + Res.underline + Res.logcat_tag + FunCom.current_time())) FunCom.make_dir_if_not_exist(dir_to_store_logfile) FunCom.log('Exception handle id:' + device_id + " dir to store log::" + dir_to_store_logfile) FunCom.p_open(Res.asb_shell_pull_log_file(device_id, dir_to_store_logfile))
def install_app_start_activity(tag, pkg, act, app_file, replace_apk=False, delay=6): if replace_apk or not FunCom.tell_app_installed(tag, pkg): apk_path = '' for f in FunCom.list_dir(FunCom.Res.util_path): if app_file in f: apk_path = FunCom.get_abspath(FunCom.path_join(FunCom.Res.util_path, f)) if apk_path == '': FunCom.raise_error( app_file + ' Apk file not found under ./util directory') # windows do not support grep command, cannot tell existence install_r(tag, apk_path, False) FunCom.sleep(delay) FunCom.p_open(FunCom.Res.asb_shell_start_activity(tag, act))
def click_test(): tags = FunCom.devices_list_with_connection_check() tag = tags[0] apk_files = FunPkg.get_apk_file_in_project() if len(apk_files) > 0: for f in apk_files: if str(f).endswith(Res.pgk_suffix): FunPkg.uninstall(tag, Res.pkg_name) FunPkg.install_r(tag, FunCom.get_abspath(f), True) break else: raise Exception( "no apk found in project '/apk' directory, put one at least") FunCom.serial_clicks_by_control_file(tag)
import sys
def start(tag, pkg, events, throttle, logfile): FunCom.p_open( Res.asb_shell_start_monkey_with_s(tag) % (pkg, events, throttle, FunCom.get_abspath(logfile))).read()
def push_lib_to_phone(tag): lib_file = FunCom.get_abspath( FunCom.path_join(Res.lib_path, Res.monkey_lib_file_name)) FunCom.p_open(Res.asb_shell_push_file(tag, lib_file))