A文件(登录取token被引用文件):
# NOTE: Generated By HttpRunner v3.1.8
# FROM: har\.\login.har
import allure
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
class TestCaseLogin(HttpRunner):
config = Config("testcase description").verify(False)
teststeps = [
Step(RunRequest("/adminapi/login").post("http://不方便展示/adminapi/login").with_headers(
**{'Host': '不方便展示', 'Content-Length': '49', 'Accept': 'application/json, text/plain, */*',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Edg/99.0.1150.55',
'Content-Type': 'application/json;charset=UTF-8', 'Origin': 'http://不方便展示',
'Referer': 'http://不方便展示/admin/login', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cookie': 'WS_ADMIN_URL=ws://不方便展示/notice; WS_CHAT_URL=ws://不方便展示/msg; collapsed=false; think_lang=zh-cn; PHPSESSID=ec012172dbb8925955ddf54ba37a38d5',
'Connection': 'keep-alive'}).with_cookies(
**{'WS_ADMIN_URL': 'ws://不方便展示/notice', 'WS_CHAT_URL': 'ws://不方便展示/msg',
'collapsed': 'false', 'think_lang': 'zh-cn', 'PHPSESSID': 'ec012172dbb8925955ddf54ba37a38d5'}).with_json(
{'account': '***', 'pwd': '***', 'imgcode': '22'})
.extract().with_jmespath("body.data.token","token").validate().assert_equal("status_code",
200).assert_equal(
'headers."Content-Type"', "application/json; charset=utf-8").assert_equal("body.status", 200).assert_equal(
"body.msg", "ok")),
]
if __name__ == "__main__":
TestCaseLogin().test_start()
如果想练习去gitee找个开源
B文件:
# NOTE: Generated By HttpRunner v3.1.8
# FROM: har\.\test_hs.har
import allure
from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
from homework.httprunner.test_crmeb.testcases.login_test import TestCaseLogin as login
class TestCaseTestHs(HttpRunner):
config = Config("testcase description").verify(False)
teststeps = [
Step(
RunTestCase("login")
.call(login)
.export("token") #todo:此处引用
),
Step(
RunRequest("/adminapi/app/wechat/speechcraft").post(
"http://null/adminapi/app/wechat/speechcraft").with_headers(
**{'Host': 'null', 'Content-Length': '64',
'Accept': 'application/json, text/plain, */*',
'Authori-zation': 'Bearer ' + '$token',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Edg/99.0.1150.55',
'Content-Type': 'application/json;charset=UTF-8', 'Origin': 'http://null',
'Referer': 'http://null/admin/setting/store_service/speechcraft',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cookie': 'WS_ADMIN_URL=ws://null/notice; WS_CHAT_URL=ws://null/msg; collapsed=false; think_lang=zh-cn; PHPSESSID=ec012172dbb8925955ddf54ba37a38d5; uuid=1; token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxMzkuMTU5LjIzMy4xMjk6ODg5OSIsImF1ZCI6IjEzOS4xNTkuMjMzLjEyOTo4ODk5IiwiaWF0IjoxNjQ4ODA2MDM2LCJuYmYiOjE2NDg4MDYwMzYsImV4cCI6MTY1MTM5ODAzNiwianRpIjp7ImlkIjoxLCJ0eXBlIjoiYWRtaW4ifX0.Y7Z0vWbzo8JWLy-Ysolyj20HFmyqsVWlXLmEdRld0YI; expires_time=1651398036',
'Connection': 'keep-alive'}).with_cookies(
**{'WS_ADMIN_URL': 'ws://null/notice', 'WS_CHAT_URL': 'ws://null/msg',
'collapsed': 'false', 'think_lang': 'zh-cn', 'PHPSESSID': 'ec012172dbb8925955ddf54ba37a38d5',
'uuid': '1',
'token': '$token',
'expires_time': '1651398036'}).with_json(
{'cate_id': '', 'title': "${cid(b)}", 'message': 'test33', 'sort': 0}).validate().assert_equal(
"status_code", 200).assert_equal('headers."Content-Type"',
"application/json; charset=utf-8").assert_equal(
"body.status", 200).assert_equal("body.msg", "创建话术成功")),
Step(RunRequest("/adminapi/app/wechat/speechcraft/"+"${cid(a)}").delete(
"http://null/adminapi/app/wechat/speechcraft/"+"${cid(a)}").with_headers(
**{'Host': 'null', 'Content-Length': '0', 'Accept': 'application/json, text/plain, */*',
'Authori-zation': 'Bearer '+'$token',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Edg/99.0.1150.55',
'Content-Type': 'text/plain;charset=UTF-8', 'Origin': 'http://null',
'Referer': 'http://null/admin/setting/store_service/speechcraft',
'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cookie': 'WS_ADMIN_URL=ws://null/notice; WS_CHAT_URL=ws://null/msg; collapsed=false; think_lang=zh-cn; PHPSESSID=ec012172dbb8925955ddf54ba37a38d5; uuid=1; token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxMzkuMTU5LjIzMy4xMjk6ODg5OSIsImF1ZCI6IjEzOS4xNTkuMjMzLjEyOTo4ODk5IiwiaWF0IjoxNjQ4ODA2MDM2LCJuYmYiOjE2NDg4MDYwMzYsImV4cCI6MTY1MTM5ODAzNiwianRpIjp7ImlkIjoxLCJ0eXBlIjoiYWRtaW4ifX0.Y7Z0vWbzo8JWLy-Ysolyj20HFmyqsVWlXLmEdRld0YI; expires_time=1651398036',
'Connection': 'keep-alive'}).with_cookies(
**{'WS_ADMIN_URL': 'ws://null/notice', 'WS_CHAT_URL': 'ws://null/msg',
'collapsed': 'false', 'think_lang': 'zh-cn', 'PHPSESSID': 'ec012172dbb8925955ddf54ba37a38d5',
'uuid': '1',
'token': '$token',
'expires_time': '1651398036'}).validate().assert_equal("status_code", 200).assert_equal(
'headers."Content-Type"', "application/json; charset=utf-8").assert_equal("body.status", 200).assert_equal(
"body.msg", "删除成功")),
]
if __name__ == "__main__":
TestCaseTestHs().test_start()
B文件有debugtalk方法,不要过分解读