集成jenkins自动安装apk文件
Posted 进击的大乐
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了集成jenkins自动安装apk文件相关的知识,希望对你有一定的参考价值。
def get_latest_package(self, path, filename): """ 在Jenkins下载最新的安装包 """ apk_path = os.path.join(sys.path[0], filename) if os.path.exists(apk_path): os.remove(filename) url = ‘http://xxx:8080/job/xxx/lastSuccessfulBuild/artifact/xxx/app/build/outputs/apk/‘ response = urllib.urlopen(url) the_page = response.read() soup = BeautifulSoup(the_page, ‘html.parser‘) all_a = soup.find_all(‘a‘) apk_filename = ‘‘ build_id = " " for a in all_a: if a.text.strip().startswith(‘#‘): build_id = a.text.strip().replace("#","") if a.text.strip().endswith(‘release.apk‘): apk_filename = a.text.strip() break full_filename = os.path.join(path, filename) build_id = build_id + " ;包名:" + apk_filename full_url = ‘%s/%s‘ %(url, apk_filename) urllib.urlretrieve(full_url, full_filename) return full_filename, build_id def get_keyboard_present_status(self, device_name): """ 通过adb命令获取键盘状态 """ system_name = platform.system() if system_name.lower() == ‘windows‘: cmdline = ‘adb -s %s shell dumpsys input_method | findstr mInputShown‘ %device_name else: cmdline = ‘adb -s %s shell dumpsys input_method | grep mInputShown‘ %device_name my_print = os.popen(cmdline).read() if my_print.find(‘mInputShown=true‘) != -1: return True return False def adb_input_text(self, device_name, set_value, get_value=""): """ 通过adb命令对输入框输入值 """ if get_value != "": txt_len = len(get_value) cmdline = ‘adb -s %s shell input keyevent 123‘ % device_name for i in range(txt_len): cmdline += ‘ & adb -s %s shell input keyevent 67‘ % device_name cmdline += ‘ & adb -s %s shell input text %s‘ % (device_name, set_value) else: cmdline = ‘adb -s %s shell input text %s‘ % (device_name, set_value) print cmdline os.system(cmdline) def get_devicename(self): """ 通过adb命令获取设备名 """ # os.system("adb devices") devicename = "" my_print = os.popen("adb devices").read() print_lists = my_print.split("\n") if len(print_lists) > 3: devicename = print_lists[1].split("\t")[0] print devicename return devicename
def android_adb_install(self, deviceName, apk_path): """ 通过adb命令安装app :param deviceName: :return: """ cmd_str = os.popen("adb -s %s uninstall com.gf" % (deviceName,)).read() print cmd_str cmd_str = os.popen("adb -s %s install %s" % (deviceName, apk_path)).read() print cmd_str return (‘successful install‘)
通过上述操作,可以将jenkins上的apk安装包直接安装到测试机,
首先通过jenkins将最新的安装包下载,然后通过adb命令对测试机进行操作
以上是关于集成jenkins自动安装apk文件的主要内容,如果未能解决你的问题,请参考以下文章