使用python+appium做android的自动化测试时,首先需要启动appium服务,然后连接上手机,配置如下:

desired_caps = {"platformName": "Android",
"deviceName": "127.0.0.1:62001",
"platformVersion": "4.4.2",
# apk包名
"appPackage": "com.ss.android.article.news",
# apk的launcherActivity
"appActivity": "com.ss.android.article.news.activity.SplashActivity",
"unicodeKeyboard": True,
"resetKeyboard": True}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

但是换一个app的话就需要改动很多代码,很不方便,可以将参数在配置文件里

    def desired_caps(self):
desired_caps = {}
desired_caps["platformName"] = self.data["platformName"]
desired_caps["deviceName"] = self.data["deviceName"]
desired_caps["platformVersion"] = self.data["platformVersion"]
desired_caps["appPackage"] = self.data["appPackage"]
desired_caps["appActivity"] = self.data["appActivity"]
desired_caps["noReset"] = self.data["noReset"]
desired_caps["unicodeKeyboard"] = self.data["unicodeKeyboard"]
desired_caps["resetKeyboard"] = self.data["resetKeyboard"] driver = webdriver.Remote("http://" + str(self.data["host"]) + ":" + str(self.data["port"]) + "/wd/hub", desired_caps)

配置文件使用的yaml文件

platformName: Android
platformVersion: 4.4.2
deviceName: 127.0.0.1:62001
appPackage: com.ss.android.article.news
appActivity: com.ss.android.article.news.activity.SplashActivity
noReset: True
unicodeKeyboard: True
resetKeyboard: True
host: 127.0.0.1
port: 4723

但是其实把参数写在了配置文件里。每次启动的时候还是需要打开appium服务。现在使用adb命令来启动appium,一起封装在desired_caps里面

class adb_start_appium(object):
def __init__(self):
with open('C://Users/EDZ/PycharmProjects/untitled/appium/desired_caps/desired_caps.yaml') as file:
self.data = yaml.load(file) def appium_start(self):
cmd = 'start /b appium -a ' + str(self.data['host']) + ' -p ' + str(self.data['port']) + ' -U ' + self.data['deviceName'] print('%s at %s' % (cmd, ctime()))
subprocess.Popen(cmd, shell=True, stdout=open('C://Users/EDZ/PycharmProjects/untitled/appium_SH/desired_caps/appium_log/'+str(self.data['port']) + '.log', 'a'), stderr=subprocess.STDOUT) def desired_caps(self):
desired_caps = {}
desired_caps["platformName"] = self.data["platformName"]
desired_caps["deviceName"] = self.data["deviceName"]
desired_caps["platformVersion"] = self.data["platformVersion"]
desired_caps["appPackage"] = self.data["appPackage"]
desired_caps["appActivity"] = self.data["appActivity"]
desired_caps["noReset"] = self.data["noReset"]
desired_caps["unicodeKeyboard"] = self.data["unicodeKeyboard"]
desired_caps["resetKeyboard"] = self.data["resetKeyboard"] driver = webdriver.Remote("http://" + str(self.data["host"]) + ":" + str(self.data["port"]) + "/wd/hub", desired_caps)
driver.implicitly_wait(8)
return driver

Python +appium 封装desired_caps模块的更多相关文章

  1. python自定义封装logging模块

    #coding:utf-8 import logging class TestLog(object): ''' 封装后的logging ''' def __init__(self , logger = ...

  2. python appium 封装获取toast方法

    获取toast text封装,传入toast 部分文本,返回全部文本 def get_toast_text(self,text): try: toast_loc = (By.XPATH, " ...

  3. Python +appium baseview

    封装python+appium 的baseview模块 from selenium.webdriver.support.ui import WebDriverWait from time import ...

  4. python封装configparser模块获取conf.ini值(优化版)

    昨天晚上封装了configparser模块,是根据keyname获取的value.python封装configparser模块获取conf.ini值 我原本是想通过config.ini文件中的sect ...

  5. Python + Appium 自动化操作微信入门看这一篇就够了

    简介 Appium 是一个开源的自动化测试工具,支持 Android.iOS 平台上的原生应用,支持 Java.Python.PHP 等多种语言. Appium 封装了 Selenium,能够为用户提 ...

  6. Python(五)模块

    本章内容: 模块介绍 time & datetime random os sys json & picle hashlib XML requests ConfigParser logg ...

  7. Python基础之--常用模块

    Python 模块 为了实现对程序特定功能的调用和存储,人们将代码封装起来,可以供其他程序调用,可以称之为模块. 如:os 是系统相关的模块:file是文件操作相关的模块:sys是访问python解释 ...

  8. Python学习笔记-常用模块

    1.python模块 如果你退出 Python 解释器并重新进入,你做的任何定义(变量和方法)都会丢失.因此,如果你想要编写一些更大的程序,为准备解释器输入使用一个文本编辑器会更好,并以那个文件替代作 ...

  9. 将Python脚本封装成exe可执行文件 转

    将Python脚本封装成exe可执行文件 http://www.cnblogs.com/renzo/archive/2012/01/01/2309260.html  cx_freeze是用来将 Pyt ...

随机推荐

  1. LeetCode_476. Number Complement

    476. Number Complement Easy Given a positive integer, output its complement number. The complement s ...

  2. idea内置tomcat中java代码热更新

    按照上图设置后,然后修改代码后按shift+F9快捷键,即可实现代码更新,这时在debug模式下会看到代码变更后的输出

  3. spring security实现记录用户登录时间等信息

    目录 spring security实现记录用户登录时间等信息 一.原理分析 二.实现方式 2.1 自定义AuthenticationSuccessHandler实现类 2.2 在spring-sec ...

  4. ThinkPHP3验证码、文件上传、缩略图、分页(自定义工具类、session和cookie)

    验证码 TP框架中自带了验证码类 位置:Think/verify.class.php 在LoginController控制器中创建生存验证码的方法 login.html登陆模板中 在LoginCont ...

  5. myssl.com SSL 检测

    配置正确了,就正常了. 与证书关系不大.

  6. asp.net中的html標籤runat=server時的映射

    asp.net中的html控制項runat=server時的映射 1.標準xhtml標籤:http://blog.csdn.net/TangZhongxin/archive/2009/07/31/43 ...

  7. php 函数篇

    1.array_values($data); 注:将关联数组转化为索引数组 <?php $a=array("Name"=>"Bill"," ...

  8. golang 网络编程之如何正确关闭tcp连接以及管理它的生命周期

    欢迎访问我的个人网站获取更佳阅读排版 golang 网络编程之如何正确关闭tcp连接以及管理它的生命周期 | yoko blog (https://pengrl.com/p/47401/) 本篇文章部 ...

  9. Jenkins 远程启动nodejs失败,使用pm2守护Nodejs

    一.概述 使用Jenkins 远程ssh到linux,使用命令: ssh root@192.168.10.1 'cd /data/test;nohup npm start &' 发现linux ...

  10. IDEA远程调试Ambari Server

    1.配置端口 Ambari Server默认配置了服务端的debug参数,端口为5005.如果要修改端口,可以在/usr/sbin/ambari_server_main.py文件中对应地方修改,直接改 ...