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)) + "." + ""
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 "制图完成"
appium+python 多设备并行执行脚本【转】的更多相关文章
- Appium+Python app自动化测试之脚本启动和停止Appium服务
研究了一段时间的Appium android app的自动化测试,工作中需要连接多台手机终端同时执行测试用例,我实现的方式是获取用例中需要执行用例的设备id个数以及实际连接到的设备数(通过adb de ...
- Appium+Python之测试数据与脚本分离
如果脚本中有很多的魔法数据,那代码的复用性就不会很高,所以我们需要将测试数据和脚本分离. 思路:将测试数据放在一个json文件中,然后写一个读取json文件的基类,测试用例中通过调基类中方法来获取js ...
- appium+python 【Mac】UI自动化测试封装框架介绍 <二>---脚本编写(单设备)
1.单设备的执行很简单,平时可多见的是直接在config中进行配置并进行运行即可.如下: # coding=UTF- ''' Created on // @author: SYW ''' from T ...
- Appium + Python App自动化第一个脚本
今天跟大家讲解一个Appium和Python App自动化的脚本.[1]打开你的夜神模拟器(或者连接你的手机) [2]打开桌面的Appium [3]下载你要测的App的apk文件,放到桌面[4]拖动你 ...
- Appium+python自动化(三十六)- 士兵突击许三多 - 多个appium服务启动,多个设备启动,多进程并发启动设备-并发测试 - 上(超详解)
简介 前面课程只是启动了单个appium服务,只能控制单台设备.如果需要针对多台设备测试那么该如何处理?而且发现群里的小伙伴们也在时不时地在讨论这个问题,想知道怎么实现的,于是宏哥就决定写一片这样的文 ...
- Appium自动化如何控制多设备并行执行
前言: 如何做到,控制多设备并行执行测试用例呢. 思路篇 我们去想下,我们可以获取参数的信息,和设备的信息,那么我们也可以针对每台设备开启不一样的端口服务.那么每个服务都对应的端口,我们在获取设备列 ...
- appium+Python真机运行测试demo的方法
appium+Python真机运行测试demo的方法 一, 打开手机的USB调试模式 二, 连接手机到电脑 将手机用数据线连接到电脑,并授权USB调试模式.查看连接的效果,在cmd下运行命 ...
- appium+python做移动端自动化测试
1 导言 1.1 编制目的 该文档为选用Appium作为移动设备原生(Native).混合(Hybrid).移动Web(Mobile Web)应用UI自动化测试的相关自动化测试人员.开发人员等提供 ...
- appium+Python 启动app(一)
当我们appium和Python环境都配置好了,如何启动我们第一个app呢?下面介绍appium+Python启动app的操作步骤,为了能够详细查看,我们这里使用夜游神模拟器进行示范. 测试项目:QQ ...
随机推荐
- PHP MySQL数据分页
SQL SELECT语句查询总是可能导致数千条记录.但是在一个页面上显示所有结果并不是一个好主意.因此,我们可以根据要求将此结果划分为多个页面.分页意味着在多个页面中显示您的查询结果,而不是仅将它们全 ...
- IOC : Unity 配置和使用
原文出自:IOC : Unity 配置和使用 之前Terry Lee 已经介绍过Unity的简单使用了,不过那篇文章是针对旧版本的,现在的版本1.2版略有不同. 我下载了Unity并做了一个简单的测试 ...
- Laravel 运行php artisan serve命令时提示No application encryption key has been specified
创建了新的laravel项目后, 运行提示:No application encryption key has been specified 解决方法: 这个是由于没有配置好 APP_KEY 在终端上 ...
- Seata为什么效率高
1. Seata为什么效率高 1.1. 应对面试官的解释 Seata的解决方案是两阶段提交的升级版,传统两阶段提交资源管理器(RM)放在数据库端,由数据库管理,需要数据库支持XA协议. 而Seata把 ...
- Ubuntu19.04安装常用软件
安装Indicator Stickynotes 桌面便签小工具sudo add-apt-repository ppa:umang/indicator-stickynotessudo apt-get u ...
- Android输出日志Log类并保存到文件中
android.util.Log常用的方法有以下5个: Log.v() Log.d() Log.i() Log.w() 以及 Log.e().根据首字母分别对应VERBOSE,DEBUG,INFO,W ...
- linux ssh免密
1.ssh-keygen -t rsa 生产密钥 2.ssh-copy-id 192.168.44.10 发布密钥
- Django框架操作数据库的两种方式
Django操作数据库的前提操作是成功连接数据库,详情见上篇:https://www.cnblogs.com/kristin/p/10791358.html Django查询数据库的方式一 from ...
- 【原创】Airflow调用talend
核心原理 因为talend job build出来是一个可直接运行的程序,可以通过shell命名启动job进程,因此可以使用airflow的bashoperator调用生成好的talend job包里 ...
- devops 下测试组织管理面临的挑战及应对
导读 先从引发的5个问题讲起,再简单回顾一下devops 简介和兴起背景 ,再从itest 测试管理团队的视角提出应对办法 DevOps后,测试面临的挑战 敏捷开发必然是迭代开发管理模式 ...