码迷,mamicode.com
首页 > 其他好文 > 详细

集成jenkins自动安装apk文件

时间:2017-09-18 10:59:03      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:star   list   通过   parser   grep   retrieve   url   下载   bsp   


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文件

标签:star   list   通过   parser   grep   retrieve   url   下载   bsp   

原文地址:http://www.cnblogs.com/jinjidedale/p/7541416.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!