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 ...
随机推荐
- 渗透常见linux命令
在拿到一个 webshell 之后,大家首先会想到去把自己的权限提升到最高,windows 我们会提升到 SYSTEM 权限,而 Linux 我们会提升到 root 权限,拿在进行 Linux 提权的 ...
- vue--购物车案例(小知识点总结)
Html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- python学习2-数据库配置操作
1.创建实体类models-自定义数据库的字段与名称 class Register (models.Model): idCard=models.CharField(max_length=18) pwd ...
- Window平台下的静默下载并安装软件脚本bat
一,隐藏命令窗口 当我们运行bat脚本的时候,弹出CMD窗口.如果要隐藏窗口可以在bat脚本开头处写一下代码: @echo off if "%1" == "h" ...
- Ubuntu 18.04上安装Apache, MySQL, PHP, LAMP
1.安装 Apache $ sudo apt update && sudo apt install apache2 中间会遇到停顿询问是否继续, 输入 y 然后 回车. 2.测试 Ap ...
- CnetOS6.7编译安装MariaDB
--安装所需软件包 [root@localhost mariadb-10.1.14]# yum install bison bison-devel ncurses libxml2 libxml2-de ...
- SDL2学习(二):常用枚举值和函数
1. 高频枚举值或结构体 1.1 SDL_WindowFlags /** * \brief The flags on a window * * \sa SDL_GetWindowFlags() */ ...
- 网络yum源配置
系统环境:CentOS7 [1] 首先备份/etc/yum.repos.d/CentOS-Base.repo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum ...
- Linux安装Gitlab服务器
1. 下载GitLab 下载地址:https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-10.8.2-ce.0.el ...
- Machine Learning in Finance – Present and Future Applications
https://emerj.com/ai-sector-overviews/machine-learning-in-finance/ Machine learning has had fruitful ...