- 博客(54)
- 收藏
- 关注
原创 yaml接口自动化实战(2)
import yamlclass YamlUtil: def __init__(self,yaml_file): """ 通过 init方法把yaml文件传入到这个类 :param yaml_file """ self.yaml_file=yaml_file def read_yaml(self): """ 读取yaml,对yaml反序列化,就是把yaml格式转换成dict格式
2021-07-06 23:59:14
404
原创 Yaml介绍(一)
#1、用于全局的配置文件 ini/yaml#2、用于写测试用例(接口测试用例)#yaml简介: yaml是一种数据格式,支持注释,换行,多行字符串,裸字符串(整形,字符串)#语法规则:#1、区别大小写#2、使用缩进表示成绩,不能使用tab键缩进,只能使用空格(和pathon一样)#3、缩进没有数量,只要前面是对齐的就行#4、注释是##----------------------------------#数据组成#1、Map对象,键值对 键:(空格)值#多行写法#msxy:
2021-07-06 23:53:28
470
原创 Pytest.mark.parametrize()
#@ pytest.mark.parametrize(args_name,args_value)#args_name 参数昵称#vaule:参数值(列表,元组,字典列表,字典元组),有多个值用例就会执行多少次第一种方式import pytest,osclass Testapi(): @pytest.mark.parametrize('args',['花木兰','凯','苏烈']) #结果 花木兰 凯 苏烈 #@pytest.mark.parametrize('args'
2021-07-06 23:25:46
331
转载 pytest文档5-fixture之conftest.py
前面一篇讲到用例加setup和teardown可以实现在测试用例之前或之后加入一些操作,但这种是整个脚本全局生效的,如果我想实现以下场景:用例1需要先登录,用例2不需要登录,用例3需要先登录。很显然这就无法用setup和teardown来实现了。这就是本篇学习的目的,自定义测试用例的预置条件fixture优势1.firture相对于setup和teardown来说应该有以下几点优势命名方式灵活,不局限于setup和teardown这几个命名 conftest.py配置里可以实现数据共享,不需.
2021-07-01 18:26:59
182
原创 smoke
pytest -vs -m “smoke” #执行装饰器带smoke的用例 -vs可以不加 pytest.ini配置文件已经加了pytest -vs -m “smoke or usermange” #执行装饰器带smoke 和 username 的用例import pytestclass TestLogin(): age=18 def setup(self): print("\n这是执行前的用例") def test_06_qianghong2(sel
2021-06-29 23:50:08
276
2
原创 pytest前置和后置
setup/teardowm,setup_class/teardowm_classsetup 在每个用例之前执行一次teardown 在每个用例之后执行一次setup_class这个在所有用例之前只执行一次(在每个类执行前的初始化工作,比如创建日志对象,创建数据库的连接,创建接口的请求对象)teardowm_class 这个在所有用例之后只执行一次(在每个类执行后的初始化工作,比如销毁日志对象,销毁数据库的连接,销毁接口的请求对象)这两种方法可以混合使用,例如setup搭配teardown_
2021-05-14 22:47:15
419
原创 一、Pytest简介和插件库
1、Pytest 简介1、pytest是一个非常成熟的pytest的单元框架2、pytest可以和selenium、requests、appnium完成web自动化、接口自动化、app自动化3、pytest可以实现测试用例的跳过以及return失败用例重跑4、pytest可以和allure生成非常美观的测试报告5、pytest可以和jmeter持续集成6、pytest有非常多强大的插件(1)、 pytest-html 生成html格式的自动化测试报告(2)、pytest-xdist 测试用例
2021-05-13 22:44:42
523
原创 Pytest测试用例的执行方法
如下是目录结构:1、主函数模式(1)运行所有 pytest.main()(2)指定模块 pytest.main(’[-vs],’,’./testcase/test_day1.py’)(3)指定目录pytest.main(’[-vs]’),’./testcase’)(4)通过nodeid指定用例运行:nodeid由模块名,分隔符,类名,方法名,函数名组成#pytest.main(["-vs"],’./interface_testcase/test_day3.py::test_demo11’)#
2021-05-13 22:40:22
1468
6
原创 ordering插件改变用例执行顺序
前提:安装pytest-ordering 插件,可用于改变测试用例的执行顺序1、unittest执行顺序 根据assii码进行执行2、pytest 从上到下依次执行 pytest.mark.run(order=2) 使用mark标记,改变默认的执行顺序,未装饰的使用默认的从上到下执行实例:import pytestclass TestLogin(): def test_06_qianghong2(self): print("我是杨强弘六号") @pytest
2021-05-13 22:33:48
187
原创 二、markers 分组测试
七、如何分组执行(冒烟,分模块执行,分接口和web执行)#需要执行的用例使用装饰器进行装饰,关键字可以自定义,在pytest.ini处需要声明 markers[pytest]addopts=-vstestpaths=./python_files=test_*.pypython_classes=Test*python_functions=testmarkers=smoke:冒烟用例 usermange:用户管理模块 productmanage:商品管理模块目
2021-05-13 22:29:36
176
原创 simple和Loghtml
报告的目录:主程序的路径:C:\Users\admin、\Downloads\AirtestIDE-win-1.2.5\AirtestIDE\case.air\Demo.air\Demo.pysimple_report 生成报告#-*- encoding=utf8 -*-__author__ = "admin、"from airtest.core.api import *from airtest.report.report import simple_reportfrom airtest.
2021-04-30 17:45:36
159
1
原创 抖音分身
添加分身__author__ = "admin、"from time import sleepfrom airtest.core.api import *from poco.drivers.android.uiautomation import AndroidUiautomationPocopoco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)auto_setup(__file_
2021-04-29 09:23:38
593
原创 airtest 截图和多图查找
# -*- encoding=utf8 -*-__author__ = "yangqianghong"from airtest.aircv import *from airtest.core.api import *from airtest.cli.parser import cli_setupfrom airtest.core.settings import Settings as STfrom poco.drivers.android.uiautomation import Android
2021-04-29 09:23:01
2224
原创 zipfile压缩
import zipfiledef zipDir(dirpath,outFULLName): zip=zipfile.ZipFile(outFULLName,'w',zipfile.ZIP_DEFLATED) for path,dirnames,filenames in os.walk(dirpath): fpath=path.replace(dirpath,"") for filename in filenames: zip.wri
2021-04-26 14:08:29
2447
原创 airtest封装的滑动
from airtest.core.api import *from airtest.report.report import simple_reportfrom airtest.report.report import LogToHtmlfrom poco.drivers.android.uiautomation import AndroidUiautomationPocofrom airtest.core.helper import Gfrom airtest.core.android.adb
2021-04-25 10:50:56
575
原创 ADB
# -*- coding: utf-8 -*-import osimport sysfrom time import sleepfrom random import randintclass Event(object): def __init__(self): '''常用keyevent事件''' self.KEYCODE_HOME = 3 # home键 self.KEYCODE_MENU = 82 # 解锁 sel
2021-04-21 17:43:44
219
原创 HTMLTestRunner生成测试报告
用例执行完成后,执行结果默认是输出在屏幕上,其实我们可以把结果输出到一个文件中,形成测试报告。unittest自带的测试报告是文本形式的,如下代码:import unittestimport os#测试用例目录test_dir=os.path.dirname(os.path.abspath(__file__))#加载测试用例disvover=unittest.defaultTestLoader.discover(test_dir,pattern="test_Suite.py")#测试报告
2021-04-20 18:22:25
550
原创 discover执行多个用例
前面我们说了,对于不同文件用例,我们可以通过addTest()把用例加载到一个测试套件(TestSuite)来统一执行,对于少量的文件这样做没问题,但是如果有几十上百个用例文件,这样做就太浪费时间了。unittest中的discover()方法可以批量加载用例discover(start_dir, pattern=‘test*.py’, top_level_dir=None)start_dir:测试模块名或测试用例所在目录pattern=‘test*.py’:表示用例文件名的匹配方式,此处匹配的是以
2021-04-19 18:10:42
241
原创 荣耀体验门店
# import json# import requests# #url="https://openapi.vmall.com/mcp/offlineshop/getShopList" #https://m.vmall.com/help/hnrstoreaddr.htm# url="https://openapi.vmall.com/mcp/offlineshop/getShopList"## heardes={"Mozilla/5.0 (Windows NT 10.0; Win64; x
2021-04-19 17:58:00
3930
原创 cls和self的区别
注意cls和self的区别class A(object): a = 'a' @staticmethod def foo1(name): print 'hello', name print A.a # 正常 print A.foo2('mamq') # 报错: unbound method foo2() must be called with A instance as first argument (got str instance
2021-04-19 15:58:22
151
原创 Unittest_assert
常用断言方法import unittestclass Test(unittest.TestCase): def test_01(self): print('判断a是否存在b中') a = '安静' b = '测试安静' self.assertIn(a, b) def test_02(self): print('判断a是否等于b') a = '111' b =
2021-04-18 23:48:56
167
原创 Unittest_skipe
# 在执行测试用例时,有时候有些用例是不需要执行的,那我们怎么办呢?难道删除这些用例?那下次执行时如果又需要执行这些用例时,又把它补回来?这样操作就太麻烦了。## unittest提供了一些跳过指定用例的方法## @unittest.skip(reason):强制跳转。reason是跳转原因# @unittest.skipIf(condition, reason):condition为True的时候跳转# @unittest.skipUnless(condition, reason):condi
2021-04-18 23:46:33
178
原创 Unittest_suite
#Test Suite简称测试套件,就是可以将不同的用例都添加到这个套件中,然后通过执行套件,然后完成执行测试用例。# 在前面一章中示例了如何编写一个简单的测试,但有两个问题:## 我们知道测试用例的执行顺序是根据测试用例名称顺序执行的,在不改变用例名称的情况下,我们怎么来控制用例执行的顺序呢?# 一个测试文件,我们直接执行该文件即可,但如果有多个测试文件,怎么进行组织,总不能一个个文件执行吧?# 要解决上面两个问题,我们就要用到测试套件(TestSuite)了import unittes
2021-04-18 23:44:41
237
1
原创 selenium爬取药监总局
url="http://125.35.6.84:81/xk/"from selenium import webdriverfrom lxml import etreefrom time import sleeppage_text_list=[]driver=webdriver.Chrome()driver.get("http://125.35.6.84:81/xk/")sleep(1)page_text=driver.page_sourcepage_text_list.append(p
2021-04-14 00:40:07
566
原创 yagmail—邮件发送
import yagmail# 连接邮箱服务器email = yagmail.SMTP(user="1584807779@qq.com", password="slycewbmwqzrfhbj", host="smtp.qq.com",# smtp服务器,每个邮箱各不相同,请自行百度 port=465)# 服务器端口,自行百度# 发送一份简单的邮件email.send(t.
2021-04-14 00:17:55
548
1
原创 详解OS模块路径问题
import osconf_path = os.path.dirname(os.path.abspath(__file__))work_path = os.path.dirname(os.path.dirname(conf_path))data_path = os.path.join(work_path, "data")print(conf_path)print(work_path)print(data_path)print(os.path.abspath(os.path.dirname(os
2021-03-29 16:05:41
285
1
原创 应用启动速度
# -*- encoding=utf8 -*-__author__ = "yangqianghong"from airtest.core.api import *import logginglogger = logging.getLogger("airtest")logger.setLevel(logging.ERROR)from airtest.cli.parser import cli_setupfrom airtest.core.android import androidfrom
2021-03-26 21:32:12
190
原创 项目路径
# -*- coding: utf-8 -*-# @File : ProjectPath.py# @Author: Zhaoziqi# @Date : 2021/2/18# @Desc :import globimport osclass ProjectPath: """项目路径""" def __init__(self): self.basedir = os.path.abspath(os.path.dirname(os.path.dirname(
2021-03-26 21:25:07
161
原创 设备滑动(上下,左右)
# -*- encoding=utf8 -*-import osimport timefrom random import choicezuohua=("100 810 550 810")youhua=("550 810 100 810")s=(zuohua,youhua) #不可用count=0for i in range(10000): time1 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())
2021-03-26 21:24:24
231
原创 Case2 个人路径
# -*- encoding=utf8 -*-__author__ = "admin、"from airtest.core.api import *from airtest.report.report import simple_reportfrom airtest.report.report import LogToHtmlfrom airtest.core.helper import Gfrom threading import Threadfrom random import randi
2021-03-26 21:22:42
271
原创 Airtest一些方法
https://mp.weixin.qq.com/s?__biz=MzUxMDc4NTkwMA==&mid=2247484579&idx=1&sn=950ebd07b063674b3a1f5f6ae2abe768
2021-03-26 21:21:31
830
原创 Case1公司路径
# -*- encoding=utf8 -*-__author__ = "admin、"from airtest.core.api import *from poco.drivers.android.uiautomation import AndroidUiautomationPocoauto_setup(__file__)poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
2021-03-26 21:20:08
244
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人