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()
相关推荐
树℡独2 小时前
ns-3仿真之应用层(五)
服务器·网络·tcp/ip·ns3
zhang133830890753 小时前
CG-09H 超声波风速风向传感器 加热型 ABS材质 重量轻 没有机械部件
大数据·运维·网络·人工智能·自动化
津津有味道4 小时前
易语言TCP服务端接收刷卡数据并向客户端读卡器发送指令
服务器·网络协议·tcp·易语言
酣大智5 小时前
接口模式参数
运维·网络·网络协议·tcp/ip
Genie cloud5 小时前
1Panel SSL证书申请完整教程
服务器·网络协议·云计算·ssl
24zhgjx-lxq5 小时前
华为ensp:MSTP
网络·安全·华为·hcip·ensp
ling___xi5 小时前
《计算机网络》计网3小时期末速成课各版本教程都可用谢稀仁湖科大版都可用_哔哩哔哩_bilibili(笔记)
网络·笔记·计算机网络
REDcker6 小时前
Linux 文件描述符与 Socket 选项操作详解
linux·运维·网络
Up九五小庞6 小时前
用arpspoof实现100%批量切断192.168.110.10 - 192.168.110.100 断网(双向欺骗)--九五小庞
网络·开源
躺柒6 小时前
读数字时代的网络风险管理:策略、计划与执行04风险指引体系
大数据·网络·信息安全·数字化·网络管理·网络风险管理