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()
相关推荐
海拥✘9 小时前
深入理解 IP 地址:概念、分类与日常应用
网络·网络协议·tcp/ip
Miracle&9 小时前
1.TCP/IP模型:各层协议(重点TCP/UDP)
网络协议·tcp/ip·udp
Miracle&9 小时前
2.TCP深度解析:握手、挥手、状态机、流量与拥塞控制
linux·网络·tcp/ip
liulilittle10 小时前
IP校验和算法:从网络协议到SIMD深度优化
网络·c++·网络协议·tcp/ip·算法·ip·通信
c&0xff0010 小时前
Flink反压问题
网络·flink
7ACE10 小时前
Wireshark TS | 接收数据超出接收窗口
网络协议·tcp/ip·wireshark
深圳多奥智能一卡(码、脸)通系统11 小时前
基于多奥(DAIC)品牌的IC卡电梯门禁系统(梯控)基础配置清单,整合核心硬件、软件及安全组件,确保系统可独立运行并支持未来扩展
网络
googleccsdn11 小时前
ESNP LAB 笔记:配置MPLS(Part4)
网络·笔记·网络协议
tan180°11 小时前
Boost搜索引擎 网络库与前端(4)
linux·网络·c++·搜索引擎
Dontla12 小时前
Docker多共享网络配置策略(Docker多网络、Docker networks、Docker Compose网络、Docker网络、Docker共享网络)
网络·docker·容器