zoukankan      html  css  js  c++  java
  • unittest_API自动化脚本应用

    import urllib.request
    import urllib.parse
    import json
    import unittest
    from HTMLTestRunner import HTMLTestRunner
    
    class qfeelapi(unittest.TestCase):
        def setUp(self):
            self.url = ""#这是发送请求的url地址
            self.headers = {
         #这是请求头,如果不知道可以用抓包工具抓出来的
    } self.cookie = {
          #cookie请求体,如果不知道可以用抓包工具抓出来的} print("start") def tearDown(self): print("over") pass def test_01(self): self.values = { #这是写入第一个user登录信息 } print("当前用户",str(self.values))#输出当前登录的用户账号 key = urllib.parse.urlencode(self.values).encode(encoding='UTF8') req = urllib.request.Request(self.url, key, self.headers,self.cookie) response = urllib.request.urlopen(req) the_page = response.read() ing = json.loads(the_page) print(ing) def test_02(self): self.values = { #这是写入第二个user登录信息 }
         print("当前用户",str(self.values))#输出当前登录的用户账号 key
    = urllib.parse.urlencode(self.values).encode(encoding='UTF8') req = urllib.request.Request(self.url, key, self.headers,self.cookie) response = urllib.request.urlopen(req) the_page = response.read() ing = json.loads(the_page) print(ing) if __name__ == '__main__':#main函数执行测试用例 suite = unittest.TestSuite() suite.addTest(qfeelapi('test_01')) suite.addTest(qfeelapi('test_02')) sop = open("D:\reboot.html","wb")#生成报告的地址 runner = HTMLTestRunner(stream=sop,title="测试执行",description="用例执行情况详情") runner.run(suite)

    我的报告结果:

  • 相关阅读:
    图片不能显示
    Lambda表达式where过滤数据
    存储文本到一个文件里
    获取用户临时文件夹路径
    判断某一个字符串是否存在另一个字符串中
    使用反射为特性赋值
    字符串与数据流之间的转换
    控制台应用程序获取计算机名
    重复输出字符或字符串
    使用HashSet<>去除重复元素的集合
  • 原文地址:https://www.cnblogs.com/zhanghaoyang/p/10277147.html
Copyright © 2011-2022 走看看