import os # 导入路径拼接
import time
import unittest
import requests
import yaml # 导入yaml模块获取yaml文件值
from ddt import ddt, data, unpack # 导入数据驱动
from selenium import webdriver
from selenium.webdriver.common.by import By
from HTMLTestRunner3_New import HTMLTestRunner
f = open(os.path.join('D:\pythonpj\pytest\lojump.yaml'), 'r', encoding='utf-8')
ts_et = yaml.safe_load(f)
url = 'http://192.168.52.129:8080/cms/manage/loginJump.do'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
drurl = 'http://192.168.52.129:8080/cms/manage/login.do'
@ddt
class lg(unittest.TestCase):#定义一个类继承单元
@data(*ts_et)
@unpack
def test_logjump(self, **dict): # 定义一个测试用例
option = webdriver.ChromeOptions()
option.add_experimental_option("detach", True)
driver = webdriver.Chrome(chrome_options=option)
driver.get(drurl)
time.sleep(2)
driver.find_element(By.XPATH, '//*[@id="userAccount"]').send_keys(dict['userAccount'])
driver.find_element(By.XPATH, '//*[@id="loginPwd"]').send_keys(dict['loginPwd'])
driver.find_element(By.XPATH, '//*[@id="loginBtn"]').click()
reps = requests.post(url=url, headers=headers,
data={'userAccount': dict['userAccount'],
'loginPwd': dict['loginPwd']})
time.sleep(2)
js = reps.json()
if js['msg'] == '登录成功!': # 设定断言
assert js['msg'] == '登录成功!' # 捕获断言
print('恭喜你接口登录成功')
elif js['msg'] == '登录密码不正确!':
assert js['msg'] == '登录密码不正确!'
print('密码不正确')
elif js['msg'] == '登录密码不能为空!':
assert js['msg'] == '登录密码不能为空!'
print('密码不能为空')
elif js['msg'] == '登录帐号不能为空!':
assert js['msg'] == '登录帐号不能为空!'
print('账户不能为空')
else:
print('接口登录不成功')
driver.quit()
def logjum():
a1_path = os.path.abspath(os.path.dirname(__file__))
report_path = os.path.join(a1_path, '用例测试报告.html')
discre = unittest.defaultTestLoader.discover(start_dir=a1_path, pattern='g2.py')
p = open(report_path, 'wb')
run = HTMLTestRunner(stream=p, title='登录接口用例测试报告', description='执行情况', tester='you')
run.run(discre)
if __name__ == '__main__':
logjum()
for i in range(0):
unittest.main()
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Python自动化测试实战篇(4)selenium+unttest+ddt实现自动化用例测试,模拟用户登陆点击交互测试,Assert捕获断言多种断言.zip (3个子文件)
g2.py 3KB
用例测试报告.html 9KB
lojump.yaml 206B
共 3 条
- 1
资源评论
轻烟飘荡
- 粉丝: 2573
- 资源: 33
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功