一、定义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的使用的更多相关文章

  1. [小北De编程手记] : Lesson 04 玩转 xUnit.Net 之 Fixture(下)

    上一篇文章<[小北De编程手记] : Lesson 03 玩转 xUnit.Net 之 Fixture(上)>向大家介绍了xUnit.Net 共享数据的方式.Test Case的构造函数 ...

  2. [小北De编程手记] : Lesson 03 玩转 xUnit.Net 之 Fixture(上)

    在使用xUnit.Net Framework构建单元测试或自动化测试项目的时候,无论是针对一些比较耗费资源的对象亦或是为了支持Test case预设数据的能力,我们都需要有一些初始化或是清理相关的动作 ...

  3. fitnesse 中各类fit fixture的python实现

    虽然网上都说slim效率很高,无奈找不到支持python的方法,继续用pyfit 1 Column Fixture 特点:行表格展现形式,一条测试用例对应一行数据 Wiki !define COMMA ...

  4. pytest进阶之xunit fixture

    前言 今天我们再说一下pytest框架和unittest框架相同的fixture的使用, 了解unittest的同学应该知道我们在初始化环境和销毁工作时,unittest使用的是setUp,tearD ...

  5. pytest进阶之fixture

    前言 学pytest就不得不说fixture,fixture是pytest的精髓所在,就像unittest中的setup和teardown一样,如果不学fixture那么使用pytest和使用unit ...

  6. 单元测试之Fixture

    声明: 作者:zhaojun  创建日期:2017-08-04  更新日期:2017-08-07 一.什么是Fixture,Fixture有什么作用,为什么需要使用Fixture # 下载 pip i ...

  7. pytest 15 fixture之autouse=True

    前言 平常写自动化用例会写一些前置的fixture操作,用例需要用到就直接传该函数的参数名称就行了.当用例很多的时候,每次都传这个参数,会比较麻烦.fixture里面有个参数autouse,默认是Fa ...

  8. pytest 12 函数传参和fixture传参数request

    前沿: 有的case,需要依赖于某些特定的case才可以执行,比如,登陆获取到的cookie,每次都需要带着他,为了确保是同一个用户,必须带着和登陆获取到的同一个cookies. 大部分的用例都会先登 ...

  9. pytest自动化4:fixture之yield实现teardown

    出处:https://www.cnblogs.com/yoyoketang/p/9401554.html 前言: 上一篇介绍了fixture通过scope参数控制setup级别,我们一起来温故下fix ...

随机推荐

  1. 面试基础_03实现strcpy、strcat、strcmp、strlen

    实现代码例如以下: /************************************************************************* > File Name: ...

  2. HDU 2444 The Accomodation of Students 二分图判定+最大匹配

    题目来源:HDU 2444 The Accomodation of Students 题意:n个人能否够分成2组 每组的人不能相互认识 就是二分图判定 能够分成2组 每组选一个2个人认识能够去一个双人 ...

  3. JS控制光标定位,定位到文本的某个位置

    这是一个数字密码,要能够智能的跳转到文本的某个位置,就需要通过JS来控制跳转! 1.onkeyup监听 <input class="put" id="number- ...

  4. Android - TextureView, SurfaceView和GLSurfaceView 以及 SurfaceTexture

    这几个概念比较绕, 又比较相近. 初看比较糊涂, 把握关键点就好. 关键字 View SurfaceViewGLSurfaceViewTextureView这三个后缀都是View, 所以这三个东西都是 ...

  5. codeforces 710A King Moves(水)

    output standard output The only king stands on the standard chess board. You are given his position ...

  6. org.w3c.dom.Document 与org.dom4j.Document互转

    public static Document parse(org.w3c.dom.Document doc) throws Exception { if (doc == null) { return ...

  7. 【Henu ACM Round#15 A】 A and B and Chess

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 统计大写和小写的个数. 比较答案.输出即可. [代码] #include <bits/stdc++.h> using n ...

  8. 洛谷 P1877 [HAOI2012]音量调节

    P1877 [HAOI2012]音量调节 题目描述 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都需要改变一次音量.在演出开始之前,他已经做好一个列表,里面 ...

  9. 阿里云server改动MySQL初始password---Linux学习笔记

    主要方法就是改动 MySQL依照文件以下的my.cnf文件 首先是找到my.cnf文件. # find / -name "my.cnf" # cd /etc 接下来最好是先备份my ...

  10. 修正EasyUI的BUG——Form中存在FileBox时的数据载入错误

    使用EasyUI载入服务端返回的数据时经常使用 $('#fm').form('load', row); 实现,既方便又简洁,可是.当Form中包括有FileBox时,代码就会报错,经过跟踪发现.由于E ...