feat: support websocket protocol

This commit is contained in:
buyuxiang
2022-04-21 20:53:11 +08:00
parent f7f0c5d2cf
commit 3588ab0f0a
18 changed files with 1205 additions and 36 deletions

View File

@@ -0,0 +1,146 @@
{
"config": {
"name": "run request with HTTP/1.1 and HTTP/2",
"base_url": "https://postman-echo.com"
},
"teststeps": [
{
"name": "HTTP/1.1 get",
"request": {
"method": "GET",
"url": "/get",
"params": {
"foo1": "foo1",
"foo2": "foo2"
},
"headers": {
"User-Agent": "HttpRunnerPlus"
}
},
"validate": [
{
"check": "status_code",
"assert": "equals",
"expect": 200,
"msg": "check status code"
},
{
"check": "proto",
"assert": "equals",
"expect": "HTTP/1.1",
"msg": "check protocol type"
},
{
"check": "body.args.foo1",
"assert": "length_equals",
"expect": 4,
"msg": "check param foo1"
}
]
},
{
"name": "HTTP/1.1 post",
"request": {
"method": "POST",
"url": "/post",
"headers": {
"User-Agent": "HttpRunnerPlus"
},
"body": {
"foo1": "foo1",
"foo2": "foo2"
}
},
"validate": [
{
"check": "status_code",
"assert": "equals",
"expect": 200,
"msg": "check status code"
},
{
"check": "proto",
"assert": "equals",
"expect": "HTTP/1.1",
"msg": "check protocol type"
},
{
"check": "body.json.foo1",
"assert": "length_equals",
"expect": 4,
"msg": "check body foo1"
}
]
},
{
"name": "HTTP/2 get",
"request": {
"method": "GET",
"url": "/get",
"http2": true,
"params": {
"foo1": "foo1",
"foo2": "foo2"
},
"headers": {
"User-Agent": "HttpRunnerPlus"
}
},
"validate": [
{
"check": "status_code",
"assert": "equals",
"expect": 200,
"msg": "check status code"
},
{
"check": "proto",
"assert": "equals",
"expect": "HTTP/2.0",
"msg": "check protocol type"
},
{
"check": "body.args.foo1",
"assert": "length_equals",
"expect": 4,
"msg": "check param foo1"
}
]
},
{
"name": "HTTP/2 post",
"request": {
"method": "POST",
"url": "/post",
"http2": true,
"headers": {
"User-Agent": "HttpRunnerPlus"
},
"body": {
"foo1": "foo1",
"foo2": "foo2"
}
},
"validate": [
{
"check": "status_code",
"assert": "equals",
"expect": 200,
"msg": "check status code"
},
{
"check": "proto",
"assert": "equals",
"expect": "HTTP/2.0",
"msg": "check protocol type"
},
{
"check": "body.json.foo1",
"assert": "length_equals",
"expect": 4,
"msg": "check body foo1"
}
]
}
]
}

View File

@@ -0,0 +1,145 @@
{
"config": {
"name": "run request with WebSocket protocol",
"base_url": "ws://echo.websocket.events",
"variables": {
"a": 12.3,
"b": 3.45,
"n": 5
}
},
"teststeps": [
{
"name": "open connection",
"websocket": {
"type": "open",
"url": "/",
"headers": {
"User-Agent": "HttpRunnerPlus"
}
},
"validate": [
{
"check": "status_code",
"assert": "equals",
"expect": 101,
"msg": "check open status code"
},
{
"check": "headers.Connection",
"assert": "equals",
"expect": "Upgrade",
"msg": "check headers"
}
]
},
{
"name": "ping pong test",
"websocket": {
"type": "ping",
"url": "/",
"timeout": 5000
}
},
{
"name": "read sponsor info",
"websocket": {
"type": "r",
"url": "/",
"timeout": 5000
},
"validate": [
{
"check": "body",
"assert": "contains",
"expect": "Lob.com",
"msg": "check sponsor message"
}
]
},
{
"name": "write json",
"websocket": {
"type": "w",
"url": "/",
"text": {
"foo1": "${gen_random_string($n)}",
"foo2": "${max($a, $b)}"
}
}
},
{
"name": "read json",
"websocket": {
"type": "r",
"url": "/"
},
"extract": {
"varFoo1": "body.foo1"
},
"validate": [
{
"check": "body.foo1",
"assert": "length_equals",
"expect": 5,
"msg": "check json foo1"
},
{
"check": "body.foo2",
"assert": "equals",
"expect": 12.3,
"msg": "check json foo2"
}
]
},
{
"name": "write and read text",
"websocket": {
"type": "wr",
"url": "/",
"text": "$varFoo1"
},
"validate": [
{
"check": "body",
"assert": "length_equals",
"expect": 5,
"msg": "check length equal"
}
]
},
{
"name": "write something redundant",
"websocket": {
"type": "w",
"url": "/",
"text": "have a nice day!"
}
},
{
"name": "write something redundant",
"websocket": {
"type": "w",
"url": "/",
"text": "balabala ..."
}
},
{
"name": "close connection",
"websocket": {
"type": "close",
"url": "/",
"close_status": 1000,
"timeout": 30000
},
"validate": [
{
"check": "status_code",
"assert": "equals",
"expect": 1000,
"msg": "check close status code"
}
]
}
]
}