def run_monkey(self, monkey_shell, actions=False, widget_black=False): ''' 清理旧的配置文件并运行monkey,等待运行时间后pull log文件到电脑 :param monkey_shell: shell命令 uiautomatortroy 时 max.xpath.selector文件需要配置正确 :param actions: 特殊事件序列 max.xpath.actions文件需要配置正确 :param widget_black: 黑控件 黑区域屏蔽 max.widget.black文件需要配置正确 :return: ''' self.clear_env() self.push_jar() if monkey_shell.find('awl.strings'): self.push_white_list() if monkey_shell.find('uiautomatortroy'): self.push_selector() if actions: self.push_actions() if widget_black: self.push_widget_black() self.set_AdbIME() runtime = monkey_shell.split('running-minutes ')[1].split(' ')[0] logger.info('starting run monkey') logger.info( 'It will be take about %s minutes,please be patient ...........................' % runtime) cmd.adb_shell(monkey_shell) time.sleep(int(runtime) * 60 + 30) logger.info('Maxim monkey run end>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
def pull_monkeylog(): if 'monkeyerr.txt' in cmd.adb_shell( 'ls /sdcard/') and 'monkeyout.txt' in cmd.adb_shell('ls /sdcard/'): cmd.pull('/sdcard/monkeyerr.txt', '../GT_Report/monkeyerr.txt') cmd.pull('/sdcard/monkeyout.txt', '../GT_Report/monkeyout.txt') logger.info('pull monkeyerr.txt monkeyout.txt ---> /GT_Report/') return True else: logger.error('There is monkeyelog file,Please check out!') return False
def pull_js(dst='../GT_Report/data/data.js'): '''将手机内的data.js复制到电脑''' if 'data' in cmd.adb_shell('ls /sdcard/GTRData/'): logger.info('Starting to pull data.js to %s ' % os.path.abspath(dst)) cmd.pull('/sdcard/GTRData/data.js', dst) logger.info('Pull data.js success') return True else: logger.error( 'There is no data.js in /sdcard/GTRData/! Please check out!') return False
def set_AdbIME(self): ime = cmd.adb_shell('ime list -s') if 'adbkeyboard' in ime: cmd.adb_shell('ime set com.android.adbkeyboard/.AdbIME') logger.info('Set adbkeyboard as default') else: cmd.install_apk('../apk/ADBKeyBoard.apk') cmd.adb_shell('ime enable com.android.adbkeyboard/.AdbIME') cmd.adb_shell('ime set com.android.adbkeyboard/.AdbIME') logger.info('install adbkeyboard and set as default') self.push_string()
def clear_env(self): logger.info('Clearing monkey env') cmd.adb_shell('rm -r /sdcard/monkeyerr.txt') cmd.adb_shell('rm -r /sdcard/monkeyout.txt') cmd.adb_shell('rm -r /sdcard/max.widget.black') cmd.adb_shell('rm -r /sdcard/max.xpath.selector') cmd.adb_shell('rm -r /sdcard/max.xpath.actions') cmd.adb_shell('rm -r /sdcard/awl.strings') cmd.adb_shell('rm -r /sdcard/monkey.jar') cmd.adb_shell('rm -r /sdcard/framework.jar') cmd.adb_shell('rm -r /sdcard/max.strings') cmd.adb_shell('rm -r /sdcard/monkeyerr.txt') cmd.adb_shell('rm -r /sdcard/monkeyout.txt') logger.info('Clear monkey env success')