当前位置:网站首页>pytest接口自动化测试框架 | pytest断言
pytest接口自动化测试框架 | pytest断言
2022-07-22 09:48:00 【COCOgsta】
视频来源:B站《冒死上传!pytest接口自动化测试框架(基础理论到项目实战及二次开发)教学视频【软件测试】》
一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!
import pytest
from selenium import webdriver
from time import sleep
"""
借助Python的运算符号和关键字实现不同数据类型的断言。
"""
# 商城登录案例
def test_login_success():
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("zz666")
driver.find_element_by_xpath('/html/body/div[4]/div/div[2]/div[2]/form/div[2]/input').send_keys("123456")
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 'zz666,欢迎来到' == welcome
driver.quit()
# != 测试不相等
# <= 测试小于等于
# >= 测试大于等于
# not in 测试不包含
# in 测试包含
# 判断是否为true
# 判断是否不为true
if __name__ == '__main__':
pytest.main(['-s', "test_assert.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_assert.py::test_login_success
Testing started at 17:59 ...
Launching pytest with arguments test_assert.py::test_login_success --no-header --no-summary -q in D:\SynologyDrive\CodeLearning\pytest\base_used
============================= test session starts =============================
collecting ... collected 1 item
test_assert.py::test_login_success PASSED [100%]
============================= 1 passed in 12.58s ==============================
Process finished with exit code 0
边栏推荐
- LeetCode 每日一题 2022/2/21-2022/2/27
- Force deduction solution summary 1217- playing chips
- LeetCode 每日一题 2022/3/28-2022/4/3
- PHP implementation deletes a value in a one-dimensional array
- Leetcode daily question 2022/1/17-2022/1/23
- Leetcode daily question 2021/12/6-2021/12/12
- SQL 查询语句性能优化
- Go language learning: go language journey (V)
- Renjie, chief scientist of rongyun: experience produces talents, and career "experience > experience"
- Force deduction solution summary 729- my schedule I
猜你喜欢
30出头成为复旦博导,陈思明:敲代码和写诗,我两样都要
Methods of wrapping classes and strings
Introduction to date object
2022版Centos8 yum镜像安装&阿里云安装Mysql 5.7教程与问题解决
Matlab plot子图的间距和边缘距离如何调整(已解决)
Centos7 installs MySQL 5.7 decompressed version & Navicat connection MySQL & firewall settings - the personal test is valid
不再执着于用产品说话,苹果库克加大美国反垄断游说投入:今年上半年支出 460 万美元
An analysis of the CPU surge of an RFID tag management system in.Net
Scope and lifecycle of beans
关于人力外包公司那些事
随机推荐
浏览器逻辑漏洞合集
Several trends in the future development of software industry
QT中多线程的使用
MySQL implements querying data from other tables and inserting another table
Leetcode daily question 2022/2/7-2022/2/13
Leetcode daily question 2022/3/21-2022/3/27
助力品牌洞察——消费者情绪行为分析
Fluent adjusts the drawing shape by dragging
什么是“实时”
蓝队资源大合集
The force deduction method summarizes the number of 1252 odd value cells
Flutter 第一个程序Hello World!
Mysql5.7 decompression configuration steps
用指针遍历数组
LeetCode 每日一题 2022/3/28-2022/4/3
他的一只鸟,卖了6000万 ——明清大家八大山人藏品发售
威胁狩猎大合集
Leetcode: 627. Change gender
This points to the problem
LeetCode 每日一题 2022/2/28-2022/3/6