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()
相关推荐
sun00770011 分钟前
高德等应用走私有apn网络
网络
XR12345678821 分钟前
连锁多分支办公网络怎么选?统一运维与快速开局是关键
运维·网络·php
zr5268554471 小时前
光电交换机-三格电子
运维·服务器·网络
huainingning1 小时前
华为oceanstor5310存储单机设备配置
运维·服务器·网络
云絮.2 小时前
网络原理 - UDP
服务器·网络·tcp/ip
xiaoye-duck2 小时前
《Linux 网络编程》应用层自定义协议(一):序列化、sk_buff 与粘包半包处理
linux·网络
专家大圣2 小时前
给自己搭一个 PDF 工具站:Stirling-PDF 部署、格式转换与远程访问实战
网络·pdf·内网穿透
rcms152702692182 小时前
Advanced Energy 27-368299-00 射频发生器
网络
张小姐的猫2 小时前
【Linux】网络编程 —— 手动部署 & 测试内网穿透
linux·运维·服务器·网络·tcp/ip
有续技术2 小时前
工业网关接入 PLC,为什么要先整理点表?
运维·网络·数据库