Appium_pytest fixture的使用
一、定义fixture方法
# -*- coding:utf-8 -*-
import pytest
from baseutil.DriverUtil import DriverConfig @pytest.fixture
def driver_handle():
driver = DriverConfig().get_driver() # get_driver()中是设备建立连接的配置
yield driver
driver.close_app()
driver.quit()
二、测试方法中传入driver
@pytest.mark.flaky(reruns=2, reruns_delay=2)
@pytest.mark.usefixtures("driver_handle")
def test_user_register(self, driver_handle):
self.driver = driver_handle
此时使用self.driver.find_element(By.ID,"id").click() 就可以正常使用了 三、get_driver()内容
class DriverUtil:
def get_driver(self):
'''获取driver'''
try:
desired_caps = {}
desired_caps['platformName'] = 'Android' # 平台
desired_caps['Version'] = '9.0.0' # 系统版本
desired_caps['appPackage'] = 'aaa.bbb.ccc' # APK包名
desired_caps['appActivity'] = '.ui.StartActivity' # 被测程序启动时的Activity
desired_caps['unicodeKeyboard'] = 'true' # 是否支持unicode的键盘。如果需要输入中文,要设置为“true”
desired_caps['resetKeyboard'] = 'true' # 是否在测试结束后将键盘重轩为系统默认的输入法。
desired_caps['newCommandTimeout'] = '120' # Appium服务器待appium客户端发送新消息的时间。默认为60秒
desired_caps['deviceName'] = 'P7CDU1833333' # 手机ID
desired_caps['automationName'] = 'Uiautomator2' # 启动Uiautomator2获取toast
desired_caps['noReset'] = True # true:不重新安装APP,false:重新安装app
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)
return driver
四、调用fixture方法中的变量
@pytest.fixture
def init_car_data():
fo = FileOperate()
car_info = fo.get_first_line_content("carInfo")
at = AppTools()
company_name_list = at.get_company(car_info[0])
return car_info,company_name_list
@pytest.mark.usefixtures("init_car_data")
def test_carinfo10(self,driver_handle,init_car_data):
"""用例描述:车辆信息10"""
car_info = init_car_data[0]
company_name_list = init_car_data[1]
Appium_pytest fixture的使用的更多相关文章
- [小北De编程手记] : Lesson 04 玩转 xUnit.Net 之 Fixture(下)
上一篇文章<[小北De编程手记] : Lesson 03 玩转 xUnit.Net 之 Fixture(上)>向大家介绍了xUnit.Net 共享数据的方式.Test Case的构造函数 ...
- [小北De编程手记] : Lesson 03 玩转 xUnit.Net 之 Fixture(上)
在使用xUnit.Net Framework构建单元测试或自动化测试项目的时候,无论是针对一些比较耗费资源的对象亦或是为了支持Test case预设数据的能力,我们都需要有一些初始化或是清理相关的动作 ...
- fitnesse 中各类fit fixture的python实现
虽然网上都说slim效率很高,无奈找不到支持python的方法,继续用pyfit 1 Column Fixture 特点:行表格展现形式,一条测试用例对应一行数据 Wiki !define COMMA ...
- pytest进阶之xunit fixture
前言 今天我们再说一下pytest框架和unittest框架相同的fixture的使用, 了解unittest的同学应该知道我们在初始化环境和销毁工作时,unittest使用的是setUp,tearD ...
- pytest进阶之fixture
前言 学pytest就不得不说fixture,fixture是pytest的精髓所在,就像unittest中的setup和teardown一样,如果不学fixture那么使用pytest和使用unit ...
- 单元测试之Fixture
声明: 作者:zhaojun 创建日期:2017-08-04 更新日期:2017-08-07 一.什么是Fixture,Fixture有什么作用,为什么需要使用Fixture # 下载 pip i ...
- pytest 15 fixture之autouse=True
前言 平常写自动化用例会写一些前置的fixture操作,用例需要用到就直接传该函数的参数名称就行了.当用例很多的时候,每次都传这个参数,会比较麻烦.fixture里面有个参数autouse,默认是Fa ...
- pytest 12 函数传参和fixture传参数request
前沿: 有的case,需要依赖于某些特定的case才可以执行,比如,登陆获取到的cookie,每次都需要带着他,为了确保是同一个用户,必须带着和登陆获取到的同一个cookies. 大部分的用例都会先登 ...
- pytest自动化4:fixture之yield实现teardown
出处:https://www.cnblogs.com/yoyoketang/p/9401554.html 前言: 上一篇介绍了fixture通过scope参数控制setup级别,我们一起来温故下fix ...
随机推荐
- Android控件-单选按钮RadioButton
RadioGroup单选按钮用法,还是先看效果图 先中后,点RadioGroup测试按钮,可在标题栏显示选择结果,点清除可以清除选择.下面上代码,main.xml: <RadioGroup an ...
- 【引用】Android程序实现完全退出
这是我在网上找到的,方法不错,都能够实现程序的完全退出http://www.jb51.net/article/37992.htm
- org.xml.sax.SAXParseException: Content is not allowed in prolog
sax错误:org.xml.sax.SAXParseException: Content is not allowed in prolog解决 标签: org. xml. sax. saxparse ...
- while my time-- , will the meaning++?
// while my time--,will the meaning++? // However,what's the meaning of life ? while(tomorrow>0){ ...
- angularjs 页面缓存及动态刷新解决方案
一.准备工作 框架:angularjs ui组件库:ionic1 二.页面缓存cache 路由设置cache参数,true为缓存,false为不缓存,代码如下: angular.module('app ...
- 安装php-ldap模块
php-ldap模块作用就是实现ldap认证,因此需要安装 1.安装软件包解决依赖 yum install openldapyum install openldap-devel 2.拷贝库文件 cp ...
- Mark Sweep GC
目录 标记清除算法 标记阶段 深度优先于广度优先 清除阶段 分配 First-fit.Best-fit.Worst-fit三种分配策略 合并 优点 实现简单 与保守式GC算法兼容 缺点 碎片化 分配速 ...
- 【Henu ACM Round #13 E】Spy Syndrome 2
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 对m个串建立一棵字典树. 然后对主串. 尝试从第一个位置开始.在字典树中尝试匹配 如果匹配到了位置i 就再从位置i+1开始尝试匹配 ...
- CCF模拟题 最大的矩形
最大的矩形 时间限制: 1.0s 内存限制: 256.0MB 问题描述 在横轴上放了n个相邻的矩形,每个矩形的宽度是1,而第i(1 ≤ i ≤ n)个矩形的高度是hi.这n个矩形构成了一个直方 ...
- log4j+slf4j迁移到log4j2+slf4j (Servlet3.0)
近期对系统中的旧项目实现log升级,选择了log4j2来取代log4j.作为最新一代的log实现.log4j2好在那里能够直接看log4j2性能章节. 这里写写怎样从log4j升级到log4j2. 1 ...