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 ...
随机推荐
- Codeforces 528A Glass Carving STL模拟
题目链接:点击打开链接 题意: 给定n*m的矩阵.k个操作 2种操作: 1.H x 横向在x位置切一刀 2.V y 竖直在y位置切一刀 每次操作后输出最大的矩阵面积 思路: 由于行列是不相干的,所以仅 ...
- leetcode -day23 Construct Binary Tree from Inorder and Postorder Traversal & Construct Binary Tree f
1. Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder travers ...
- shrio 加密/编码
在涉及到密码存储问题上,应该加密/生成密码摘要存储,而不是存储明文密码.比如之前的600w csdn账号泄露对用户可能造成很大损失,因此应加密/生成不可逆的摘要方式存储. 5.1 编码/解码 Shir ...
- 线性同余同余方程组解法(excrt)
[问题描述] 求关于 x 的同余方程组 x%a 1 =b 1 a1=b1 x%a 2 =b 2 a2=b2 x%a 3 =b 3 a3=b3 x%a 4 =b 4 a4=b4 的大于等于 0 ...
- 简单的字符串压缩--C代码
#include <stdio.h> #include <string.h> bool compress(char *str) { char *p=str,c; ; if(!s ...
- HTTP 各种特性应用(二)
一.Cookie 通过 Set-Cookie 设置. 下次浏览器请求就会带上. 键值对,可以设置多个. Cookie 属性 max-age 和 expires 设置过期时间 Secure 只在 htt ...
- python requests请求卡住问题
最近经常接到别人反馈某个爬虫工具程序没有正常运行,需要下载的资讯数据也没有及时进行收录. 刚开始以为可能是机器的问题,偶尔机器会出现程序运行中途卡住的情况. 但随着异常的情况越来越频繁,我便只好去排查 ...
- Vue官方文档中的camelCased (驼峰式) 命名与 kebab-case
因为html特性中 元素的 prop是不区分大小写的 所以不管html中怎么大写小写变化,下面的组件的prop应该写成小写 Vue中有这样一种设定: props中如果使用为kebab-case命名方式 ...
- 【Redis发布订阅】
Redis通过PUBLISH.SUBSCRIBE等命令实现发布与订阅模式. 举例:QQ群的公告,单个发布者,多个收听着. *** 发布/订阅 PUBLISH 频道 消息 将消息发布到指定的频道. . ...
- 紫书 例题 9-3 UVa 1347 ( 状态设计)
首先做一个转化,这种转化很常见. 题目里面讲要来回走一遍,所以就转化成两个从起点到终点,路径不重合 那么很容易想到用f[i][j]表示第一个走到i,第二个人走到j还需要走的距离 但是这里无法保证路径不 ...