Skip to content

Commit

Permalink
Merge branch 'release/v0.3.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
pojol committed Dec 19, 2023
2 parents aabd666 + 7540a5f commit 63f1fc0
Show file tree
Hide file tree
Showing 42 changed files with 3,811 additions and 280 deletions.
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ Gobot is a powerful stateful API testing robot. It provides a graphical interfac

## Feature

* Use the `behavior tree` to control the running order of the robot, and use the `script` to control the specific behavior of the node (such as making an http request
* SuProvides graphical editing and debugging capabilities
* You can `prefab` template nodes in the configuration page, and `reuse` the nodes in the editor
* It can be driven by http `api` (`post /bot.run -d '{"Name":"a robot"}'` can be easily integrated into CI
* Support a `stress test` (you can set the number of concurrency on the configuration page
* Utilizes the 'behavior tree' to control the robot's execution order and uses 'scripts' for specific node behaviors, such as making HTTP requests.
* Provides graphical editing and debugging capabilities.
* Allows creating and reusing 'prefab' template nodes in the configuration page.
* Supports driving via HTTP API (post /bot.run -d '{"Name":"a robot"}'), making it easy to integrate into CI.
* Supports multiple protocol formats (HTTP, TCP, etc.).
* Offers 'stress testing' with configurable concurrency settings on the configuration page.


## NodeScript
> Through built-in modules and scripts, we can have rich logical expression capabilities. We can also use global (single bot) meta structures to maintain various state changes of the bot.
```lua
--[[
Each node has its own independent .lua script. When the node is executed, dostring will be called to load and run this script.
Each node has its own independent .lua script for execution. When a node is executed, the script is loaded and run using dostring.
Users can load desired 'modules' into the script for additional functionalities. For more information, refer to the documentation.
The script allows defining node execution logic, like sending an HTTP request.
]]--

-- Users can load "modules" they want to use in the script.
Expand Down Expand Up @@ -60,13 +63,20 @@ end
```

## Script Module
|||||||
|-|-|-|-|-|-|
|`base64`|`http`|`protobuf`|`mongoDB`|`json`|
|`md5`|`uuid`|`random`|...|
| 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. |
| 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. |

## Try it out
Try the editor out [on website](http://123.60.17.61:7777)
Try the editor out [on website](http://178.128.113.58:31293)

## Preview
[![image.png](https://i.postimg.cc/t4jMVjp1/image.png)](https://postimg.cc/PPS4B0Lh)
7 changes: 4 additions & 3 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Gobot是一个功能强大的有状态API测试机器人。它提供图形界面
* 提供图形化的编辑,调试能力
* 可以`预制`模版节点,在编辑器中直接使用预制过的节点(可通过标签筛选
* 可以通过 http api `'curl post /bot.run -d '{"Name":"某个机器人"}'` 驱动一个阻塞式的机器人,通过这种方式可以方便的集成进`CI`中的测试流程
* 可以进行`压力测试`(可以在配置页设置并发数
* 支持多种协议格式(HTTP, TCP ...
* 可以进行`压力测试`(可以在配置页设置不同的并发策略
* 提供压力测试后的API/协议`报告`查看

## 节点脚本
Expand Down Expand Up @@ -57,10 +58,10 @@ end
## 脚本层模块
|||||||
|-|-|-|-|-|-|
|`base64`|`http`|`protobuf`|`mongoDB`|`json`|
|`base64`|`http`|`tcp`|`protobuf`|`mongoDB`|`json`|
|`md5`|`uuid`|`random`|...|

## [在线试用](http://123.60.17.61:7777)
## [在线试用](http://178.128.113.58:31293)
## [文档](https://pojol.gitee.io/gobot/#/)

## [视频演示](https://www.bilibili.com/video/BV1sS4y1z7Dg/?vd_source=7c2dfd750914fd5f8a9811b19f0bf447)
Expand Down
13 changes: 9 additions & 4 deletions bot/behavior/action_loop.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package behavior

import "fmt"
import (
"fmt"
)

type LoopAction struct {
INod
base Node

loop int
curLoop int
loop int64
curLoop int64
}

func (a *LoopAction) Init(t *Tree, parent INod, mode Mode) {
a.base.Init(t, parent, mode)
a.loop = int(t.Loop)
a.loop = int64(t.Loop)
if a.loop == 0 {
a.loop = 100000000000 // 无限循环 一千亿
}
}

func (a *LoopAction) AddChild(nod INod) {
Expand Down
4 changes: 3 additions & 1 deletion bot/behavior/action_wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (a *WaitAction) onNext(t *Tick) {
if currTime >= a.endtime {
a.endtime = 0

if a.base.ChildrenNum() > 0 {
if a.base.ChildrenNum() > 0 && !a.base.GetFreeze() {
a.base.SetFreeze(true)
t.blackboard.Append([]INod{a.base.Children()[0]})
} else {
a.base.parent.onNext(t)
Expand All @@ -59,6 +60,7 @@ func (a *WaitAction) onNext(t *Tick) {

func (a *WaitAction) onReset() {
a.endtime = 0
a.base.SetFreeze(false)

for _, child := range a.base.Children() {
child.onReset()
Expand Down
1 change: 1 addition & 0 deletions bot/behavior/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (a *Node) GetFreeze() bool {
return a.freeze
}

// SetFreeze 使节点无效(已经执行过的节点)
func (a *Node) SetFreeze(f bool) {
a.freeze = f
}
Expand Down
5 changes: 4 additions & 1 deletion bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ func (b *Bot) RunByBlock() error {
}

func (b *Bot) GetReport() []script.Report {
return b.bs.HttpMod.GetReport()
httpreport := b.bs.HttpMod.GetReport()
tcpreport := b.bs.TCPMod.GetReport()

return append(httpreport, tcpreport...)
}

func (b *Bot) close() {
Expand Down
2 changes: 1 addition & 1 deletion bot/bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestMain(m *testing.M) {
ms := mock.NewServer()
ms := mock.NewHttpServer()
go ms.Start(":6666")

defer ms.Close()
Expand Down
3 changes: 3 additions & 0 deletions bot/pool/lua_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type lStatePool struct {
type BotState struct {
L *lua.LState
HttpMod *script.HttpModule
TCPMod *script.TCPModule
protoMod *script.ProtoModule
utilsMod *script.UtilsModule
base64Mod *script.Base64Module
Expand All @@ -41,6 +42,7 @@ func _new_state() *BotState {
b := &BotState{
L: lua.NewState(),
HttpMod: script.NewHttpModule(),
TCPMod: script.NewTCPModule(),
protoMod: &script.ProtoModule{},
utilsMod: &script.UtilsModule{},
base64Mod: &script.Base64Module{},
Expand All @@ -50,6 +52,7 @@ func _new_state() *BotState {

b.L.PreloadModule("proto", b.protoMod.Loader)
b.L.PreloadModule("http", b.HttpMod.Loader)
b.L.PreloadModule("tcpconn", b.TCPMod.Loader)
b.L.PreloadModule("utils", b.utilsMod.Loader)
b.L.PreloadModule("base64", b.base64Mod.Loader)
b.L.PreloadModule("mgo", b.mgoMod.Loader)
Expand Down
1 change: 0 additions & 1 deletion editor/.umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default defineConfig({
{ path: "/report", component: "report", name: "report", key: "report" },
{ path: "/prefab", component: "prefab", name: "prefab", key: "prefab" },
{ path: "/config", component: "config", name: "config", key: "config" },
{ path: "/docs", component: "docs", name: "docs", key: "docs" },
],
plugins: [
],
Expand Down
4 changes: 2 additions & 2 deletions editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"start": "npm run dev",
"electron-dev": "electron .",
"package_win32_x64": "electron-packager ./ Gobot --platform=win32 --arch=x64 --asar=true --prune=true --overwrite",
"package_darwin_arm64": "electron-packager ./ Gobot --platform=darwin --arch=arm64 --overwrite"
"package_darwin_arm64": "electron-packager ./ Gobot --platform=darwin --arch=arm64 --asar=true --overwrite"
},
"dependencies": {
"@ant-design/charts": "^1.4.2",
"@ant-design/pro-layout": "^7.6.1",
"@antv/x6": "1.27.2",
"@antv/x6": "1.34.6",
"@codemirror/legacy-modes": "^6.3.2",
"@octokit/request": "^6.2.3",
"@reduxjs/toolkit": "^1.9.3",
Expand Down
4 changes: 2 additions & 2 deletions editor/src/layouts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function Layout() {

if (props.isMobile) return [];
return [
<Tag>v0.3.5</Tag>,
<Tag>v0.3.7</Tag>,
<Radio.Group onChange={themeChange} value={themeValue} buttonStyle="solid" defaultValue={localStorage.theme} size={"small"}>
<Radio.Button value={ThemeType.Dark}>Dark</Radio.Button>
<Radio.Button value={ThemeType.Light}>Light</Radio.Button>
Expand All @@ -153,7 +153,7 @@ function Layout() {
onOk={modalHandleOk}
onCancel={modalHandleCancel}
>
<Tag>e.g. http://123.60.17.61:8888 (Sample driver server address</Tag>
<Tag>e.g. http://178.128.113.58:30000 (Sample driver server address</Tag>
<Input
placeholder={"Input drive server address"}
onChange={modalConfigChange}
Expand Down
2 changes: 1 addition & 1 deletion editor/src/models/debuginfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const debugInfoSlice = createSlice({
state.threadInfo = action.payload.threadInfo

// 每次创建新的机器人时重制锁
state.lock = false
state.lock = action.payload.lock
},
setLock(state, action: PayloadAction<boolean>) {
state.lock = action.payload
Expand Down
2 changes: 1 addition & 1 deletion editor/src/models/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { combineReducers } from 'redux';


import prefabSlice from "@/models/prefab"
import treeSlice from "@/models/newtree"
import treeSlice from "@/models/tree"
import debugInfoSlice from "@/models/debuginfo"
import configSlice from './config';
import resizeSlice from './resize';
Expand Down
28 changes: 21 additions & 7 deletions editor/src/models/newtree.ts → editor/src/models/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ interface TreeState {
currentDebugTree: NodeNotifyInfo;
currentDebugBot: string;
currentClickNode: NodeClickInfo;
currentLockedNode: NodeClickInfo;
updatetick: number;
}


const initialState: TreeState = {
nodes: new Array<NodeNotifyInfo>(),
history: new Array<NodeNotifyInfo>(),
Expand All @@ -27,6 +27,7 @@ const initialState: TreeState = {
currentDebugBot: "",
currentDebugTree: getDefaultNodeNotifyInfo(),
currentClickNode: { id: "", type: "" },
currentLockedNode: { id: "", type: "" },
updatetick: 0,
};

Expand Down Expand Up @@ -206,11 +207,11 @@ function save(state: TreeState, name: string) {
var xmltree = {
behavior: nod,
};

var blob = new Blob([OBJ2XML(xmltree)], {
type: "application/json",
});

PostBlob(
localStorage.remoteAddr,
Api.FileBlobUpload,
Expand All @@ -222,8 +223,7 @@ function save(state: TreeState, name: string) {
"upload fail:" + String(json.Code) + " msg: " + json.Msg
);
} else {
console.info(json.Body)
message.success("upload succ ");
message.success(name + " upload succ");
}
});
}
Expand Down Expand Up @@ -292,10 +292,24 @@ const treeSlice = createSlice({
},
nodeSave(state, action: PayloadAction<string>) {
let behavirName = action.payload
save(state, behavirName)

if (behavirName == "") {
if (state.currentTreeName !== "") {
save(state, state.currentTreeName)
}
} else {
save(state, behavirName)
state.currentTreeName = behavirName
}

},
unlockFocus(state, action: PayloadAction<NodeClickInfo>) {
let info = action.payload
state.currentLockedNode = info
console.info("lock/unlock info", info)
}
},
});

export const { nodeAdd, nodeRmv, nodeLink, nodeUnlink, cleanTree, nodeUpdate, nodeClick, nodeRedraw, initTree, setCurrentDebugBot, nodeSave } = treeSlice.actions;
export const { nodeAdd, nodeRmv, nodeLink, nodeUnlink, cleanTree, nodeUpdate, nodeClick, nodeRedraw, initTree, setCurrentDebugBot, nodeSave,unlockFocus } = treeSlice.actions;
export default treeSlice;
12 changes: 5 additions & 7 deletions editor/src/pages/bots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import PubSub from "pubsub-js";
import Topic from "../constant/topic";
import Api from "../constant/api";
import { HomeTag } from "./tags/tags";
import { initTree } from "@/models/newtree";
import { initTree } from "@/models/tree";

const { Post } = require("../utils/request");
const { LoadBehaviorWithBlob, LoadBehaviorWithFile } = require('../utils/parse');
Expand Down Expand Up @@ -153,13 +153,11 @@ const Bots = (props: BotsProps) => {

var intags = (tags: Array<string>) => {
for (var i = 0; i < selectedTag.length; i++) {
for (var j = 0; j < tags.length; j++) {
if (selectedTag[i] === tags[j]) {
return true
}
if (!tags.includes(selectedTag[i])) {
return false
}
}
return false
return true
}

if (bots.length > 0) {
Expand Down Expand Up @@ -283,7 +281,7 @@ const Bots = (props: BotsProps) => {
}

const handleBotLoad = (e: any) => {
selectedRows

if (selectedRows.length > 0) {
var row = selectedRows[0]
LoadBehaviorWithBlob(
Expand Down
Loading

0 comments on commit 63f1fc0

Please sign in to comment.