当前位置:网站首页>pytest接口自动化测试框架 | pytest参数化
pytest接口自动化测试框架 | pytest参数化
2022-07-22 09:48:00 【COCOgsta】
视频来源:B站《冒死上传!pytest接口自动化测试框架(基础理论到项目实战及二次开发)教学视频【软件测试】》
一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!
import pytest
from selenium import webdriver
from time import sleep
"""
pytest参数化
当一组测试用例有固定的测试数据时,就可以通过参数化的方式简化测试用例的编写。
通过pytest.mark.parametrize()方法设置参数:
参数名:"user,pw,expected"用来定义参数的名称
参数值:通过数组定义参数值时,每一个元组都是一条测试用例的测试数据
ids参数:默认None,用来重新定义测试用例的名称
"""
@pytest.mark.parametrize(
"user,pw,expected",
[("xuzhu666", "123456", "xuzhu666,欢迎来到"),
("zz666", "123456", "zz666,欢迎来到")],
ids=["case1","case2"])
def test_login(user,pw,expected):
driver = webdriver.Chrome()
driver.get("http://39.98.138.157/shopxo/")
driver.find_element_by_link_text("登录").click()
driver.find_element_by_xpath("/html/body/div[4]/div/div[2]/div[2]/form/div[1]/input").send_keys(user)
driver.find_element_by_xpath('/html/body/div[4]/div/div[2]/div[2]/form/div[2]/input').send_keys(pw)
driver.find_element_by_xpath("/html/body/div[4]/div/div[2]/div[2]/form/div[3]/button").click()
sleep(3)
# == 测试相等
# 登录成功检查
welcome = driver.find_element_by_xpath("//*[contains(text(),'欢迎来到')]").text
assert expected == welcome
driver.quit()
if __name__ == '__main__':
pytest.main(['-s', "test_param.py"])
运行结果
C:\Users\guoliang\AppData\Local\Programs\Python\Python36\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2022.1.3\plugins\python-ce\helpers\pycharm\_jb_pytest_runner.py" --target test_param.py::test_login
Testing started at 18:10 ...
Launching pytest with arguments test_param.py::test_login --no-header --no-summary -q in D:\SynologyDrive\CodeLearning\pytest\base_used
============================= test session starts =============================
collecting ... collected 2 items
test_param.py::test_login[case1]
test_param.py::test_login[case2]
============================= 2 passed in 36.90s ==============================
Process finished with exit code 0
PASSED [ 50%]PASSED [100%]
边栏推荐
- Leetcode daily question 2021/12/20-2021/12/26
- 助力品牌洞察——消费者情绪行为分析
- Idea Quick Start Guide
- arguments
- LeetCode 每日一题 2022/1/3-2022/1/9
- Research on the principle of Tencent persistence framework mmkv
- Leetcode daily question 2022/2/21-2022/2/27
- grafana面板-关于转换
- Leetcode daily question 2022/1/10-2022/1/16
- Laravel solves [1045] access denied for user 'homestead' @ 'localhost' (usin g password: yes)
猜你喜欢
Jackson parsing JSON detailed tutorial
Enumerate properties in objects
Nacos persistent connection MySQL database SM4 encryption scheme
experience""/>
Renjie, chief scientist of rongyun: experience produces talents, and career "experience > experience"
Swagger UI introduction and common notes
Scenario practice | how to use rongyun super group to build a game community
用指针遍历数组
Grafana panel - override field values
JS advanced - understanding of functions
Grafana panel - about conversion
随机推荐
PHP implementation deletes a value in a one-dimensional array
Grafana panel - modify visual text and background colors
Day5:构造程序逻辑
Bean 的作用域和生命周期
LeetCode 每日一题 2022/3/21-2022/3/27
JS advanced - lexical scope
The force deduction method summarizes the k-diff number pairs in the 532 array
LeetCode 每日一题 2021/12/13-2021/12/19
IT外包服务业各领域的未来前景和趋势
Force deduction solution summary 1108-ip address invalidation
Traversing an array with a pointer
Call() and apply()
工业路由器油田无线监控
Jackson parsing JSON detailed tutorial
由浅入深详解NLP中的Adapter技术
Why is it necessary to rewrite the hashcode method when rewriting the requests method
关于红队方面的学习资料
Force deduction solution summary 731- my schedule II
DOM add
2022版Centos8 yum镜像安装&阿里云安装Mysql 5.7教程与问题解决