hrp

package
v0.0.0-...-a74421f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 58 Imported by: 0

README

代码阅读指南(golang 部分)

核心数据结构

HttpRunner 以 TestCase 为核心,将任意测试场景抽象为有序步骤的集合。

type TestCase struct {
	Config    *TConfig
	TestSteps []IStep
}

其中,测试步骤 IStep 采用了 go interface 的设计理念,支持进行任意拓展;步骤内容统一在 Run 方法中进行实现。

type IStep interface {
	Name() string
	Type() StepType
	Struct() *TStep
	Run(*SessionRunner) (*StepResult, error)
}

我们只需遵循 IStep 的接口定义,即可实现各种类型的测试步骤类型。当前 hrp 已支持的步骤类型包括:

  • request:发起单次 HTTP 请求
  • api:引用执行其它 API 文件
  • testcase:引用执行其它测试用例文件
  • thinktime:思考时间,按照配置的逻辑进行等待
  • transaction:事务机制,用于压测
  • rendezvous:集合点机制,用于压测

基于该机制,我们可以扩展支持新的协议类型,例如 HTTP2/WebSocket/RPC 等;同时也可以支持新的测试类型,例如 UI 自动化。甚至我们还可以在一个测试用例中混合调用多种不同的 Step 类型,例如实现 HTTP/RPC/UI 混合场景。

运行主流程

整体控制器 HRPRunner

执行接口测试时,会初始化一个 HRPRunner,用于控制测试的执行策略。

type HRPRunner struct {
	t             *testing.T
	failfast      bool
	requestsLogOn bool
	pluginLogOn   bool
	saveTests     bool
	genHTMLReport bool
	client        *http.Client
}

func (r *HRPRunner) Run(testcases ...ITestCase) error
func (r *HRPRunner) NewCaseRunner(testcase *TestCase) (*CaseRunner, error)

重点关注两个方法:

  • Run:测试执行的主入口,支持运行一个或多个测试用例
  • NewCaseRunner:针对给定的测试用例初始化一个 CaseRunner
用例执行器 CaseRunner

针对每个测试用例,采用 CaseRunner 存储其公共信息,包括 plugin/parser

type CaseRunner struct {
	testCase  *TestCase
	hrpRunner *HRPRunner
	parser    *Parser

	parsedConfig       *TConfig
	parametersIterator *ParametersIterator
	rootDir            string // project root dir
}

func (r *CaseRunner) NewSession() *SessionRunner {

重点关注一个方法:

  • NewSession:测试用例的每一次执行对应一个 SessionRunner
SessionRunner

测试用例的具体执行都由 SessionRunner 完成,每个 session 实例中除了包含测试用例自身内容外,还会包含测试过程的 session 数据和最终测试结果 summary。

type SessionRunner struct {
	caseRunner       *CaseRunner
	sessionVariables map[string]interface{}
	transactions      map[string]map[transactionType]time.Time
	startTime         time.Time                  // record start time of the testcase
	summary           *TestCaseSummary           // record test case summary
}

func (r *SessionRunner) Start(givenVars map[string]interface{}) error

重点关注一个方法:

  • Start:启动执行用例,依次执行所有测试步骤
func (r *SessionRunner) Start(givenVars map[string]interface{}) error {
	...
	r.resetSession()

	r.InitWithParameters(givenVars)

	// run step in sequential order
	for _, step := range r.testCase.TestSteps {
		// parse step

		// run step
		stepResult, err := step.Run(r)

		// update summary
		r.summary.Records = append(r.summary.Records, stepResult)

		// update extracted variables
		for k, v := range stepResult.ExportVars {
			r.sessionVariables[k] = v
		}

		// check if failfast
		if err != nil && r.caseRunner.hrpRunner.failfast {
			return errors.Wrap(err, "abort running due to failfast setting")
		}
	}
	...
}

在主流程中,SessionRunner 并不需要关注 step 的具体类型,统一都是调用 step.Run(r),具体实现逻辑都在对应 step 的 Run(*SessionRunner) 方法中。

Documentation

Index

Constants

View Source
const (
	PluginGoBuiltFile          = "debugtalk.so"      // built from go official plugin
	PluginHashicorpGoBuiltFile = "debugtalk.bin"     // built from hashicorp go plugin
	PluginGoSourceFile         = "debugtalk.go"      // golang function plugin source file
	PluginGoSourceGenFile      = "debugtalk_gen.go"  // generated for hashicorp go plugin
	PluginPySourceFile         = "debugtalk.py"      // python function plugin source file
	PluginPySourceGenFile      = ".debugtalk_gen.py" // generated for hashicorp python plugin
)

Variables

View Source
var EnumAPIResponseSuccess = ServerStatus{
	Code:    Success,
	Message: "success",
}

Functions

func BuildPlugin

func BuildPlugin(path string, output string) (err error)

func GetProjectRootDirPath

func GetProjectRootDirPath(path string) (rootDir string, err error)

func Run

func Run(testcases ...ITestCase) error

Run starts to run API test with default configs.

Types

type API

type API struct {
	Name          string                 `json:"name" yaml:"name"` // required
	Request       *Request               `json:"request,omitempty" yaml:"request,omitempty"`
	Variables     map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`
	SetupHooks    []string               `json:"setup_hooks,omitempty" yaml:"setup_hooks,omitempty"`
	TeardownHooks []string               `json:"teardown_hooks,omitempty" yaml:"teardown_hooks,omitempty"`
	Extract       map[string]string      `json:"extract,omitempty" yaml:"extract,omitempty"`
	Validators    []interface{}          `json:"validate,omitempty" yaml:"validate,omitempty"`
	Export        []string               `json:"export,omitempty" yaml:"export,omitempty"`
	Path          string
}

API 直接定义结构体

func (*API) GetPath

func (api *API) GetPath() string

func (*API) ToAPI

func (api *API) ToAPI() (*API, error)

ToAPI 直接定义的结构体的API不需要进行转换

type APIGetMasterRequestBody

type APIGetMasterRequestBody struct{}

type APIGetMasterResponseBody

type APIGetMasterResponseBody struct {
	ServerStatus
	Data map[string]interface{} `json:"data"`
}

type APIGetWorkersRequestBody

type APIGetWorkersRequestBody struct{}

type APIGetWorkersResponseBody

type APIGetWorkersResponseBody struct {
	ServerStatus
	Data []boomer.WorkerNode `json:"data"`
}

type APIPath

type APIPath string

APIPath implements IAPI interface.

func (*APIPath) GetPath

func (path *APIPath) GetPath() string

func (*APIPath) ToAPI

func (path *APIPath) ToAPI() (*API, error)

ToAPI 通过路径引用的API需要将文件内容转换为API结构体

type ActionType

type ActionType string

type Address

type Address struct {
	ClientIP   string `json:"client_ip,omitempty" yaml:"client_ip,omitempty"`
	ClientPort string `json:"client_port,omitempty" yaml:"client_port,omitempty"`
	ServerIP   string `json:"server_ip,omitempty" yaml:"server_ip,omitempty"`
	ServerPort string `json:"server_port,omitempty" yaml:"server_port,omitempty"`
}

type CaseRunner

type CaseRunner struct {
	// contains filtered or unexported fields
}

CaseRunner 结构体用于执行单个测试用例的运行器

func (*CaseRunner) NewSession

func (r *CaseRunner) NewSession() *SessionRunner

NewSession 方法用于创建一个新的会话运行器(SessionRunner)

type CommonResponseBody

type CommonResponseBody struct {
	ServerStatus
}

type HRPBoomer

type HRPBoomer struct {
	*boomer.Boomer
	// contains filtered or unexported fields
}

func NewMasterBoomer

func NewMasterBoomer(masterBindHost string, masterBindPort int) *HRPBoomer

func NewStandaloneBoomer

func NewStandaloneBoomer(spawnCount int64, spawnRate float64) *HRPBoomer

func NewWorkerBoomer

func NewWorkerBoomer(masterHost string, masterPort int) *HRPBoomer

func (*HRPBoomer) BytesToTCases

func (b *HRPBoomer) BytesToTCases(testCasesBytes []byte) []*TCase

func (*HRPBoomer) ConvertTestCasesToBoomerTasks

func (b *HRPBoomer) ConvertTestCasesToBoomerTasks(testcases ...ITestCase) (taskSlice []*boomer.Task)

func (*HRPBoomer) InitBoomer

func (b *HRPBoomer) InitBoomer()

func (*HRPBoomer) NewAPIHandler

func (b *HRPBoomer) NewAPIHandler() *apiHandler

func (*HRPBoomer) ParseTestCases

func (b *HRPBoomer) ParseTestCases(testCases []*TestCase) []*TCase

func (*HRPBoomer) PollTasks

func (b *HRPBoomer) PollTasks(ctx context.Context)

func (*HRPBoomer) PollTestCases

func (b *HRPBoomer) PollTestCases(ctx context.Context)

func (*HRPBoomer) Quit

func (b *HRPBoomer) Quit()

func (*HRPBoomer) Run

func (b *HRPBoomer) Run(testcases ...ITestCase)

Run starts to run load test for one or multiple testcases.

func (*HRPBoomer) SetClientTransport

func (b *HRPBoomer) SetClientTransport() *HRPBoomer

func (*HRPBoomer) SetPython3Venv

func (b *HRPBoomer) SetPython3Venv(venv string) *HRPBoomer

SetPython3Venv specifies python3 venv.

func (*HRPBoomer) StartServer

func (b *HRPBoomer) StartServer(ctx context.Context, addr string)

func (*HRPBoomer) TestCasesToBytes

func (b *HRPBoomer) TestCasesToBytes(testcases ...ITestCase) []byte

type HRPRunner

type HRPRunner struct {
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner(t *testing.T) *HRPRunner

NewRunner 构造一个新的运行器实例。

func (*HRPRunner) GenHTMLReport

func (r *HRPRunner) GenHTMLReport() *HRPRunner

GenHTMLReport 配置是否生成 API 测试的 HTML 报告。

func (*HRPRunner) NewCaseRunner

func (r *HRPRunner) NewCaseRunner(testcase *TestCase) (*CaseRunner, error)

NewCaseRunner 创建一个新的用例运行器(CaseRunner)用于指定的测试用例(testcase)。 每个测试用例都有自己的用例运行器。

func (*HRPRunner) Run

func (r *HRPRunner) Run(testcases ...ITestCase) error

Run 开始执行一个或多个测试用例。

func (*HRPRunner) SetClientTransport

func (r *HRPRunner) SetClientTransport(maxConns int, disableKeepAlive bool, disableCompression bool) *HRPRunner

SetClientTransport 配置 HTTP 客户端的传输以进行高并发负载测试。

func (*HRPRunner) SetFailfast

func (r *HRPRunner) SetFailfast(failfast bool) *HRPRunner

SetFailfast 配置是否在步骤失败时停止运行。

func (*HRPRunner) SetHTTPStatOn

func (r *HRPRunner) SetHTTPStatOn() *HRPRunner

SetHTTPStatOn 打开 HTTP 延迟统计。

func (*HRPRunner) SetPluginLogOn

func (r *HRPRunner) SetPluginLogOn() *HRPRunner

SetPluginLogOn 打开插件日志记录。

func (*HRPRunner) SetProxyUrl

func (r *HRPRunner) SetProxyUrl(proxyUrl string) *HRPRunner

SetProxyUrl 配置代理 URL,通常用于捕获 HTTP 数据包进行调试。

func (*HRPRunner) SetPython3Venv

func (r *HRPRunner) SetPython3Venv(venv string) *HRPRunner

SetPython3Venv 指定 Python3 虚拟环境。

func (*HRPRunner) SetRequestsLogOn

func (r *HRPRunner) SetRequestsLogOn() *HRPRunner

SetRequestsLogOn 打开请求和响应详细信息记录。

func (*HRPRunner) SetSaveTests

func (r *HRPRunner) SetSaveTests(saveTests bool) *HRPRunner

SetSaveTests 配置是否保存测试摘要。

func (*HRPRunner) SetTimeout

func (r *HRPRunner) SetTimeout(timeout time.Duration) *HRPRunner

SetTimeout 配置全局超时时间(秒)。

type HTTPMethod

type HTTPMethod string

type IAPI

type IAPI interface {
	GetPath() string
	ToAPI() (*API, error)
}

IAPI represents interface for api, includes API and APIPath. API实现有2中方式,一种是直接定义API结构体,另一种是定义APIPath结构体,然后通过APIPath结构体的GetPath()方法获取API结构体

type IStep

type IStep interface {
	Name() string                            // 步骤名称
	Type() StepType                          // 步骤类型
	Struct() *TStep                          // 步骤实例
	Run(*SessionRunner) (*StepResult, error) // 运行步骤
}

IStep represents interface for all types for teststeps, includes: StepRequest, StepRequestWithOptionalArgs, StepRequestValidation, StepRequestExtraction, StepTestCaseWithOptionalArgs, StepTransaction, StepRendezvous, StepWebSocket. 测试步骤接口(类型)

type ITestCase

type ITestCase interface {
	GetPath() string
	ToTestCase() (*TestCase, error)
}

ITestCase represents interface for testcases, includes TestCase and TestCasePath.

type MessageType

type MessageType int

type MobileStep

type MobileStep struct {
	Serial            string `json:"serial,omitempty" yaml:"serial,omitempty"`
	uixt.MobileAction `yaml:",inline"`
	Actions           []uixt.MobileAction `json:"actions,omitempty" yaml:"actions,omitempty"`
}

type Parameters

type Parameters []map[string]interface{}

[

{"username": "test1", "password": "111111"},
{"username": "test2", "password": "222222"},

]

type ParametersIterator

type ParametersIterator struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ParametersIterator 用于迭代测试参数。

func (*ParametersIterator) HasNext

func (iter *ParametersIterator) HasNext() bool

func (*ParametersIterator) Next

func (iter *ParametersIterator) Next() map[string]interface{}

func (*ParametersIterator) SetUnlimitedMode

func (iter *ParametersIterator) SetUnlimitedMode()

SetUnlimitedMode 用于设置无限制模式,适用于负载测试。

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func (*Parser) Parse

func (p *Parser) Parse(raw interface{}, variablesMapping map[string]interface{}) (interface{}, error)

ParseString 将interface(变量、函数)内容转换为string

func (*Parser) ParseHeaders

func (p *Parser) ParseHeaders(rawHeaders map[string]string, variablesMapping map[string]interface{}) (map[string]string, error)

func (*Parser) ParseString

func (p *Parser) ParseString(raw string, variablesMapping map[string]interface{}) (interface{}, error)

ParseString parse string with variables 将变量解析为常量 raw:需要解析函数、变量的字符串 variablesMapping:变量映射,key为变量名,value为变量值

func (*Parser) ParseVariables

func (p *Parser) ParseVariables(variables map[string]interface{}) (map[string]interface{}, error)

type Platform

type Platform struct {
	HttprunnerVersion string `json:"httprunner_version" yaml:"httprunner_version"`
	GoVersion         string `json:"go_version" yaml:"go_version"`
	Platform          string `json:"platform" yaml:"platform"`
}

type PluginConfig

type PluginConfig struct {
	Path    string
	Type    string // bin、so、py
	Content []byte
}

type QuitRequestBody

type QuitRequestBody struct {
	Worker string `json:"worker"`
}

type RebalanceRequestBody

type RebalanceRequestBody struct {
	boomer.Profile `mapstructure:",squash"`
	Worker         string                 `json:"worker,omitempty" yaml:"worker,omitempty" mapstructure:"worker"`
	Other          map[string]interface{} `mapstructure:",remain"`
}

type Rendezvous

type Rendezvous struct {
	Name    string  `json:"name" yaml:"name"`                           // required
	Percent float32 `json:"percent,omitempty" yaml:"percent,omitempty"` // default to 1(100%)
	Number  int64   `json:"number,omitempty" yaml:"number,omitempty"`
	Timeout int64   `json:"timeout,omitempty" yaml:"timeout,omitempty"` // milliseconds
	// contains filtered or unexported fields
}

type ReqResps

type ReqResps struct {
	Request  interface{} `json:"request" yaml:"request"`
	Response interface{} `json:"response" yaml:"response"`
}

type Request

type Request struct {
	Method         HTTPMethod             `json:"method" yaml:"method"` // required
	URL            string                 `json:"url" yaml:"url"`       // required
	HTTP2          bool                   `json:"http2,omitempty" yaml:"http2,omitempty"`
	Params         map[string]interface{} `json:"params,omitempty" yaml:"params,omitempty"`
	Headers        map[string]string      `json:"headers,omitempty" yaml:"headers,omitempty"`
	Cookies        map[string]string      `json:"cookies,omitempty" yaml:"cookies,omitempty"`
	Body           interface{}            `json:"body,omitempty" yaml:"body,omitempty"`
	Json           interface{}            `json:"json,omitempty" yaml:"json,omitempty"`
	Data           interface{}            `json:"data,omitempty" yaml:"data,omitempty"`
	Timeout        float64                `json:"timeout,omitempty" yaml:"timeout,omitempty"` // timeout in seconds
	AllowRedirects bool                   `json:"allow_redirects,omitempty" yaml:"allow_redirects,omitempty"`
	Verify         bool                   `json:"verify,omitempty" yaml:"verify,omitempty"`
	Upload         map[string]interface{} `json:"upload,omitempty" yaml:"upload,omitempty"`
}

Request represents HTTP request data structure. This is used for teststep. 请求结构体

type ServerCode

type ServerCode int
const (
	Success ServerCode = iota
	ParamsError
	ServerError
	StopError
)

server response code

type ServerStatus

type ServerStatus struct {
	Code    ServerCode `json:"code"`
	Message string     `json:"message"`
}

ServerStatus stores http response code and message

func CustomAPIResponse

func CustomAPIResponse(errCode ServerCode, errMsg string) ServerStatus

func EnumAPIResponseParamError

func EnumAPIResponseParamError(errMsg string) ServerStatus

func EnumAPIResponseServerError

func EnumAPIResponseServerError(errMsg string) ServerStatus

func EnumAPIResponseStopError

func EnumAPIResponseStopError(errMsg string) ServerStatus

type SessionData

type SessionData struct {
	Success    bool                `json:"success" yaml:"success"`
	ReqResps   *ReqResps           `json:"req_resps" yaml:"req_resps"`
	Address    *Address            `json:"address,omitempty" yaml:"address,omitempty"` // TODO
	Validators []*ValidationResult `json:"validators,omitempty" yaml:"validators,omitempty"`
}

type SessionRunner

type SessionRunner struct {
	// contains filtered or unexported fields
}

SessionRunner 用于运行测试用例及其步骤。 每个测试用例都有自己的 SessionRunner 实例,并共享会话变量。

func (*SessionRunner) GetSummary

func (r *SessionRunner) GetSummary() (*TestCaseSummary, error)

GetSummary 获取测试用例的摘要信息

func (*SessionRunner) InitWithParameters

func (r *SessionRunner) InitWithParameters(parameters map[string]interface{})

InitWithParameters 使用给定参数更新会话变量。 这用于数据驱动

func (*SessionRunner) ParseStepVariables

func (r *SessionRunner) ParseStepVariables(stepVariables map[string]interface{}) (map[string]interface{}, error)

ParseStepVariables 将步骤变量与配置变量和会话变量合并

func (*SessionRunner) Start

func (r *SessionRunner) Start(givenVars map[string]interface{}) error

Start 按顺序运行测试步骤。 givenVars 用于数据驱动

type StartRequestBody

type StartRequestBody struct {
	boomer.Profile `mapstructure:",squash"`
	Worker         string                 `json:"worker,omitempty" yaml:"worker,omitempty" mapstructure:"worker"` // all
	TestCasePath   string                 `json:"testcase-path" yaml:"testcase-path" mapstructure:"testcase-path"`
	Other          map[string]interface{} `mapstructure:",remain"`
}

type Stat

type Stat struct {
	TestCases TestCaseStat `json:"testcases" yaml:"testcases"`
	TestSteps TestStepStat `json:"teststeps" yaml:"teststeps"`
}

type StepAPIWithOptionalArgs

type StepAPIWithOptionalArgs struct {
	// contains filtered or unexported fields
}

StepAPIWithOptionalArgs implements IStep interface. 定义API类型的步骤

func (*StepAPIWithOptionalArgs) Export

Export specifies variable names to export from referenced api for current step. 设置步骤导出的变量

func (*StepAPIWithOptionalArgs) Name

func (s *StepAPIWithOptionalArgs) Name() string

func (*StepAPIWithOptionalArgs) Run

func (s *StepAPIWithOptionalArgs) Run(r *SessionRunner) (stepResult *StepResult, err error)

Run 执行步骤

func (*StepAPIWithOptionalArgs) Struct

func (s *StepAPIWithOptionalArgs) Struct() *TStep

Struct 返回结构体

func (*StepAPIWithOptionalArgs) TeardownHook

TeardownHook adds a teardown hook for current teststep. 设置步骤的teardown hook,主要用户清理数据

func (*StepAPIWithOptionalArgs) Type

Type 设置类型

type StepMobile

type StepMobile struct {
	// contains filtered or unexported fields
}

StepMobile implements IStep interface.

func (*StepMobile) AppLaunch

func (s *StepMobile) AppLaunch(bundleId string) *StepMobile

func (*StepMobile) AppTerminate

func (s *StepMobile) AppTerminate(bundleId string) *StepMobile

func (*StepMobile) Back

func (s *StepMobile) Back(options ...uixt.ActionOption) *StepMobile

func (*StepMobile) DoubleTap

func (s *StepMobile) DoubleTap(params string, options ...uixt.ActionOption) *StepMobile

func (*StepMobile) DoubleTapXY

func (s *StepMobile) DoubleTapXY(x, y float64) *StepMobile

DoubleTapXY double taps the point {X,Y}, X & Y is percentage of coordinates

func (*StepMobile) Home

func (s *StepMobile) Home() *StepMobile

func (*StepMobile) Input

func (s *StepMobile) Input(text string, options ...uixt.ActionOption) *StepMobile

func (*StepMobile) InstallApp

func (s *StepMobile) InstallApp(path string) *StepMobile

func (*StepMobile) Name

func (s *StepMobile) Name() string

func (*StepMobile) Run

func (s *StepMobile) Run(r *SessionRunner) (*StepResult, error)

func (*StepMobile) ScreenShot

func (s *StepMobile) ScreenShot() *StepMobile

func (*StepMobile) Serial

func (s *StepMobile) Serial(serial string) *StepMobile

func (*StepMobile) Sleep

func (s *StepMobile) Sleep(n float64) *StepMobile

Sleep specify sleep seconds after last action

func (*StepMobile) SleepRandom

func (s *StepMobile) SleepRandom(params ...float64) *StepMobile

SleepRandom specify random sleeping seconds after last action params have two different kinds: 1. [min, max] : min and max are float64 time range boudaries 2. [min1, max1, weight1, min2, max2, weight2, ...] : weight is the probability of the time range

func (*StepMobile) StartCamera

func (s *StepMobile) StartCamera() *StepMobile

func (*StepMobile) StopCamera

func (s *StepMobile) StopCamera() *StepMobile

func (*StepMobile) Struct

func (s *StepMobile) Struct() *TStep

func (*StepMobile) Swipe

func (s *StepMobile) Swipe(sx, sy, ex, ey float64, options ...uixt.ActionOption) *StepMobile

func (*StepMobile) SwipeDown

func (s *StepMobile) SwipeDown(options ...uixt.ActionOption) *StepMobile

func (*StepMobile) SwipeLeft

func (s *StepMobile) SwipeLeft(options ...uixt.ActionOption) *StepMobile

func (*StepMobile) SwipeRight

func (s *StepMobile) SwipeRight(options ...uixt.ActionOption) *StepMobile

func (*StepMobile) SwipeToTapApp

func (s *StepMobile) SwipeToTapApp(appName string, options ...uixt.ActionOption) *StepMobile

func (*StepMobile) SwipeToTapText

func (s *StepMobile) SwipeToTapText(text string, options ...uixt.ActionOption) *StepMobile

func (*StepMobile) SwipeToTapTexts

func (s *StepMobile) SwipeToTapTexts(texts interface{}, options ...uixt.ActionOption) *StepMobile

func (*StepMobile) SwipeUp

func (s *StepMobile) SwipeUp(options ...uixt.ActionOption) *StepMobile

func (*StepMobile) Tap

func (s *StepMobile) Tap(params string, options ...uixt.ActionOption) *StepMobile

Tap taps on the target element

func (*StepMobile) TapAbsXY

func (s *StepMobile) TapAbsXY(x, y float64, options ...uixt.ActionOption) *StepMobile

TapAbsXY taps the point {X,Y}, X & Y is absolute coordinates

func (*StepMobile) TapByCV

func (s *StepMobile) TapByCV(imagePath string, options ...uixt.ActionOption) *StepMobile

Tap taps on the target element by CV recognition

func (*StepMobile) TapByOCR

func (s *StepMobile) TapByOCR(ocrText string, options ...uixt.ActionOption) *StepMobile

Tap taps on the target element by OCR recognition

func (*StepMobile) TapXY

func (s *StepMobile) TapXY(x, y float64, options ...uixt.ActionOption) *StepMobile

TapXY taps the point {X,Y}, X & Y is percentage of coordinates

func (*StepMobile) Type

func (s *StepMobile) Type() StepType

func (*StepMobile) Validate

func (s *StepMobile) Validate() *StepMobileUIValidation

Validate switches to step validation.

type StepMobileUIValidation

type StepMobileUIValidation struct {
	// contains filtered or unexported fields
}

StepMobileUIValidation implements IStep interface.

func (*StepMobileUIValidation) AssertAppInForeground

func (s *StepMobileUIValidation) AssertAppInForeground(packageName string, msg ...string) *StepMobileUIValidation

func (*StepMobileUIValidation) AssertAppNotInForeground

func (s *StepMobileUIValidation) AssertAppNotInForeground(packageName string, msg ...string) *StepMobileUIValidation

func (*StepMobileUIValidation) AssertImageExists

func (s *StepMobileUIValidation) AssertImageExists(expectedImagePath string, msg ...string) *StepMobileUIValidation

func (*StepMobileUIValidation) AssertImageNotExists

func (s *StepMobileUIValidation) AssertImageNotExists(expectedImagePath string, msg ...string) *StepMobileUIValidation

func (*StepMobileUIValidation) AssertLabelExists

func (s *StepMobileUIValidation) AssertLabelExists(expectedLabel string, msg ...string) *StepMobileUIValidation

func (*StepMobileUIValidation) AssertLabelNotExists

func (s *StepMobileUIValidation) AssertLabelNotExists(expectedLabel string, msg ...string) *StepMobileUIValidation

func (*StepMobileUIValidation) AssertNameExists

func (s *StepMobileUIValidation) AssertNameExists(expectedName string, msg ...string) *StepMobileUIValidation

func (*StepMobileUIValidation) AssertNameNotExists

func (s *StepMobileUIValidation) AssertNameNotExists(expectedName string, msg ...string) *StepMobileUIValidation

func (*StepMobileUIValidation) AssertOCRExists

func (s *StepMobileUIValidation) AssertOCRExists(expectedText string, msg ...string) *StepMobileUIValidation

func (*StepMobileUIValidation) AssertOCRNotExists

func (s *StepMobileUIValidation) AssertOCRNotExists(expectedText string, msg ...string) *StepMobileUIValidation

func (*StepMobileUIValidation) Name

func (s *StepMobileUIValidation) Name() string

func (*StepMobileUIValidation) Run

func (*StepMobileUIValidation) Struct

func (s *StepMobileUIValidation) Struct() *TStep

func (*StepMobileUIValidation) Type

func (s *StepMobileUIValidation) Type() StepType

type StepRendezvous

type StepRendezvous struct {
	// contains filtered or unexported fields
}

StepRendezvous implements IStep interface.

func (*StepRendezvous) Name

func (s *StepRendezvous) Name() string

func (*StepRendezvous) Run

func (*StepRendezvous) Struct

func (s *StepRendezvous) Struct() *TStep

func (*StepRendezvous) Type

func (s *StepRendezvous) Type() StepType

func (*StepRendezvous) WithTimeout

func (s *StepRendezvous) WithTimeout(timeout int64) *StepRendezvous

WithTimeout sets the timeout of duration between each user arriving at the current rendezvous

func (*StepRendezvous) WithUserNumber

func (s *StepRendezvous) WithUserNumber(number int64) *StepRendezvous

WithUserNumber sets the user number needed to release the current rendezvous

func (*StepRendezvous) WithUserPercent

func (s *StepRendezvous) WithUserPercent(percent float32) *StepRendezvous

WithUserPercent sets the user percent needed to release the current rendezvous

type StepRequest

type StepRequest struct {
	// contains filtered or unexported fields
}

StepRequest 设置测试步骤类型

func NewStep

func NewStep(name string) *StepRequest

NewStep returns a new constructed teststep with specified step name. 创建一个新的测试步骤

func (*StepRequest) Android

func (s *StepRequest) Android() *StepMobile

Android 创建一个新的 Android 动作。

func (*StepRequest) CallRefAPI

func (s *StepRequest) CallRefAPI(api IAPI) *StepAPIWithOptionalArgs

CallRefAPI 调用一个引用的 API。

func (*StepRequest) CallRefCase

CallRefCase 调用一个引用的测试用例。

func (*StepRequest) DELETE

DELETE 设置当前测试步骤的请求方法为DELETE、设置url

func (*StepRequest) EndTransaction

func (s *StepRequest) EndTransaction(name string) *StepTransaction

EndTransaction 结束一个事务。

func (*StepRequest) GET

GET 设置当前测试步骤的请求方法为GET、设置url

func (*StepRequest) HEAD

HEAD 设置当前测试步骤的请求方法为HEAD、设置url

func (*StepRequest) HTTP2

func (s *StepRequest) HTTP2() *StepRequest

HTTP2 设置当前测试步骤的HTTP2协议

func (*StepRequest) IOS

func (s *StepRequest) IOS() *StepMobile

IOS 创建一个新的 iOS 动作。

func (*StepRequest) Loop

func (s *StepRequest) Loop(times int) *StepRequest

Loop 设置当前测试步骤的循环次数

func (*StepRequest) OPTIONS

OPTIONS 设置当前测试步骤的请求方法为OPTIONS、设置url

func (*StepRequest) PATCH

PATCH 设置当前测试步骤的请求方法为PATCH、设置url

func (*StepRequest) POST

POST 设置当前测试步骤的请求方法为POST、设置url

func (*StepRequest) PUT

PUT 设置当前测试步骤的请求方法为PUT、设置url

func (*StepRequest) SetRendezvous

func (s *StepRequest) SetRendezvous(name string) *StepRendezvous

SetRendezvous 创建一个新的会合点。

func (*StepRequest) SetThinkTime

func (s *StepRequest) SetThinkTime(time float64) *StepThinkTime

SetThinkTime 设置思考时间。

func (*StepRequest) SetupHook

func (s *StepRequest) SetupHook(hook string) *StepRequest

SetupHook 设置当前测试步骤的setup hook

func (*StepRequest) StartTransaction

func (s *StepRequest) StartTransaction(name string) *StepTransaction

StartTransaction 开始一个事务。

func (*StepRequest) WebSocket

func (s *StepRequest) WebSocket() *StepWebSocket

WebSocket 创建一个新的 WebSocket 动作。

func (*StepRequest) WithVariables

func (s *StepRequest) WithVariables(variables map[string]interface{}) *StepRequest

WithVariables 设置当前测试步骤的变量

type StepRequestExtraction

type StepRequestExtraction struct {
	// contains filtered or unexported fields
}

StepRequestExtraction implements IStep interface.

func (*StepRequestExtraction) Name

func (s *StepRequestExtraction) Name() string

func (*StepRequestExtraction) Run

func (*StepRequestExtraction) Struct

func (s *StepRequestExtraction) Struct() *TStep

func (*StepRequestExtraction) Type

func (s *StepRequestExtraction) Type() StepType

func (*StepRequestExtraction) Validate

Validate switches to step validation.

func (*StepRequestExtraction) WithJmesPath

func (s *StepRequestExtraction) WithJmesPath(jmesPath string, varName string) *StepRequestExtraction

WithJmesPath sets the JMESPath expression to extract from the response.

type StepRequestValidation

type StepRequestValidation struct {
	// contains filtered or unexported fields
}

StepRequestValidation implements IStep interface.

func (*StepRequestValidation) AssertContainedBy

func (s *StepRequestValidation) AssertContainedBy(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertContains

func (s *StepRequestValidation) AssertContains(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertEndsWith

func (s *StepRequestValidation) AssertEndsWith(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertEqual

func (s *StepRequestValidation) AssertEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertEqualFold

func (s *StepRequestValidation) AssertEqualFold(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertGreater

func (s *StepRequestValidation) AssertGreater(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertGreaterOrEqual

func (s *StepRequestValidation) AssertGreaterOrEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLengthEqual

func (s *StepRequestValidation) AssertLengthEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLengthGreaterOrEquals

func (s *StepRequestValidation) AssertLengthGreaterOrEquals(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLengthGreaterThan

func (s *StepRequestValidation) AssertLengthGreaterThan(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLengthLessOrEquals

func (s *StepRequestValidation) AssertLengthLessOrEquals(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLengthLessThan

func (s *StepRequestValidation) AssertLengthLessThan(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLess

func (s *StepRequestValidation) AssertLess(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertLessOrEqual

func (s *StepRequestValidation) AssertLessOrEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertNotEqual

func (s *StepRequestValidation) AssertNotEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertRegexp

func (s *StepRequestValidation) AssertRegexp(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertStartsWith

func (s *StepRequestValidation) AssertStartsWith(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertStringEqual

func (s *StepRequestValidation) AssertStringEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) AssertTypeMatch

func (s *StepRequestValidation) AssertTypeMatch(jmesPath string, expected interface{}, msg string) *StepRequestValidation

func (*StepRequestValidation) Name

func (s *StepRequestValidation) Name() string

func (*StepRequestValidation) Run

func (*StepRequestValidation) Struct

func (s *StepRequestValidation) Struct() *TStep

func (*StepRequestValidation) Type

func (s *StepRequestValidation) Type() StepType

type StepRequestWithOptionalArgs

type StepRequestWithOptionalArgs struct {
	// contains filtered or unexported fields
}

StepRequestWithOptionalArgs implements IStep interface.

func (*StepRequestWithOptionalArgs) Extract

Extract switches to step extraction.

func (*StepRequestWithOptionalArgs) Name

func (*StepRequestWithOptionalArgs) Run

func (*StepRequestWithOptionalArgs) SetAllowRedirects

func (s *StepRequestWithOptionalArgs) SetAllowRedirects(allowRedirects bool) *StepRequestWithOptionalArgs

SetAllowRedirects sets whether to allow redirects for current HTTP request.

func (*StepRequestWithOptionalArgs) SetAuth

SetAuth sets auth for current HTTP request.

func (*StepRequestWithOptionalArgs) SetProxies

SetProxies sets proxies for current HTTP request.

func (*StepRequestWithOptionalArgs) SetTimeout

SetTimeout sets timeout for current HTTP request.

func (*StepRequestWithOptionalArgs) SetVerify

SetVerify sets whether to verify SSL for current HTTP request.

func (*StepRequestWithOptionalArgs) Struct

func (s *StepRequestWithOptionalArgs) Struct() *TStep

func (*StepRequestWithOptionalArgs) TeardownHook

TeardownHook adds a teardown hook for current teststep.

func (*StepRequestWithOptionalArgs) Type

func (*StepRequestWithOptionalArgs) Validate

Validate switches to step validation.

func (*StepRequestWithOptionalArgs) WithBody

func (s *StepRequestWithOptionalArgs) WithBody(body interface{}) *StepRequestWithOptionalArgs

WithBody sets HTTP request body for current step.

func (*StepRequestWithOptionalArgs) WithCookies

WithCookies sets HTTP request cookies for current step.

func (*StepRequestWithOptionalArgs) WithHeaders

WithHeaders sets HTTP request headers for current step.

func (*StepRequestWithOptionalArgs) WithParams

func (s *StepRequestWithOptionalArgs) WithParams(params map[string]interface{}) *StepRequestWithOptionalArgs

WithParams sets HTTP request params for current step.

func (*StepRequestWithOptionalArgs) WithUpload

func (s *StepRequestWithOptionalArgs) WithUpload(upload map[string]interface{}) *StepRequestWithOptionalArgs

WithUpload sets HTTP request body for uploading file(s).

type StepResult

type StepResult struct {
	Name        string                 `json:"name" yaml:"name"`                                   // step name
	StepType    StepType               `json:"step_type" yaml:"step_type"`                         // step type, testcase/request/transaction/rendezvous
	Success     bool                   `json:"success" yaml:"success"`                             // step execution result
	Elapsed     int64                  `json:"elapsed_ms" yaml:"elapsed_ms"`                       // step execution time in millisecond(ms)
	HttpStat    map[string]int64       `json:"httpstat,omitempty" yaml:"httpstat,omitempty"`       // httpstat in millisecond(ms)
	Data        interface{}            `json:"data,omitempty" yaml:"data,omitempty"`               // session data or slice of step data
	ContentSize int64                  `json:"content_size" yaml:"content_size"`                   // response body length
	ExportVars  map[string]interface{} `json:"export_vars,omitempty" yaml:"export_vars,omitempty"` // extract variables
	Attachments interface{}            `json:"attachments,omitempty" yaml:"attachments,omitempty"` // store extra step information, such as error message or screenshots
}

StepResult 测试报告结构体

type StepTestCaseWithOptionalArgs

type StepTestCaseWithOptionalArgs struct {
	// contains filtered or unexported fields
}

StepTestCaseWithOptionalArgs implements IStep interface.

func (*StepTestCaseWithOptionalArgs) Export

Export specifies variable names to export from referenced testcase for current step.

func (*StepTestCaseWithOptionalArgs) Name

func (*StepTestCaseWithOptionalArgs) Run

func (s *StepTestCaseWithOptionalArgs) Run(r *SessionRunner) (stepResult *StepResult, err error)

func (*StepTestCaseWithOptionalArgs) Struct

func (s *StepTestCaseWithOptionalArgs) Struct() *TStep

func (*StepTestCaseWithOptionalArgs) TeardownHook

TeardownHook adds a teardown hook for current teststep.

func (*StepTestCaseWithOptionalArgs) Type

type StepThinkTime

type StepThinkTime struct {
	// contains filtered or unexported fields
}

StepThinkTime implements IStep interface.

func (*StepThinkTime) Name

func (s *StepThinkTime) Name() string

func (*StepThinkTime) Run

func (*StepThinkTime) Struct

func (s *StepThinkTime) Struct() *TStep

func (*StepThinkTime) Type

func (s *StepThinkTime) Type() StepType

type StepTransaction

type StepTransaction struct {
	// contains filtered or unexported fields
}

StepTransaction implements IStep interface.

func (*StepTransaction) Name

func (s *StepTransaction) Name() string

func (*StepTransaction) Run

func (*StepTransaction) Struct

func (s *StepTransaction) Struct() *TStep

func (*StepTransaction) Type

func (s *StepTransaction) Type() StepType

type StepType

type StepType string

type StepWebSocket

type StepWebSocket struct {
	// contains filtered or unexported fields
}

StepWebSocket implements IStep interface.

func (*StepWebSocket) CloseConnection

func (s *StepWebSocket) CloseConnection(url ...string) *StepWebSocket

func (*StepWebSocket) Extract

func (s *StepWebSocket) Extract() *StepRequestExtraction

Extract switches to step extraction.

func (*StepWebSocket) Name

func (s *StepWebSocket) Name() string

func (*StepWebSocket) NewConnection

func (s *StepWebSocket) NewConnection() *StepWebSocket

func (*StepWebSocket) OpenConnection

func (s *StepWebSocket) OpenConnection(url ...string) *StepWebSocket

func (*StepWebSocket) PingPong

func (s *StepWebSocket) PingPong(url ...string) *StepWebSocket

func (*StepWebSocket) Read

func (s *StepWebSocket) Read(url ...string) *StepWebSocket

func (*StepWebSocket) Run

func (*StepWebSocket) Struct

func (s *StepWebSocket) Struct() *TStep

func (*StepWebSocket) Type

func (s *StepWebSocket) Type() StepType

func (*StepWebSocket) Validate

func (s *StepWebSocket) Validate() *StepRequestValidation

Validate switches to step validation.

func (*StepWebSocket) WithBinaryMessage

func (s *StepWebSocket) WithBinaryMessage(message interface{}) *StepWebSocket

func (*StepWebSocket) WithCloseStatus

func (s *StepWebSocket) WithCloseStatus(closeStatus int64) *StepWebSocket

func (*StepWebSocket) WithHeaders

func (s *StepWebSocket) WithHeaders(headers map[string]string) *StepWebSocket

func (*StepWebSocket) WithParams

func (s *StepWebSocket) WithParams(params map[string]interface{}) *StepWebSocket

func (*StepWebSocket) WithTextMessage

func (s *StepWebSocket) WithTextMessage(message interface{}) *StepWebSocket

func (*StepWebSocket) WithTimeout

func (s *StepWebSocket) WithTimeout(timeout int64) *StepWebSocket

func (*StepWebSocket) Write

func (s *StepWebSocket) Write(url ...string) *StepWebSocket

func (*StepWebSocket) WriteAndRead

func (s *StepWebSocket) WriteAndRead(url ...string) *StepWebSocket

type StopRequestBody

type StopRequestBody struct {
	Worker string `json:"worker"`
}

type Summary

type Summary struct {
	Success  bool               `json:"success" yaml:"success"`
	Stat     *Stat              `json:"stat" yaml:"stat"`
	Time     *TestCaseTime      `json:"time" yaml:"time"`
	Platform *Platform          `json:"platform" yaml:"platform"`
	Details  []*TestCaseSummary `json:"details" yaml:"details"`
	// contains filtered or unexported fields
}

Summary stores tests summary for current task execution, maybe include one or multiple testcases

type TCase

type TCase struct {
	Config    *TConfig `json:"config" yaml:"config"`
	TestSteps []*TStep `json:"teststeps" yaml:"teststeps"`
}

TCase represents testcase data structure. Each testcase includes one public config and several sequential teststeps.

func (*TCase) MakeCompat

func (tc *TCase) MakeCompat() (err error)

MakeCompat converts TCase compatible with Golang engine style 目的是使TCase结构与Golang引擎风格兼容。它通过对TCase对象及其相关的TestSteps执行某些兼容性转换来实现

func (*TCase) ToTestCase

func (tc *TCase) ToTestCase(casePath string) (*TestCase, error)

type TConfig

type TConfig struct {
	Name              string                 `json:"name" yaml:"name"` // required
	Verify            bool                   `json:"verify,omitempty" yaml:"verify,omitempty"`
	BaseURL           string                 `json:"base_url,omitempty" yaml:"base_url,omitempty"`   // deprecated in v4.1, moved to env
	Headers           map[string]string      `json:"headers,omitempty" yaml:"headers,omitempty"`     // public request headers
	Environs          map[string]string      `json:"environs,omitempty" yaml:"environs,omitempty"`   // environment variables
	Variables         map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"` // global variables
	Parameters        map[string]interface{} `json:"parameters,omitempty" yaml:"parameters,omitempty"`
	ParametersSetting *TParamsConfig         `json:"parameters_setting,omitempty" yaml:"parameters_setting,omitempty"`
	ThinkTimeSetting  *ThinkTimeConfig       `json:"think_time,omitempty" yaml:"think_time,omitempty"`
	WebSocketSetting  *WebSocketConfig       `json:"websocket,omitempty" yaml:"websocket,omitempty"`
	IOS               []*uixt.IOSDevice      `json:"ios,omitempty" yaml:"ios,omitempty"`
	Android           []*uixt.AndroidDevice  `json:"android,omitempty" yaml:"android,omitempty"`
	Timeout           float64                `json:"timeout,omitempty" yaml:"timeout,omitempty"` // global timeout in seconds
	Export            []string               `json:"export,omitempty" yaml:"export,omitempty"`
	Weight            int                    `json:"weight,omitempty" yaml:"weight,omitempty"`
	Path              string                 `json:"path,omitempty" yaml:"path,omitempty"`     // testcase file path
	PluginSetting     *PluginConfig          `json:"plugin,omitempty" yaml:"plugin,omitempty"` // plugin config
}

TConfig represents config data structure for testcase. Each testcase should contain one config part.

func NewConfig

func NewConfig(name string) *TConfig

NewConfig returns a new constructed testcase config with specified testcase name.

func (*TConfig) ExportVars

func (c *TConfig) ExportVars(vars ...string) *TConfig

ExportVars specifies variable names to export for current testcase.

func (*TConfig) SetAndroid

func (c *TConfig) SetAndroid(options ...uixt.AndroidDeviceOption) *TConfig

func (*TConfig) SetBaseURL

func (c *TConfig) SetBaseURL(baseURL string) *TConfig

SetBaseURL sets base URL for current testcase.

func (*TConfig) SetHeaders

func (c *TConfig) SetHeaders(headers map[string]string) *TConfig

SetHeaders sets global headers for current testcase.

func (*TConfig) SetIOS

func (c *TConfig) SetIOS(options ...uixt.IOSDeviceOption) *TConfig

func (*TConfig) SetThinkTime

func (c *TConfig) SetThinkTime(strategy thinkTimeStrategy, cfg interface{}, limit float64) *TConfig

SetThinkTime sets think time config for current testcase.

func (*TConfig) SetTimeout

func (c *TConfig) SetTimeout(timeout time.Duration) *TConfig

SetTimeout sets testcase timeout in seconds.

func (*TConfig) SetVerifySSL

func (c *TConfig) SetVerifySSL(verify bool) *TConfig

SetVerifySSL sets whether to verify SSL for current testcase.

func (*TConfig) SetWebSocket

func (c *TConfig) SetWebSocket(times, interval, timeout, size int64) *TConfig

func (*TConfig) SetWeight

func (c *TConfig) SetWeight(weight int) *TConfig

SetWeight sets weight for current testcase, which is used in load testing.

func (*TConfig) WithParameters

func (c *TConfig) WithParameters(parameters map[string]interface{}) *TConfig

WithParameters sets parameters for current testcase.

func (*TConfig) WithVariables

func (c *TConfig) WithVariables(variables map[string]interface{}) *TConfig

WithVariables sets variables for current testcase.

type TParamsConfig

type TParamsConfig struct {
	PickOrder  iteratorPickOrder           `json:"pick_order,omitempty" yaml:"pick_order,omitempty"` // overall pick-order strategy
	Strategies map[string]iteratorStrategy `json:"strategies,omitempty" yaml:"strategies,omitempty"` // individual strategies for each parameters
	Limit      int                         `json:"limit,omitempty" yaml:"limit,omitempty"`
}

type TStep

type TStep struct {
	Name          string                 `json:"name" yaml:"name"` // required
	Request       *Request               `json:"request,omitempty" yaml:"request,omitempty"`
	API           interface{}            `json:"api,omitempty" yaml:"api,omitempty"`           // *APIPath or *API
	TestCase      interface{}            `json:"testcase,omitempty" yaml:"testcase,omitempty"` // *TestCasePath or *TestCase
	Transaction   *Transaction           `json:"transaction,omitempty" yaml:"transaction,omitempty"`
	Rendezvous    *Rendezvous            `json:"rendezvous,omitempty" yaml:"rendezvous,omitempty"`
	ThinkTime     *ThinkTime             `json:"think_time,omitempty" yaml:"think_time,omitempty"`
	WebSocket     *WebSocketAction       `json:"websocket,omitempty" yaml:"websocket,omitempty"`
	Android       *MobileStep            `json:"android,omitempty" yaml:"android,omitempty"`
	IOS           *MobileStep            `json:"ios,omitempty" yaml:"ios,omitempty"`
	Variables     map[string]interface{} `json:"variables,omitempty" yaml:"variables,omitempty"`
	SetupHooks    []string               `json:"setup_hooks,omitempty" yaml:"setup_hooks,omitempty"`
	TeardownHooks []string               `json:"teardown_hooks,omitempty" yaml:"teardown_hooks,omitempty"`
	Extract       map[string]string      `json:"extract,omitempty" yaml:"extract,omitempty"`
	Validators    []interface{}          `json:"validate,omitempty" yaml:"validate,omitempty"`
	Export        []string               `json:"export,omitempty" yaml:"export,omitempty"`
	Loops         int                    `json:"loops,omitempty" yaml:"loops,omitempty"`
}

TStep represents teststep data structure. Each step maybe three different types: make one request or reference another api/testcase. 测试步骤结构体

type TestCase

type TestCase struct {
	Config    *TConfig
	TestSteps []IStep
}

TestCase is a container for one testcase, which is used for testcase runner. TestCase implements ITestCase interface.

func LoadTestCases

func LoadTestCases(iTestCases ...ITestCase) ([]*TestCase, error)

func (*TestCase) Dump2JSON

func (tc *TestCase) Dump2JSON(targetPath string) error

func (*TestCase) Dump2YAML

func (tc *TestCase) Dump2YAML(targetPath string) error

func (*TestCase) GetPath

func (tc *TestCase) GetPath() string

func (*TestCase) ToTCase

func (tc *TestCase) ToTCase() *TCase

func (*TestCase) ToTestCase

func (tc *TestCase) ToTestCase() (*TestCase, error)

type TestCaseInOut

type TestCaseInOut struct {
	ConfigVars map[string]interface{} `json:"config_vars" yaml:"config_vars"`
	ExportVars map[string]interface{} `json:"export_vars" yaml:"export_vars"`
}

type TestCasePath

type TestCasePath string

TestCasePath implements ITestCase interface.

func (*TestCasePath) GetPath

func (path *TestCasePath) GetPath() string

func (*TestCasePath) ToTestCase

func (path *TestCasePath) ToTestCase() (*TestCase, error)

ToTestCase loads testcase path and convert to *TestCase

type TestCaseStat

type TestCaseStat struct {
	Total   int `json:"total" yaml:"total"`
	Success int `json:"success" yaml:"success"`
	Fail    int `json:"fail" yaml:"fail"`
}

type TestCaseSummary

type TestCaseSummary struct {
	Name    string         `json:"name" yaml:"name"`
	Success bool           `json:"success" yaml:"success"`
	CaseId  string         `json:"case_id,omitempty" yaml:"case_id,omitempty"` // TODO
	Stat    *TestStepStat  `json:"stat" yaml:"stat"`
	Time    *TestCaseTime  `json:"time" yaml:"time"`
	InOut   *TestCaseInOut `json:"in_out" yaml:"in_out"`
	Logs    []interface{}  `json:"logs,omitempty" yaml:"logs,omitempty"`
	Records []*StepResult  `json:"records" yaml:"records"`
	RootDir string         `json:"root_dir" yaml:"root_dir"`
}

TestCaseSummary stores tests summary for one testcase

type TestCaseTime

type TestCaseTime struct {
	StartAt  time.Time `json:"start_at,omitempty" yaml:"start_at,omitempty"`
	Duration float64   `json:"duration,omitempty" yaml:"duration,omitempty"`
}

type TestStepStat

type TestStepStat struct {
	Total     int `json:"total" yaml:"total"`
	Successes int `json:"successes" yaml:"successes"`
	Failures  int `json:"failures" yaml:"failures"`
}

type ThinkTime

type ThinkTime struct {
	Time float64 `json:"time" yaml:"time"`
}

type ThinkTimeConfig

type ThinkTimeConfig struct {
	Strategy thinkTimeStrategy `json:"strategy,omitempty" yaml:"strategy,omitempty"` // default、random、multiply、ignore
	Setting  interface{}       `json:"setting,omitempty" yaml:"setting,omitempty"`   // random(map): {"min_percentage": 0.5, "max_percentage": 1.5}; 10、multiply(float64): 1.5
	Limit    float64           `json:"limit,omitempty" yaml:"limit,omitempty"`       // limit think time no more than specific time, ignore if value <= 0
}

type Transaction

type Transaction struct {
	Name string          `json:"name" yaml:"name"`
	Type transactionType `json:"type" yaml:"type"`
}

type ValidationResult

type ValidationResult struct {
	Validator
	CheckValue  interface{} `json:"check_value" yaml:"check_value"`
	CheckResult string      `json:"check_result" yaml:"check_result"`
}

type Validator

type Validator struct {
	Check   string      `json:"check" yaml:"check"` // get value with jmespath
	Assert  string      `json:"assert" yaml:"assert"`
	Expect  interface{} `json:"expect" yaml:"expect"`
	Message string      `json:"msg,omitempty" yaml:"msg,omitempty"` // optional
}

Validator represents validator for one HTTP response.

type WebSocketAction

type WebSocketAction struct {
	Type            ActionType             `json:"type" yaml:"type"`
	URL             string                 `json:"url" yaml:"url"`
	Params          map[string]interface{} `json:"params,omitempty" yaml:"params,omitempty"`
	Headers         map[string]string      `json:"headers,omitempty" yaml:"headers,omitempty"`
	NewConnection   bool                   `json:"new_connection,omitempty" yaml:"new_connection,omitempty"` // TODO support
	TextMessage     interface{}            `json:"text,omitempty" yaml:"text,omitempty"`
	BinaryMessage   interface{}            `json:"binary,omitempty" yaml:"binary,omitempty"`
	CloseStatusCode int64                  `json:"close_status,omitempty" yaml:"close_status,omitempty"`
	Timeout         int64                  `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}

func (*WebSocketAction) GetCloseStatusCode

func (w *WebSocketAction) GetCloseStatusCode() int64

func (*WebSocketAction) GetTimeout

func (w *WebSocketAction) GetTimeout() int64

type WebSocketConfig

type WebSocketConfig struct {
	ReconnectionTimes    int64 `json:"reconnection_times,omitempty" yaml:"reconnection_times,omitempty"`       // maximum reconnection times when the connection closed by remote server
	ReconnectionInterval int64 `json:"reconnection_interval,omitempty" yaml:"reconnection_interval,omitempty"` // interval between each reconnection in milliseconds
	MaxMessageSize       int64 `json:"max_message_size,omitempty" yaml:"max_message_size,omitempty"`           // maximum message size during writing/reading
}

WebSocketConfig TODO: support reconnection ability

Directories

Path Synopsis
cmd
adb
cli
ios
internal
env
scaffold/templates/plugin
NOTE: Generated By hrp v4.3.3, DO NOT EDIT!
NOTE: Generated By hrp v4.3.3, DO NOT EDIT!
sdk
pkg
httpstat
Package httpstat traces HTTP latency infomation (DNSLookup, TCP Connection and so on) on any golang HTTP request.
Package httpstat traces HTTP latency infomation (DNSLookup, TCP Connection and so on) on any golang HTTP request.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL