Postman performs Websocket interface testing

Recently, I need to test the websocket interface in my work. I have been using Postman as a short-connection contract sending tool such as http requests. Now I find that Postman v8.5 or above supports websocket. I will record it here.

First New a WebSocket Request

In the WebSocket API, the browser and the server only need to complete a handshake, and a persistent connection can be created directly between the two for bidirectional data transmission.

Enter the WebSocket API URL in Postman, click connect to establish a connection, and you can seamlessly send and receive messages.

Text plain text can be sent, with syntax highlighting and automatic formatting if the data format is JSON and XML, and raw ArrayBuffer messages can be written.


Timeout will prompt that the connection has been disconnected

The data sent and received will be displayed in order below


Historical functions:

You can also revisit previous WebSocket sessions in the History section of the Postman sidebar. Not only can you view messages from historical conversations, but you can also reuse the same API.

Insert image description here
Additional : (When I learned about the websockt protocol before, I used Python to simulate a simple communication process between the websocket client and the server, and monitored the number of handles occupied by the process and the network connection on the server)

Server:

#! python3
# SocketTestClient
# -*- coding:utf-8 -*-
 
import socket
import os
import subprocess
import time
 
host = '0.0.0.0'
port = 9918
 
host = socket.gethostname()
print('客户端host = ',host)
print("客户端请求PID = %i" % (os.getpid(),))
obj = socket.socket()
obj.connect((host, port))
print('netstat -nlp | grep %s' % port)
os.system('netstat -nlp | grep %s' % port)
j = 0
while True:
    obj.send(bytes("这是客户端第 %s 条消息! " % j, encoding="utf-8"))
    #time.sleep(5)
    j = j + 1
    print("发送了 %s 条!" %j)
    if j == 5:
        obj.send(bytes("End", encoding="utf-8"))
        ret = str(obj.recv(1024), encoding="utf-8")
        print('ret = ',ret)
        if ret == 'Finish!':
            obj.close()
            break
    else:
        continue

Client:

#! python3
# SocketTest.py
# -*- coding:utf-8 -*-
 
 
import socket
import os
import time
 
 
def socketTest():
    while True:
        ret = str(conn.recv(1024), encoding="utf-8")
        print(ret)
        if 'End' in ret:
            print('连接结束-End')
            print('---------------------------------')
            conn.sendall(bytes("收到断开连接信息-End!", encoding="utf-8"))
            conn.close()
            sk.close #不发送fin包
            conn.sendall(bytes("我再发!", encoding="utf-8"))
            conn.sendall(bytes("我再发!", encoding="utf-8"))
            os.system('netstat -nlp | grep %s' % port)
            break
        else:
            print('Not close')
            continue
 
 
if __name__ == '__main__':
    while True:
        host = '0.0.0.0'
        port = 9918
 
        host = socket.gethostname()
        print(host)
        print("PID = %i" % (os.getpid(),))
 
        sk = socket.socket()
        sk.bind((host, port))
        sk.listen(60)
        # sk.settimeout(10)
        print('端口监听中...')
        os.system("netstat -nlp|grep :%i" % (port,))
        print('客户端返回连接信息')
        conn, address = sk.accept()
        print('连接中...')
        print('连接来自: ', address)
        print('---------------------------------')
        print("lsof -p %i" % (os.getpid(),))
        os.system("lsof -p %i" % (os.getpid(),))
        print('---------------------------------')
        print('netstat -nlp | grep %s' % port)
        os.system('netstat -nlp | grep %s' % port)
        print('---------------------------------')
        print('ls /proc/%i/fd |wc -l '% (os.getpid(),))
        os.system('ls /proc/%i/fd |wc -l '% (os.getpid(),))
        #socketTest()

Finally, I would like to share with you some of my learning materials:

The above content should be the most comprehensive and complete preparation warehouse for software testing friends. In order to better organize each module, I also referred to many high-quality blog posts on the Internet. and projects, trying not to miss every knowledge point. Many friends relied on these contents to review and got offers from major manufacturers such as BATJ. This warehouse has also helped many software testing learners. I hope it can also help you. .

Follow my WeChat official account below to get it for free! ↓ ↓ ↓ ↓ ↓

Guess you like

Origin blog.csdn.net/weixin_56331124/article/details/132715027