首页 > 其他分享 >接口自动化项目落地之HTTPBin网站

接口自动化项目落地之HTTPBin网站

时间:2024-03-24 09:11:06浏览次数:32  
标签:zh en httpbin 落地 接口 env org HTTPBin response

接口自动化项目落地之HTTPBin网站

接口自动化项目落地系列

找个开源网站或开源项目,用tep实现整套pytest接口自动化项目落地,归档到电子书,作为tep完整教程项目篇一部分。自从tep完整教程发布以后,tep被越来越多小伙伴了解。教程只是纯理论,是骡子是马,拉出来遛遛才知道。做接口自动化项目落地,一方面是为了让自己脑海中的构想实实在在的呈现出来,现实和理想存在多少差距,不断尝试去弥补和修缮;另一方面也是方便读者朋友们学习使用,借助实际项目来练习,才能在赛道中弯道超车。

HTTPBin网站

httpbin.org是一个简单的在线提供HTTP服务的网站:

它能够用来对HTTP进行在线测试。

测试报告

HTTPBin网站的接口自动化项目包含11个用例集

67条测试用例

自动化执行正确率98.5%,其中有1条错误结果,是我故意为之的,因为想展示下断言失败的效果。

环境配置

包含http和https两套环境,因为HTTPBin支持HTTP&HTTPS:

fixtures/fixture_env_vars.py

#!/usr/bin/python
# encoding=utf-8

from tep.fixture import *

@pytest.fixture(scope="session")
def env_vars(config):
class Clazz(TepVars):
env = config["env"]

    <span class="token string">""</span><span class="token string">"变量定义开始"</span><span class="token string">""</span>
    # 环境变量
    mapping <span class="token operator">=</span> <span class="token punctuation">{</span>
        <span class="token string-property property">"http"</span><span class="token operator">:</span> <span class="token punctuation">{</span>  # http环境
            <span class="token string-property property">"domain"</span><span class="token operator">:</span> <span class="token string">"http://httpbin.org"</span><span class="token punctuation">,</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token string-property property">"https"</span><span class="token operator">:</span> <span class="token punctuation">{</span>  # https环境
            <span class="token string-property property">"domain"</span><span class="token operator">:</span> <span class="token string">"https://httpbin.org"</span><span class="token punctuation">,</span>
        <span class="token punctuation">}</span>
        # 继续添加
    <span class="token punctuation">}</span>
    # 定义类属性,敲代码时会自动补全
    domain <span class="token operator">=</span> mapping<span class="token punctuation">[</span>env<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">"domain"</span><span class="token punctuation">]</span>
    <span class="token string">""</span><span class="token string">"变量定义结束"</span><span class="token string">""</span>

<span class="token keyword">return</span> <span class="token function">Clazz</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><div class="developer-code-block-operation"><button class="developer-code-block-btn">复制</button></div></div><p>配置默认为http环境:</p><p><em style="font-style:italic">conf.yaml</em></p><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript" tabindex="0"><code class="language-javascript" style="margin-left:0"><span class="token literal-property property">env</span><span class="token operator">:</span> http<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><div class="developer-code-block-operation"><button class="developer-code-block-btn">复制</button></div></div><h2 id="abinr" name="%E7%94%A8%E4%BE%8B%E9%9B%86">用例集</h2><h3 id="3stc7" name="http-methods">http-methods</h3><figure class=""><div class="rno-markdown-img-url" style="text-align:center"><div class="rno-markdown-img-url-inner" style="width:47.45%"><div style="width:100%"><img src="https://ask.qcloudimg.com/http-save/yehe-5545582/9111469d89507106db3134d8945d1581.png"></div></div></div></figure><div class="developer-code-block"><pre class="prism-token token line-numbers language-javascript" tabindex="0"><code class="language-javascript" style="margin-left:0"><span class="token keyword">import</span> allure

from tep.client import request

@allure.title("get请求")
def test(env_vars):
# 描述
# 数据
# 请求
response = request(
"get",
url=env_vars.domain + "/get",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'accept': 'application/json',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Referer': 'http://httpbin.org/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'},
params={}
)
# 提取
# 断言
assert response.status_code < 400

auth

import allure
from tep.client import request

@allure.title("Authorization以Bearer开头,认证成功")
def test(env_vars):
# 描述
# http://httpbin.org/#/Auth/get_basic_auth__user___passwd_
# 数据
# 请求
response = request(
"get",
url=env_vars.domain + "/bearer",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'accept': 'application/json',
'Authorization': 'Bearer ZG9uZ2ZhbmdlcjoxMjM0NTY=', # 替换token
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Referer': 'http://httpbin.org/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'},
params={}
)
# 提取
# 断言
assert response.status_code < 400

status-codes

import allure
from tep.client import request

@allure.title("post返回状态码300")
def test(env_vars):
# 描述
# 数据
# 请求
response = request(
"post",
url=env_vars.domain + "/status/300",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'Content-Length': '0', 'accept': 'text/plain',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Origin': 'http://httpbin.org', 'Referer': 'http://httpbin.org/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Cookie': 'stale_after=never; fake=fake_value'},
json={}
)
# 提取
# 断言
assert response.status_code == 300

request_inspection

import allure
from tep.client import request

@allure.title("捕获请求信息--headers")
def test(env_vars):
# 描述
# 数据
# 请求
response = request(
"get",
url=env_vars.domain + "/headers",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'accept': 'application/json',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Referer': 'http://httpbin.org/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Cookie': 'stale_after=never; fake=fake_value'},
params={}
)
# 提取
# 断言
assert response.status_code < 400
assert response.json()["headers"]

response_inspection

import allure
from tep.client import request

@allure.title("捕获响应信息--缓存")
def test(env_vars):
# 描述
# 数据
# 请求
response = request(
"get",
url=env_vars.domain + "/cache",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'Cache-Control': 'max-age=0',
'accept': 'application/json', 'If-None-Match': '1', 'If-Modified-Since': '1',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Referer': 'http://httpbin.org/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Cookie': 'stale_after=never; fake=fake_value'},
params={}
)
# 提取
# 断言
assert response.status_code == 304

response_formats

import allure
from tep.client import request

@allure.title("txt文本text/plain")
def test(env_vars):
# 描述
# 数据
# 请求
response = request(
"get",
url=env_vars.domain + "/robots.txt",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'accept': 'text/plain',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Referer': 'http://httpbin.org/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Cookie': 'stale_after=never; fake=fake_value'},
params={}
)
# 提取
# 断言
assert response.status_code < 400
assert response.headers["content-type"] == "text/plain"

dynamic_data

import allure
from tep.client import request

@allure.title("base64解码")
def test(env_vars):
# 描述
# 数据
# 请求
response = request(
"get",
url=env_vars.domain + "/base64/SFRUUEJJTiBpcyBhd2Vzb21l",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'accept': 'text/html',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Referer': 'http://httpbin.org/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Cookie': 'stale_after=never; fake=fake_value'},
params={}
)
# 提取
# 断言
assert response.status_code < 400
assert "HTTPBIN is awesome" == response.text

cookies

import allure
from tep.client import request

@allure.title("cookies")
def test(env_vars):
# 描述
# 数据
# 请求
response = request(
"get",
url=env_vars.domain + "/cookies",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'accept': 'application/json',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Referer': 'http://httpbin.org/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Cookie': 'stale_after=never; fake=fake_value'},
params={}
)
# 提取
# 断言
assert response.status_code < 400
assert response.json()["cookies"]

images

import allure
from tep.client import request

@allure.title("图片")
def test(env_vars):
# 描述
# 数据
# 请求
response = request(
"get",
url=env_vars.domain + "/image",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'accept': 'image/webp',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Referer': 'http://httpbin.org/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Cookie': 'stale_after=never; fake=fake_value; freeform=3; name=dongfanger'},
params={}
)
# 提取
# 断言
assert response.status_code < 400

redirects

import allure
from tep.client import request

@allure.title("重定向")
def test(env_vars):
# 描述
# 数据
# 请求
response = request(
"get",
url=env_vars.domain + "/redirect/1",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'accept': 'text/html',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Referer': 'http://httpbin.org/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Cookie': 'stale_after=never; fake=fake_value; freeform=3; name=dongfanger'},
params={}
)
# 提取
# 断言
assert response.status_code == 404

anything

import allure
from tep.client import request

@allure.title("返回所有数据")
def test(env_vars):
# 描述
# 数据
# 请求
response = request(
"delete",
url=env_vars.domain + "/anything",
headers={'Host': 'httpbin.org', 'Proxy-Connection': 'keep-alive', 'accept': 'application/json',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36',
'Origin': '', 'Referer': '/', 'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
'Cookie': 'stale_after=never; fake=fake_value; freeform=3; name=dongfanger'},
json={}
)
# 提取
# 断言
assert response.status_code < 400

# 描述
# 数据
# 请求
response <span class="token operator">=</span> <span class="token function">request</span><span class="token punctuation">(</span>
    <span class="token string">"get"</span><span class="token punctuation">,</span>
    url<span class="token operator">=</span>env_vars<span class="token punctuation">.</span>domain <span class="token operator">+</span> <span class="token string">"/anything"</span><span class="token punctuation">,</span>
    headers<span class="token operator">=</span><span class="token punctuation">{</span><span class="token string-property property">'Host'</span><span class="token operator">:</span> <span class="token string">'httpbin.org'</span><span class="token punctuation">,</span> <span class="token string-property property">'Proxy-Connection'</span><span class="token operator">:</span> <span class="token string">'keep-alive'</span><span class="token punctuation">,</span> <span class="token string-property property">'accept'</span><span class="token operator">:</span> <span class="token string">'application/json'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'User-Agent'</span><span class="token operator">:</span> <span class="token string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Referer'</span><span class="token operator">:</span> <span class="token string">'/'</span><span class="token punctuation">,</span> <span class="token string-property property">'Accept-Encoding'</span><span class="token operator">:</span> <span class="token string">'gzip, deflate'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Accept-Language'</span><span class="token operator">:</span> <span class="token string">'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Cookie'</span><span class="token operator">:</span> <span class="token string">'stale_after=never; fake=fake_value; freeform=3; name=dongfanger'</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    params<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">)</span>
# 提取
# 断言
assert response<span class="token punctuation">.</span>status_code <span class="token operator">&lt;</span> <span class="token number">400</span>

# 描述
# 数据
# 请求
response <span class="token operator">=</span> <span class="token function">request</span><span class="token punctuation">(</span>
    <span class="token string">"patch"</span><span class="token punctuation">,</span>
    url<span class="token operator">=</span>env_vars<span class="token punctuation">.</span>domain <span class="token operator">+</span> <span class="token string">"/anything"</span><span class="token punctuation">,</span>
    headers<span class="token operator">=</span><span class="token punctuation">{</span><span class="token string-property property">'Host'</span><span class="token operator">:</span> <span class="token string">'httpbin.org'</span><span class="token punctuation">,</span> <span class="token string-property property">'Proxy-Connection'</span><span class="token operator">:</span> <span class="token string">'keep-alive'</span><span class="token punctuation">,</span> <span class="token string-property property">'accept'</span><span class="token operator">:</span> <span class="token string">'application/json'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'User-Agent'</span><span class="token operator">:</span> <span class="token string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Origin'</span><span class="token operator">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string-property property">'Referer'</span><span class="token operator">:</span> <span class="token string">'/'</span><span class="token punctuation">,</span> <span class="token string-property property">'Accept-Encoding'</span><span class="token operator">:</span> <span class="token string">'gzip, deflate'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Accept-Language'</span><span class="token operator">:</span> <span class="token string">'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Cookie'</span><span class="token operator">:</span> <span class="token string">'stale_after=never; fake=fake_value; freeform=3; name=dongfanger'</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    json<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">)</span>
# 提取
# 断言
assert response<span class="token punctuation">.</span>status_code <span class="token operator">&lt;</span> <span class="token number">400</span>

# 描述
# 数据
# 请求
response <span class="token operator">=</span> <span class="token function">request</span><span class="token punctuation">(</span>
    <span class="token string">"post"</span><span class="token punctuation">,</span>
    url<span class="token operator">=</span>env_vars<span class="token punctuation">.</span>domain <span class="token operator">+</span> <span class="token string">"/anything"</span><span class="token punctuation">,</span>
    headers<span class="token operator">=</span><span class="token punctuation">{</span><span class="token string-property property">'Host'</span><span class="token operator">:</span> <span class="token string">'httpbin.org'</span><span class="token punctuation">,</span> <span class="token string-property property">'Proxy-Connection'</span><span class="token operator">:</span> <span class="token string">'keep-alive'</span><span class="token punctuation">,</span> <span class="token string-property property">'Content-Length'</span><span class="token operator">:</span> <span class="token string">'0'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'accept'</span><span class="token operator">:</span> <span class="token string">'application/json'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'User-Agent'</span><span class="token operator">:</span> <span class="token string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Origin'</span><span class="token operator">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string-property property">'Referer'</span><span class="token operator">:</span> <span class="token string">'/'</span><span class="token punctuation">,</span> <span class="token string-property property">'Accept-Encoding'</span><span class="token operator">:</span> <span class="token string">'gzip, deflate'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Accept-Language'</span><span class="token operator">:</span> <span class="token string">'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Cookie'</span><span class="token operator">:</span> <span class="token string">'stale_after=never; fake=fake_value; freeform=3; name=dongfanger'</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    json<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">)</span>
# 提取
# 断言
assert response<span class="token punctuation">.</span>status_code <span class="token operator">&lt;</span> <span class="token number">400</span>

# 描述
# 数据
# 请求
response <span class="token operator">=</span> <span class="token function">request</span><span class="token punctuation">(</span>
    <span class="token string">"put"</span><span class="token punctuation">,</span>
    url<span class="token operator">=</span>env_vars<span class="token punctuation">.</span>domain <span class="token operator">+</span> <span class="token string">"/anything"</span><span class="token punctuation">,</span>
    headers<span class="token operator">=</span><span class="token punctuation">{</span><span class="token string-property property">'Host'</span><span class="token operator">:</span> <span class="token string">'httpbin.org'</span><span class="token punctuation">,</span> <span class="token string-property property">'Proxy-Connection'</span><span class="token operator">:</span> <span class="token string">'keep-alive'</span><span class="token punctuation">,</span> <span class="token string-property property">'Content-Length'</span><span class="token operator">:</span> <span class="token string">'0'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'accept'</span><span class="token operator">:</span> <span class="token string">'application/json'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'User-Agent'</span><span class="token operator">:</span> <span class="token string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Origin'</span><span class="token operator">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string-property property">'Referer'</span><span class="token operator">:</span> <span class="token string">'/'</span><span class="token punctuation">,</span> <span class="token string-property property">'Accept-Encoding'</span><span class="token operator">:</span> <span class="token string">'gzip, deflate'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Accept-Language'</span><span class="token operator">:</span> <span class="token string">'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'</span><span class="token punctuation">,</span>
             <span class="token string-property property">'Cookie'</span><span class="token operator">:</span> <span class="token string">'stale_after=never; fake=fake_value; freeform=3; name=dongfanger'</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
    json<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">)</span>
# 提取
# 断言
assert response<span class="token punctuation">.</span>status_code <span class="token operator">&lt;</span> <span class="token number">400</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><div class="developer-code-block-operation"><button class="developer-code-block-btn">复制</button></div></div><h2 id="8gi40" name="%E5%8F%AA%E8%8A%B1%E4%BA%863%E5%B0%8F%E6%97%B6%E5%AE%8C%E6%88%90">只花了3小时完成</h2><p>通过mitmproxy来录制流量自动生成用例,效率得到了极大的提高,从原来的1天缩短到3小时就完成了整个项目落地。相比于手工编写用例,这次写HTTPBin的接口自动化,我使用了<code>utils/mitm.py</code>来录制流量,mitmproxy稍微不方便的是需要手动开启代理,不过适应了以后还是能接受。录制流量后就会生成自动化用例,但是还需要二次修改,才会变成最终的用例。主要修改的工作量是在添加断言,根据业务设置合理的断言。其次是替换url为<code>env_vars.domain + "/api"</code>拼接方式,直接批量Replace即可。然后就是修改文件名和<code>@allure.title</code>了,给用例加上标题。工欲善其事,必先利其器。</p><h2 id="cv25e" name="tep%E5%85%B1%E5%BB%BA">tep共建</h2><p>欢迎添加微信:<strong>cekaigang</strong>,分享交流tep实践案例,可以提供开源项目我来写,也可以写好后发我一起看看,优秀的项目会添加到tep完整教程的项目篇,以便更多测试同行们借鉴,大佬们赶快来加入我们吧。</p><blockquote><p> 参考资料:

HTTPBin接口自动化项目源码 https://github.com/dongfanger/httpbin
postman https://www.postman.com/postman/workspace/httpbin/collection/


原文链接:https://cloud.tencent.com/developer/article/1997535

标签:zh,en,httpbin,落地,接口,env,org,HTTPBin,response
From: https://www.cnblogs.com/sunny3158/p/18092076

相关文章

  • JAVA面向对象高级二:接口:认识接口,接口的好处
    1.接口: packagecom.itheima.接口;publicinterfacea{//接口中不能有构造器也不能有代码块,不能创建对象//成员变量(默认为常量)大写比较官方StringschoolName="黑马程序员";voidtest();//在接口中成员方法(默认为抽象方法)}     2.接......
  • 等两个异步请求结束之后再请求接口
    importrequestfrom'@/utils/request.js'import{headerEncrypt,paramEncrypt}from'@/utils/bridge.js'asyncfunctionEncryptProcess(obj1,obj2){letdata={'param1':{'param':''},'param2......
  • Postman接口判断写法
    1.请求结果固定若是请求结果固定时使用pm.test("自定义名字",function(){pm.expect(数据字段).equal("预期结果")})传过来的数据必须和预期结果相同才可以通过.2.请求结果半固定若是请求结果半固定时使用pm.test("自定义名字",function(){pm.exp......
  • 实时汇率API查询接口接入方法:支持逐笔报价、批量订阅、历史日K线、周K、月K
    在进行量化回测时,确实需要支持逐笔报价、批量订阅、以及获取历史日K线、周K线、月K线等功能,这些功能对于编写有效的交易策略和分析市场数据至关重要。一般来说,在进行量化回测时,我们可以选择使用专业的量化交易平台或软件,这些平台通常会提供相应的API接口来支持逐笔报价、批量订阅......
  • .Net 8.0 下的新RPC,IceRPC之接口定义语言 [Slice] VS [Protobuf]
    作者引言很高兴啊,我们来到了接口定义语言(IDL)篇,RPC之基石,有了它,可以在各种各种语言中实现RPC通讯。Slice和Protobuf是什么?IceRPC的核心是一个面向字节bytes的RPC框架:它可以轻松地发送携带字节的请求requests,并接收携带更多字节的响应responses.IceRPC以字节为中心......
  • jmeter 多接口之间,token连接
    接口名称接口类型URL参数    银行登录接口2(token)POST/pinter/bank/api/login2userName=admin&password=1234    银行余额查询接口(token)GET/pinter/bank/api/query2userName=admin接口一:登录接口,post请求,url地址:/pinter/bank/api/login2,参......
  • 解读国内首家AI Agent公测背后的商业落地路径
    随着大语言模型技术的日益成熟,国内科技巨头纷纷加快在AI Agent领域的布局和应用落地。凭借自身强大的技术积累和丰富的应用场景,推动AI Agent技术在各行各业的深度融合与创新应用。在AI Agent的落地应用上,目前科技巨头正借助已有AI技术平台集体发力,众多创业公司也在拼命......
  • 解读国内首家AI Agent公测背后的商业落地路径
     随着大语言模型技术的日益成熟,国内科技巨头纷纷加快在AIAgent领域的布局和应用落地。凭借自身强大的技术积累和丰富的应用场景,推动AIAgent技术在各行各业的深度融合与创新应用。在AIAgent的落地应用上,目前科技巨头正借助已有AI技术平台集体发力,众多创业公司也在拼命迎头......
  • API接口开发规范
    API接口是不同软件系统之间进行通信的重要方式,良好的API接口设计规范可以提高系统的可维护性、可扩展性和易用性。本文介绍了一套详细的API接口开发规范,包括命名规范、请求和响应规范、安全规范等内容,旨在帮助开发团队统一规范API接口的设计和实现。一、命名规范URL命名规范使......
  • Java抽象类和接口详解
    1.抽象类的概念和语法实现 当一个类中的信息不足以描述一个具体的对象的时候,我们可以将这个类定义为抽象类。那么我们怎么定义出一个抽象类呢?我们要采用一个关键字abstract。下面我们来看具体代码:abstractclassAnimal{publicStringname;publicintage;......