使用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. Classic BAdi and New BAdi

    Former Member Classic BAdi and New BAdi ... 2007年04月27日 04:43 | 1.5k Views Hi all, I have a question ...

  2. Playbooks简介

    Playbooks简介 关于Playbooks Playbook简单示例 基本组成 主机和用户 任务列表 Handlers: 配置更改时运行操作 执行Playbook Ansible-Pull Lin ...

  3. DevExpress XtraReport - 动态加载报表布局模板

    XtraReport的报表模板文件是.repx,下面的代码演示动态加载报表布局模板. XtraReport mReport = new XtraReport(); mReport.LoadLayout ...

  4. [LeetCode] 334. Increasing Triplet Subsequence 递增三元子序列

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  5. Android Studio 开发

    Android studio安装与配置 (收藏) https://www.cnblogs.com/gufengchen/p/10991886.html ------------------------ ...

  6. png8和png24的根本区别

    1.png8和png24的根本区别,不是颜色位的区别,而是存储方式不同. 2.png8有1位的布尔透明通道(要么完全透明,要么完全不透明),png24则有8位(256阶)的布尔透明通道(所谓半透明). ...

  7. Oracle Spatial分区应用研究之五:不同分区粒度+本地空间索引效率对比

    1.实验目的 若使用本地空间索引,不同分区粒度将产生不同索引组织,其索引分区个数.大小.R-TREE树结构均不相同.那么,在什么分区粒度下的本地空间索引效率较高呢? 2实验数据 实验数据为全国2531 ...

  8. MySQL [Err] 1055--1064 - Expression #1 of ORDER BY clause is not in GROUP BY clause

    1055错误: 方案1: 修改sql_mode的值 set sql_mode = '';set sql_mode = 'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABL ...

  9. C# 拷贝文件夹到指定文件夹并更改文件夹名称

    using System; using System.Collections.Generic; using System.Text; namespace ClientPrintServer.Tools ...

  10. php中让数组顺序随机化,打乱顺序等

    php中有很多排序的函数,sort,rsort,ksort,krsort,asort,arsort,natcasesort,这些函数用来对数组的键或值进行这样,或那样的排序. 可以终究有时候还需要一些 ...