pytest 框架自动化Selenium 之yield 使用
环境
python 3.7 由于3.0-3.5以下部分pytest可能有部分兼容问题安装建议2.7-2.9,3.5-最新
pip install pytest专属 pytest框架包
pip install allure-pytest 专属allure的报告包后面会用到可以不安装这里
pip install pytest-html pytest自己专属报告包
pip install pytest-rerunfailures 失败重跑包也是pytest专属
并发的也可以安下,利用多cpu运行调高用例执行速度
python -m pip install xdist

配置
file>>setting>>tools>>Diff>>python integrated tools,选取pytest框架

2.重新封装webdriver定位方法
# coding=utf-8
"""
@author: ChenQuan 2019/1/20;
@:param: rewrite old find ways and return ele or elements ;
@:param: Usage: ele/elements = GetEle().ele_by_id(locator)
@:param: driver is given by setup/fixture by yield
"""
class GetEle(object):
def __init__(self,driver): self.driver=driver def find_element(self,*loc):
return self.driver.find_element(*loc) def find_elements(self,*loc):
return self.driver.find_elements(*loc) def openPage(self,url):
self.driver.get(url) def getTitle(self):
return self.driver.current_url
3.编写pytest脚本
pytest命名规则:
包名test_开头或者以_test结尾
用例名称test_格式开头
类名称Test开头
4.脚本解释:
yield 作用是类似return ,在用例执行完成后会返回继续执行yield后面代码,yield将在python4.0以后删除详情见官网
# coding=utf-8
import pytest
from selenium import webdriver
from pyfoo.Utils.pageobj import GetEle
from pyfoo.Utils.pageobj import *
@pytest.fixture(scope="class")
def driver():
url="http://www.baidu.com"
driver= webdriver.Chrome()
driver.get(url)
yield driver
driver.close()
print("teardown...")
@pytest.mark.usefixtures("driver")
class Test_fix_module(object):
def test_open_bd(self,driver):
GetEle().find_element(By.IDr,'kw').send_keys("pytest")
GetEle().find_element(By.ID,'su').click()
print("搜索资源成功")
def test_open_tb(self,driver):
GetEle().find_element(By.XPATH,'//*[@id="s_tab"]/div/a[1]').click()
print("进入资讯系列")
if __name__ == "__main__":
pytest.main(['-v','-s','-q'])

pytest 框架自动化Selenium 之yield 使用的更多相关文章
- 自从学会了Python自动化Pytest框架,领导再也不敢在我背后指手划脚了
前言 大家都知道Python有自带的单元测试框架unittest,那为什么还要学习Pytest呢?先了解下Pytest优点 pytest: pytest是一个非常成熟的全功能的Python测试框架,是 ...
- 《Selenium+Pytest Web自动化实战》随到随学在线课程,零基础也能学!
课程介绍 课程主题:<Selenium+Pytest Web自动化实战> 适合人群: 1.功能测试转型自动化测试 2.web自动化零基础的小白 3.对python 和 selenium 有 ...
- Pytest(18)pytest接口自动化完整框架思维导图
pytest接口自动化完整框架思维导图
- python pytest接口自动化框架搭建(一)
1.首先安装pytest pip install pytest 2.编写单测用例 在pytest框架中,有如下约束: 所有的单测文件名都需要满足test_*.py格式或*_test.py格式. 在单测 ...
- requests接口自动化-pytest框架
pytest框架规则 测试文件以test_开头或者以_test结尾 测试类以Test开头,并且不能带有init方法 测试函数以test_开头 断言使用assert pytest框架运行用例 运行单个文 ...
- pytest框架使用教程
Pytest框架 一.简介 pytest:基于unittest之上的单元测试框架 有什么特点? 自动发现测试模块和测试方法 断言更加方便,assert + 表达式,例如 assert 1 == 1 灵 ...
- pytest框架的安装与使用
pytest框架的安装与使用 一,pytest了解 pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高. ...
- 『德不孤』Pytest框架 — 1、Pytest测试框架介绍
目录 1.什么是单元测试框架 2.单元测试框架主要做什么 3.单元测试框架和自动化测试框架有什么关系 4.Pytest测试框架说明 5.Pytest框架和Unittest框架区别 (1)Unittes ...
- 『德不孤』Pytest框架 — 2、Pytest的基本使用
目录 1.Pytest安装 2.Pytest常用插件 3.Pytest运行的第一个例子 4.Pytest框架的运行方式 5.在PyCharm中以Pytest的方式运行测试用例 1.Pytest安装 C ...
随机推荐
- Tips——RN canvas缩放处理
一.关于canvas缩放 canvas图像缩放处理有两种思路: ctx.scale(),对整个canvas进行重绘,会导致每次缩放都重新加载,影响体验效果 在canvas外包层view,直接对外层的v ...
- csharp:获取 DNS、网关、子网掩码、IP
/// <summary> /// DNS.网关.子网掩码.IP /// 涂聚文 2015 /// </summary> public class IPAddressStrin ...
- centos 删除文件和目录
每次都记不住,发个文章记录一下.直接rm就可以了,不过要加两个参数-rf 即:rm -rf 目录名字-r 就是向下递归,不管有多少级目录,一并删除-f 就是直接强行删除,不作任何提示的意思 删除文件夹 ...
- LeetCode 536----Construct Binary Tree from String
536. Construct Binary Tree from String You need to construct a binary tree from a string consisting ...
- redis介绍(2)简单安装
我分两种方式讲解 window 下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 位.这个需要根据你系统平台的实 ...
- python queue和生产者和消费者模型
queue队列 当必须安全地在多个线程之间交换信息时,队列在线程编程中特别有用. class queue.Queue(maxsize=0) #先入先出 class queue.LifoQueue(ma ...
- Linux 环境下为VirtualBox安装增强功能
VirtualBox安装CentOS后,再安装增强功能就可以共享文件夹.粘贴板以及鼠标无缝移动,主要步骤如下: 1.yum -y update 2.yum -y install g++ gcc gcc ...
- 使用ServiceBroker自动激活模拟"秒杀"场景
1.简介 SQL Server Service Broker 是SQL server 里面比较独特的一个功能.它可帮助开发人员构建异步的松散耦合应用程序 ServiceBroker入门文章:http: ...
- 如何在ScrollView滑动的瞬间禁用拖拽手势
如何在ScrollView滑动的瞬间禁用拖拽手势 效果: 在UIScrollView滑动的瞬间禁用pan手势,可以防止用户按着屏幕不放后导致出现的一些莫须有的bug. // // ViewContro ...
- [控件] 心形加载的view
心形加载的view 效果: 素材图片: 源码: StarView.h 与 StarView.m // // StarView.h // Star // // Created by XianMingYo ...