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 "制图完成"

 

转载于:https://www.cnblogs.com/lixy-88428977/p/10439251.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值