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 天前
BGP 高防 IP 与 CDN 混合部署:攻防场景选型实战指南
网络·网络协议·tcp/ip
Shingmc31 天前
【Linux】多路转接之select
linux·网络
溜达的大象1 天前
从到处找资源到统一检索:飞牛NAS部署Pansou实战记录
网络·云计算
2401_868534781 天前
园区网设计
网络
宋浮檀s1 天前
春秋云镜——CVE-2020-25540
网络·安全·web安全
天天进步20151 天前
Tunnelto 源码解析 #4:Wormhole 控制通道:WebSocket 如何建立一条“隧道控制线”
网络·websocket·网络协议
xiaofeichaichai1 天前
网络与跨域
前端·网络
Latticy1 天前
内网渗透-Windows RDP凭证的抓取和密码破解
网络·安全·网络安全·内网渗透·内网
Forget_85501 天前
HCIA——计算机网络诞生与发展
服务器·网络·计算机网络
志栋智能1 天前
超自动化巡检:降低运维总成本(TCO)的有效路径
大数据·运维·网络·人工智能·自动化