• appium+python 多设备并行执行脚本【转】


    1.ready.py文件

    def getport():
        aport = random.randint(4700, 4900)
        # 判断端口是否被占用
        while getDeviceInfo.is_open('127.0.0.1', aport):
            aport = random.randint(4700, 4900)
        bpport = random.randint(4700, 4900)
        while getDeviceInfo.is_open('127.0.0.1', bpport):
            bpport = random.randint(4700, 4900)
        return aport, bpport
    def getsys():
        sys = str(random.randint(4, 6)) + "." + str(random.randint(4, 6)) + "." + "2"
        return sys
     
     
    class readyH(object):
        def __init__(self,device):
            self.device = device
            aa= getport()
            self.ap = aa[0]
            self.bp = aa[1]
     
        def installapp(self):
            os.popen("adb install -r "+str(getApkPath.get_apk_path()))
     
        def start_appium(self):  # device_uid,
            # appium -p 4723 -bp 4724 -U 22238e79 --command-timeout 600
            errormsg = ""
            appium_server_url = ""
            try:
                ap = getport()[0]
                bp = getport()[1]
                print ap,bp,self.device
                cmd = 'appium' + ' -p ' + str(self.ap )+ ' --bootstrap-port ' + str(self.bp) + ' -U ' + str(self.device) # ' -U '+ device_uid+
                print cmd
                # p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #stdout=PIPE, stderr=PIPE)
                p = subprocess.Popen(cmd, shell=True)
                print p
            except Exception, msg:
                errormsg = str(msg)
        def get_driver(self):
            desired_caps = {}
            desired_caps['platformName'] = 'Android'
            desired_caps['platformVersion'] = getsys()
            desired_caps['app'] = getApkPath.get_apk_path()
            desired_caps['appPackage'] = 'vStudio.Android.Camera360'
            desired_caps['deviceName'] = self.device
            url = 'http://localhost:%s/wd/hub' % str(self.ap)
            print url
            self.driver = webdriver.Remote(url, desired_caps)
            return self.driver
        def disdrop(self):
            self.driver.close_app()
            self.driver.quit()
        def main_case(self):
            self.installapp()
            time.sleep(10)
            self.start_appium()
            time.sleep(5)
            self.get_driver()
            time.sleep(5)
            testcase.myCase(self.driver,self.device).case_one()
            time.sleep(5)
            self.disdrop()

    2.run.py

    class myThread(threading.Thread):
        def __init__(self,device):
            threading.Thread.__init__(self)
            self.device = device
        def run(self):
            if __name__ == '__main__':
                a = ready.readyH(self.device)
                a.main_case()
     
    if __name__ == '__main__':
     
        try:
            devices = mod_config.getDeviceListConfig("alldevices")
     
            tt =[]
            for device in devices :
                t = myThread(device[0])
                tt.append(t)
            for t in tt:
                t.start()
                time.sleep(5)
            for t in tt:
                t.join()
        except:
            print "线程运行失败"

    3.testcase.py

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    from appium import webdriver
    from public import mod_config
    from lib import appiumLib
    import time
     
    _initSize = [1080,1776]
     
    class myCase(object):
        def __init__(self,driver,device):
            self.device = device
            self.driver = driver
        def case_one(self):
            print self.driver
            tipsclick = mod_config.get_config("firstPage", "开机画面跳过")
            setting = mod_config.get_config("mine", "设置")
            about = mod_config.get_config("mine", "关于")
            c360icon = mod_config.get_config("mine", "图标")
            entersdk = mod_config.get_config("mine", "特效测试")
            makePic = mod_config.get_config("mine", "制图测试")
            mine = mod_config.get_config("firstPage", "我的")
     
            appiumLib.click_by_id(self, tipsclick)
            appiumLib.click_by_name(self, "立即体验")
            appiumLib.back_times(self, 1)
            time.sleep(2)
            appiumLib.click_by_xpath(self, mine)
            # 取消发布按钮处的提示信息
            appiumLib.tap_forxy(self, [595, 150], _initSize, 500)
     
            appiumLib.click_by_id(self, setting)
            appiumLib.click_by_id(self, about)
            appiumLib.click_by_id(self, c360icon)
            appiumLib.click_by_id(self, entersdk)
            appiumLib.click_by_id(self, makePic)
            for i in range(0, 3):
                time.sleep(5)
                appiumLib.click_by_id(self, makePic)
            print "制图完成"
  • 相关阅读:
    Android流畅度测试
    linux常用操作指令
    SQL语句
    客户端专项测试谈
    我的面经(ing)
    整理面试题
    百度质量部测试开发面试题
    UIResponder响应链
    NSURLSession进行网络请求
    命令行工具打包
  • 原文地址:https://www.cnblogs.com/lixy-88428977/p/10439251.html
Copyright © 2020-2023  润新知