集成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命令對測試機進行操作

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM