使用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. CSS继承控制:inherit、initial和unset

    CSS里有三种常用的属性值继承方式:inherit,initial和unset.我们用一个简单的例子来演示一下: <ul style="color: green;"> ...

  2. win7下IntelliJ IDEA使用curl

    curl是利用URL语法在命令行方式下工作的开源文件传输工具 curl命令可以在开发web应用时,模拟前端发起的HTTP请求 1.下载curl https://curl.haxx.se/downloa ...

  3. 【视频开发】ONVIF、RTSP/RTP、FFMPEG的开发实录

    ONVIF.RTSP/RTP.FFMPEG的开发实录 前言 本文从零基础一步步实现ONVIF协议.RTSP/RTP协议获取IPC实时视频流.FFMPEG解码.开发环境为WIN7 32位 + VS201 ...

  4. bridge和原生交互的简单用法

    首先获取当前环境是ios还是Android var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u ...

  5. org.apache.hadoop.conf.Configuration无法引用 解决方法

    我用的是Hadoop-common 2.6.4jar,可是明明包里面有这个类却引用不了,然后我看了下包里面是一个抽象类......................................... ...

  6. C/C++ 快速排序实现

    #include<iostream> using namespace std; void qS(int *array,int left,int right){ if(left<rig ...

  7. Go调用Delphi编写的DLL

    参数整数没有问题,但是如果是字符串,要注意几个细节. 记录如下: 1.Delphi定义函数的时候,字符串参数需要使用PChar类型 2.Go传递参数的时候要将字符串转成UTF16的指针,接收的时候采用 ...

  8. SpringBootServletInitializer报错

    1. 现象 从Springboot 1.5.1.RELEASE 升级到Springboot 2.1.2.RELEASE 后SpringBootServletInitializer报错. 2.解决方法 ...

  9. Java单元测试 Http Server Mock框架选型

    背景动机 某期优化需要针对通用的HttpClient封装组件--HttpExecutor在保证上层暴露API不动的前提做较多改动,大致包括以下几点: apache http client 版本升级 H ...

  10. 关于SQL中SELECT *(星号)的危害论

    听闻有许多人是禁止开发人员在SQL中使用SELECT *的,这里翻译一下StackOverflow的一篇提问,个人认为相当客观 [SELECT *]危害主要有以下几点: 给数据消费者传数据的低效.当你 ...