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()
相关推荐
明月_清风1 天前
开发者网络概念全扫盲:一篇搞定
后端·网络协议
刘马想放假2 天前
Modbus 全栈技术解析:TCP、RTU、ASCII、RTU over TCP
数据结构·网络协议
王二端茶倒水3 天前
一套可落地的无线运营方案,不能只管 AP,还要管用户、计费和运维
网络协议
162723816083 天前
EtherCAT 分布式时钟(DC)原理与配置实战:把多轴真正"对齐到同一时刻"
网络协议
王二端茶倒水3 天前
宽带无线项目,怎么从一次性交付变成长期运营收入?
网络协议
用户2530171996274 天前
第6篇:从技术到产品 — Ghost Proxifier 的设计哲学
网络协议
用户2530171996274 天前
第3篇:注入的艺术 — Ghost Proxifier 核心架构拆解
网络协议
王二端茶倒水6 天前
商业 WiFi 不是免费上网,而是门店数字化的入口
网络协议
网络研究院10 天前
2026年网络安全
网络·安全·法律·法规·趋势·发展