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 ...
随机推荐
- 【C#】C#托付和事件的实例解说
using System; namespace delegate_event { // 定义一个猫类 class Cat { // 定义一个名字字段 private string name; // 创 ...
- 我看Java二十年:它是怎样永远改变编程的。
转自jdon的小文章:来自Infoworld的一篇纪念mod=viewthread&tid=3042" target="_blank">Java诞生20周年 ...
- 如何下载最新版的 Adobe Flash Player
如何下载最新版的 Adobe Flash Player 中国访客用代理访问下面的链接,否则会自动跳转到 https://www.flash.cn/ 当我们从 https://get.adobe.com ...
- vue5 过滤器 模版
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vim 基础学习之文件跳转
1. ''-当前文件上次跳转之前的位置2. '.-当前文件上次修改的位置,只要是发生了可能导致变化的命令操作就会被标记,哪怕实际结果没有变化3. '^-当前文件上次插入的位置,只要是发生了插入操作命令 ...
- IBM软件技术峰会归来
为期两天在北京国际饭店会议中心的IBM软件技术峰会已近结束,此次大会最大的收获是能和沃森实验室的王博士沟通探讨人工智能软件的发展问题.领略到IBM 云计算首席架构师Jason R.McGee如何呼风唤 ...
- while my time-- , will the meaning++?
// while my time--,will the meaning++? // However,what's the meaning of life ? while(tomorrow>0){ ...
- Springboot 获取yml、properties参数
获取properties或yml文件的配置数据(两种方法)(默认的application文件或者自定义的yml和properties) 1.使用@Value()注解 1.1 配置数据 如:在prope ...
- HDU 4588 Count The Carries 数位DP || 打表找规律
2013年南京邀请赛的铜牌题...做的非常是伤心.另外有两个不太好想到的地方.. ..a 能够等于零,另外a到b的累加和比較大.大约在2^70左右. 首先说一下解题思路. 首先统计出每一位的1的个数, ...
- 4.2.2 MINUS
4.2.2 MINUS正在更新内容,请稍后