monkeyrunner进行多设备UI测试  
首先你要连接好多个手机
设置好已经连接好的手机的ip列表ipp = ['192xxx','192xxx']
杀掉之前所有appium进程subprocess.Popen('killall node',shell = True)
声明一个方法def start(ip):调用时需要把ipp传入
在方法中写for循环,循环内循环内用传入的ip来启动appium服务,注意要用不同的端口号启动,相差2以上
在循环中调用webdriver.Remote方法创建driver对象
在循环中创建脚本类的实例时,请在循环中创建,并且传入driver
8.声明多线程列表
在循环中用多线程创建该实例的方法的对象,并加入多线程列表
在main函数中,先调用start方法,填充好多线程的列表。然后再用for循环启动多线程列表。

下面上start方法代码:

def start(ip):
    for i in range(len(ip)):
    subprocess.Popen(‘/Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/build/lib/main.js –address “127.0.0.1” -p “’+str(4723+2*i)+’” –command-timeout “100” –automation-name “Appium” -U “’+ip[i]+’:’+str(5555+i)+’” >/tmp/1.txt’,shell=True)
    time.sleep(3.5)
    wzj = webdriver.Remote(‘http://localhost:’+str(4723+2*i)+’/wd/hub’, desired_caps)
    dingwei = DingWei(wzj, name)
    t = threading.Thread(target=dingwei.begin)
    tt.append(t)

上面的DingWei 是我的脚本类,其中的begin是类中的启动脚本的方法。下面上主函数的代码

if name == “main“:
    start(ipp)
    time.sleep(2)
    for i in tt:
    i.start()

下面是全套脚本:拿去用吧,自己改改。

# -*- coding:utf-8 -*-
from __future__ import division
import time
import datetime,subprocess
import unittest
import threading
from appium import webdriver
import os
import xlrd,xlwt,xlutils
from xlutils.copy import copy
import wx
from HTMLTestRunner import HTMLTestRunner
from appium.webdriver.common.touch_action import TouchAction
from appium.webdriver.common.touch_action import TouchAction

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.1'
desired_caps['deviceName'] = 'hahaha'
desired_caps['appPackage'] = 'com.........blehunter.debug'
desired_caps['appActivity'] = 'com.........blehunter.ui.WelcomeActivity'
# desired_caps["unicodeKeyboard"] = "True"
# desired_caps["resetKeyboard"] = "True"
subprocess.Popen('killall node',shell=True)
ipp = ['192.168.0.171','192.168.0.175']
tt = []   #多线程对象
def server(ip):
    for i in range(len(ip)):
        name = "./new/"+str(ipp[i])+"*****"+time.ctime()+".xls"
        SZ = xlrd.open_workbook('./new/0.xls')
        ww = copy(SZ)
        ww.save(name)
        subprocess.Popen('/Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/build/lib/main.js --address "127.0.0.1" -p "'+str(4723+2*i)+'" --command-timeout "100"  --automation-name "Appium" -U "'+ip[i]+':'+str(5555+i)+'" >/tmp/1.txt',shell=True)
        time.sleep(3.5)
        wzj = webdriver.Remote('http://localhost:'+str(4723+2*i)+'/wd/hub', desired_caps)
        dingwei = DingWei(wzj, name)
        t = threading.Thread(target=dingwei.begin)
        tt.append(t)

class DingWei():
    def __init__(self,www,fname):
        self.wzj = www
        self.num = 0
        self.fname = fname
        self.SZ = xlrd.open_workbook(self.fname)
        self.sz = self.SZ.sheet_by_name("sheet1")
        self.ww = copy(self.SZ)
        self.nrows = self.sz.nrows
    def id(self,s):
        return self.wzj.find_element_by_id(s)
    ################
    def first_start(self):
        time.sleep(4)
        for i in range(7):
            try:
                self.wzj.swipe(1000, 1500, 180, 1500)
            except:
                self.wzj.swipe(400,706,90,706)
            time.sleep(0.2)
        time.sleep(3)
        try:
            self.wzj.find_element_by_id("com.........blehunter.debug:id/bt_guide_login").click()
        except:
            pass
        time.sleep(4)
        self.id('com.........blehunter.debug:id/et_phone').send_keys('18810437161')
        self.id('com.........blehunter.debug:id/et_phone_password').send_keys('qwerty')
        self.id('com.........blehunter.debug:id/btn_login').click()
        time.sleep(5)
    def chushihua(self):
        while 1:
            if self.m.is_enabled():
                try:
                    self.id('com.........blehunter.debug:id/tv_location_failed')
                except:
                    pass
                break
            else:
                pass
    def panduan(self,no):
        while 1:
            if self.m.is_enabled():
                try :
                    self.id('com.........blehunter.debug:id/tv_location_failed')
                    self.ww.get_sheet(0).write(no+1, 1, "failed")
                    os.remove(self.fname)
                    self.ww.save(self.fname)
                except :
                    self.ww.get_sheet(0).write(no+1, 1, "success")
                    os.remove(self.fname)
                    self.ww.save(self.fname)
                    self.num += 1
                break
            else:
                pass
    def begin(self):
        #self.first_start()
        self.wzj.implicitly_wait(10)
        b = self.wzj.find_element_by_xpath('//android.support.v7.widget.RecyclerView/android.widget.FrameLayout[2]/android.widget.ImageView')
        b.click()
        print self.wzj,u"初始次... "
        self.m = self.id('com.........blehunter.debug:id/iv_refresh_friend_location')
        self.chushihua()
        j = 0
        time0 = datetime.datetime.now()
        #总次数
        n = input(u'请输入测试次数,必须为整数!')
        for i in range(n):
            j += 1
            time.sleep(1)
            time1 = datetime.datetime.now()
            self.id('com.........blehunter.debug:id/iv_refresh_friend_location').click()
            self.panduan(i)
            time2 = datetime.datetime.now()
            self.ww.get_sheet(0).write(i+1, 2, "j")
            self.ww.get_sheet(0).write(i+1, 3, str(self.num))
            self.ww.get_sheet(0).write(i+1, 4, str(j-self.num))
            self.ww.get_sheet(0).write(i+1, 5, str((time2-time1).seconds))
            self.ww.get_sheet(0).write(i+1, 6, str(int((time2-time0).seconds)-j))
            os.remove(self.fname)
            self.ww.save(self.fname)
        self.ww.get_sheet(0).write(n+2, 0,str(((self.num)/n)*100)[:6]+'%' )
        os.remove(self.fname)
        self.ww.save(self.fname)

if __name__ == "__main__":
    server(ipp)
    time.sleep(2)
    for i in tt:
        i.start()

原文:https://blog.csdn.net/qq_22795513/article/details/53169416

monkeyrunner 进行多设备UI测试的更多相关文章

  1. WWDC15 Session笔记 - Xcode 7 UI 测试初窥

    https://onevcat.com/2015/09/ui-testing/ WWDC15 Session笔记 - Xcode 7 UI 测试初窥 Unit Test 在 iOS 开发中已经有足够多 ...

  2. 使用uiautomator做UI测试

    转载~~~~~~~~~~~~~~~~~~~~~~~~ 若有侵权,请及时联系本博主,博主将第一时间撤销 在Android 4.1发布的时候包含了一种新的测试工具–uiautomator,uiautoma ...

  3. 使用uiautomatorviewer和uiautomator来做android的UI测试

    来自:http://university.utest.com    作者:Angelos Nakulas (All Authored Courses)      译者:Elaine00 目录 简介 什 ...

  4. [转载]使用uiautomator做UI测试

    这个只是单纯的mark一下.还没有认真去研究.鉴于最近也不会做手机的自动化测试,所以留作以后参考吧. 转自: http://blog.chengyunfeng.com/?p=504 在Android ...

  5. Google推出iOS功能性UI测试框架EarlGrey

    经过了一段时间的酝酿后,Google很高兴地宣布了EarlGrey,一款针对于iOS的功能性UI测试框架.诸如YouTube.Google Calendar.Google Photos.Google ...

  6. 在Android Studio中进行单元测试和UI测试

    本篇教程翻译自Google I/O 2015中关于测试的codelab,掌握科学上网的同学请点击这里阅读:Unit and UI Testing in Android Studio.能力有限,如有翻译 ...

  7. 4、Android UI测试

    为你的APP进行UI测试是为了确保不出现意料之外的结果,提升用户的体验.如果你需要验证你的APP UI的正确性,你需要养成创建UI测试的习惯. Espresso测试框架是由Android Testin ...

  8. H5测试点总结-UI测试、功能测试、兼容性测试、体验相关(弱网、资源、手机操作等)、安全性测试、性能测试

    一.概述 1.1 什么是H5 H5 即 HTML5,是最新的 Web 端开发语言版本,现如今,大多数手机 APP 页面会用 H5 实现,包括 PC Web 站点也会用它开发实现.所以 Web 的通用测 ...

  9. 一种新的自动化 UI 测试解决方案 Airtest Project

    今天分享一个自动化UI测试工具airtest——一款网易出品的基于图像识别面向游UI测试的工具,也支持原生Android App基于元素识别的UI自动化测试.主要包含了三部分:Airtest IDE. ...

随机推荐

  1. echarts绘制饼图时的一点特殊设置

    最后的效果如图,需要在中间展示的部分换行然后字体大小不同. 以下为option的设置,使用rich里面的参数来设置更多的文本样式,使用‘\n’来控制换行 let option = { color: c ...

  2. 探索Redis设计与实现11:使用快照和AOF将Redis数据持久化到硬盘中

    本文转自互联网 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial ...

  3. (转)使用OpenGL显示图像(六)响应触摸事件

    响应触摸事件 编写:jdneo - 原文:http://developer.android.com/training/graphics/opengl/touch.html 让对象根据预设的程序运动(如 ...

  4. django 里面的更新数据(update)

    https://blog.csdn.net/qq_42606051/article/details/81162189 https://blog.csdn.net/luojie140/article/d ...

  5. 2019牛客多校第五场B-generator 1(矩阵快速幂)

    generator 1 题目传送门 解题思路 矩阵快速幂.只是平时的矩阵快速幂是二进制的,这题要用十进制的快速幂. 代码如下 #include <bits/stdc++.h> #defin ...

  6. B - Heshen's Account Book HihoCoder - 1871

    题目链接:https://hihocoder.com/problemset/problem/1871 思路:满满的细节满满的坑,尤其是 123df123 居然也要算成123123 的时候真是惊呆了,我 ...

  7. Java web后台插入数据库中文乱码问题解决

    前言:项目想要避免乱码情况的出现,要保持服务器.数据库.项目.以及前端编码一致.一.项目以及前端编码,设置. myeclipse--->右键项目--->Properties--->R ...

  8. nmon 定时任务 监控资源

    nmon命令: # ./nmon  –f  -s 30 –c 100 说明:-f 以文件的形式输出,默认输出是机器名+日期.nmon的格式,也可以用-F指定输出的文件名,例如: # ./nmon_x8 ...

  9. fedora 25重新安装引导

    引导区被其他系统给覆盖了,重新安装引导 grub2-install /dev/sdb GRUB_SAVEDEFAULT=true BIOS grub2-mkconfig -o /boot/grub2/ ...

  10. Python matplotlib 交互模式

    在交互模式下一定要执行plt.pause(0.0001)  才会显示图像