websocket

复制代码
test_case.py
复制代码
import json

import pytest,allure
import websocket
@allure.epic("websocket")
@allure.feature("test")
class Testcase():
    def test_send(self,ws):
        # 发送消息并检查返回值
        data = {"source":"zhouzk_2_1701332591320","username":"zhouzk","id":"35b18c93-6318-4783-993d-b5f487932b03","cmdNames":["robotStatus"],"op":"subscribe_req","timeStamp":1701332591655,"payload":None}
        ws.send(json.dumps(data))
        result = ws.recv()
        print(result)
        #assert result == "Hello, World!"
复制代码
复制代码
conftest.py
#coding:utf-8
import pytest,websocket
def pytest_collection_modifyitems(items):
    """
    测试用例收集完成时,将收集到的item的name和nodeid 的中文显示在控制台上
    :return:
    """
    for item in items:
        item.name = item.name.encode("utf-8").decode("unicode_escape")
        print(item.nodeid)
        item._nodeid = item.nodeid.encode("utf-8").decode("unicode_escape")

@pytest.fixture(scope="module")
def ws():
    # 创建websocket连接
    try:
        ws = websocket.create_connection("ws://198.188.188.1:14048")
        print(ws)
        yield ws
        # 关闭连接
        ws.close()
    except Exception as e:
        print(e)
        pytest.exit()
相关推荐
网络安全许木几秒前
自学渗透测试第19天(ARP欺骗原理与Ettercap实战)
网络·web安全·渗透测试
Chengbei119 分钟前
业务视角下的金融SRC快速挖掘思路
网络·安全·web安全·网络安全·金融·系统安全·网络攻击模型
中科三方12 分钟前
SSL证书、域名与IP地址:三者关系全面解析与常见误区澄清
网络·tcp/ip·ssl
上海合宙LuatOS35 分钟前
LuatOS扩展库API——【httpplus】HTTP客户端
网络·物联网·网络协议·http·lua·luatos
@insist12341 分钟前
网络工程师-边界安全与远程接入实战(二):NAT 配置全解
网络·网络工程师·软考·软件水平考试
@insist12341 分钟前
网络工程师-智能流量管控实战(一):策略路由与路由策略精讲
网络·网络工程师·软考·软件水平考试
橙子也要努力变强1 小时前
信号的处理方式与生命周期(核心机制篇)
linux·网络·c++
Shingmc31 小时前
【Linux】Socket编程TCP
服务器·网络·tcp/ip
xixixi777771 小时前
Gartner 2026核心趋势:前置式主动安全(PCS)成为安全战略新范式,量子安全+国密算法构筑政企纵深防御底座
网络·人工智能·安全·web安全·ai·量子计算
胡志辉1 小时前
网络七层到底怎么落到一次前端请求上:从浏览器到网卡,再到远端服务器
前端·网络协议