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()
相关推荐
上海云盾-高防顾问6 小时前
中小企业低成本渗透测试实操指南
网络协议·web安全·网络安全
猿小路6 小时前
抓包工具-Wireshark
网络·测试工具·wireshark
Rabbit_QL6 小时前
【网络设置】Docker 自定义网络深度解析:从踩坑到工程实践
网络·docker·容器
浩子智控8 小时前
电子产品三防设计
网络·系统安全
我要升天!8 小时前
Linux中《网络基础》
linux·运维·网络
安科瑞刘鸿鹏179 小时前
工业自动化系统中抗晃电保护的协同控制研究
运维·网络·嵌入式硬件·物联网
ZStack开发者社区9 小时前
ZStack Cloud 5.5.0正式发布
运维·服务器·网络
2501_945837439 小时前
云服务器的防护体系构建之道
网络·安全
徐*红9 小时前
物理层-传输介质:双绞线,同轴电缆,光纤,无线传输介质
网络
yuanmenghao11 小时前
CAN系列 — (6) CAN FD 带宽、CPU、中断:工程上是如何一起算的?
网络·驱动开发·单片机·mcu·自动驾驶·信息与通信