3 Star 28 Fork 6

pojol / gobot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

gobot

Gobot是一个功能强大的有状态API测试机器人。它提供图形界面进行测试场景的搭建,可以方便的进行测试脚本编写、单步调试和压力测试,并可以在测试过程的每个阶段之间共享和存储状态。

Go Report Card CI

快速安装

  1. 进入最新的 release页面 下载可执行程序
  2. 执行 gobot_driver_win_x64_v0.3.8 目录中的 start.bat 文件, 运行服务器
  3. 执行 gobot_editor_win_x64_v0.3.8 目录中的 gobot.exe, 运行编辑器程序
  4. 在弹出的地址输入窗口 或 config 页的地址栏中填入 http://127.0.0.1:8888 本地服务器地址

特性

  • 使用行为树控制机器人的运行逻辑,使用脚本控制节点的具体行为(比如发起一次http请求
  • 提供图形化的编辑,调试能力
  • 可以预制模版节点,在编辑器中直接使用预制过的节点(可通过标签筛选
  • 可以通过 http api 'curl post /bot.run -d '{"Name":"某个机器人"}' 驱动一个阻塞式的机器人,通过这种方式可以方便的集成进CI中的测试流程
  • 支持多种协议格式(HTTP, TCP, WebSocket ... ,且支持在脚本层自行对字节流 pack/unpack
  • 可以进行压力测试(可以在配置页设置不同的并发策略
  • 提供压力测试后的API/协议报告查看

节点脚本

通过内置的模块+脚本可以使我们拥有丰富的逻辑表达能力,也可以使用全局的(单个bot)meta 结构来维护 bot 的各种状态变更

--[[
    每个节点都拥有一个独立属于自己的 .lua 脚本,当节点被执行到的时候会调用 dostring 加载并运行这个脚本
]]--

-- 用户可以在脚本中加载自己想要使用的 “模块”
-- document https://pojol.gitee.io/gobot/#/zh-cn/script/meta
local http = require("http")

-- 定义一些逻辑所需的结构
req = {
    body = {},       -- post body
    timeout = "10s", -- http timeout  
    headers = {},    -- http headers
}

-- 当脚本成功加载后,会调用这个 execute 函数
function execute()

    -- 用户可以在这里自行定义节点的执行逻辑(例如发送一次http请求
    res, err = http.post("url", req)
    
    -- todo
    
    -- 返回值
    --  state 状态码
    --  res 显示在 Response 面板的信息
    return state.Succ, res
end

脚本层模块

Module interface Description
base64 encode decode Provides base64 encoding/decoding functionality.
http post get put Support HTTP connection.
tcp dail close write read Support TCP connection.
websocket dail close write read Support WebSocket connection.
protobuf marshal unmarshal Provides Protobuf operations.
mongoDB insert find update delete ... Provides MongoDB operations.
json encode decode Offers JSON functionalities.
md5 sum Calculates MD5 hashes.
utils uuid random Generates random values, UUIDs.
... More modules available.

解析流式协议包

示例 message.lua 位于 script/ 用户可以参考里面的实现,更改自己项目中的协议包解析方式

-- message.lua
function TCPUnpackMsg(msglen, buf, errmsg)
    if errmsg ~= "nil" then
        return 0, ""
    end

    local msg = message.new(buf, ByteOrder, 0)

    local msgTy = msg:readi1()
    local msgCustom = msg:readi2()
    local msgId = msg:readi2()
    local msgbody = msg:readBytes(msglen-(2+1+2+2), -1)

    return msgId, msgbody

end

function TCPPackMsg(msgid, msgbody)
    local msglen = #msgbody+2+1+2+2

    local msg = message.new("", ByteOrder, msglen)
    msg:writei2(msglen)
    msg:writei1(1)
    msg:writei2(0)
    msg:writei2(msgid)
    msg:writeBytes(msgbody)

    return msg:pack()

end

-- use
--------------------------------------------------------
-- 使用 proto.marshal 序列化
-- 使用 TCPPackMsg 组装 TCP 报文
local reqbody, errmsg = proto.marshal("HelloReq", json.encode({
    Message = "hello",
}))
ret = conn.write(TCPPackMsg(1002, reqbody))

--------------------------------------------------------
-- 2 是 message length 的设计字节长度,conn会首先尝试读取指定的字节数用于解析报文大小
-- 通过 msgid 解析协议报文内容
-- TCPUnpackMsg 用户可以自行定义,不一定按 msgid, msgbody 的形式返回,也可以是 msghead, msgbody 看用户的报文结构设计
msgid, msgbody = TCPUnpackMsg(conn.read(2))
if msgid == 1002 then
    body = proto.unmarshal("HelloRes", msgbody)
end

在线试用 <-- 点击试用

驱动端地址 http://47.120.59.203:8888 (弹出窗口填写

文档

视频演示

编辑器预览

image.png

MIT License Copyright (c) 2021 pojol Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

有状态的测试机器人 展开 收起
取消

发行版 (2)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/pojol/gobot.git
git@gitee.com:pojol/gobot.git
pojol
gobot
gobot
develop

搜索帮助