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)

    我的报告结果:

  • 相关阅读:
    [adminitrative][archlinux][setfont] 设置console的字体大小
    [daily][archlinux][rsync] rsync
    [skill][msgpack] 初试msgpack库以及基本使用
    AWS之搭建深度学习主机
    AWS之SSH登录:使用 PuTTY 从 Windows 连接到 Linux 实例
    加拿大大学排名 by USNews
    Python多进程vs多线程
    Python之JSON使用
    Python之模块与包
    Android重打包+重新签名工具Apktool Box
  • 原文地址:https://www.cnblogs.com/zhanghaoyang/p/10277147.html
Copyright © 2011-2022 走看看