refactor: TestCase/TestCaseDef/StepConfig models

This commit is contained in:
lilong.129
2024-11-09 20:15:40 +08:00
parent 2587bbee82
commit 8846e84d19
31 changed files with 621 additions and 563 deletions
+3 -3
View File
@@ -94,12 +94,12 @@ func init() {
}
// LoadCurlCase loads testcase from one or more curl commands in .txt file
func LoadCurlCase(path string) (*hrp.TestCase, error) {
func LoadCurlCase(path string) (*hrp.TestCaseDef, error) {
cmds, err := readFileLines(path)
if err != nil {
return nil, err
}
tCase := &hrp.TestCase{
tCase := &hrp.TestCaseDef{
Config: &hrp.TConfig{
Name: "testcase converted from curl command",
},
@@ -307,7 +307,7 @@ type stepFromCurl struct {
}
func (s *stepFromCurl) makeRequestName(c CaseCurl) error {
s.Name = c.Get(originCmdKey, 0)
s.StepName = c.Get(originCmdKey, 0)
return nil
}
+1 -1
View File
@@ -18,7 +18,7 @@ func TestLoadCurlCase(t *testing.T) {
}
// curl httpbin.org
if !assert.Equal(t, "curl httpbin.org", tCase.Steps[0].Name) {
if !assert.Equal(t, "curl httpbin.org", tCase.Steps[0].StepName) {
t.Fatal()
}
if !assert.EqualValues(t, "GET", tCase.Steps[0].Request.Method) {
+7 -5
View File
@@ -357,7 +357,7 @@ type TestResult struct {
// ==================== model definition ends here ====================
func LoadHARCase(path string) (*hrp.TestCase, error) {
func LoadHARCase(path string) (*hrp.TestCaseDef, error) {
// load har file
caseHAR, err := loadCaseHAR(path)
if err != nil {
@@ -381,13 +381,13 @@ func loadCaseHAR(path string) (*CaseHar, error) {
}
// convert CaseHar to TestCase format
func (c *CaseHar) ToTestCase() (*hrp.TestCase, error) {
func (c *CaseHar) ToTestCase() (*hrp.TestCaseDef, error) {
teststeps, err := c.prepareTestSteps()
if err != nil {
return nil, err
}
tCase := &hrp.TestCase{
tCase := &hrp.TestCaseDef{
Config: c.prepareConfig(),
Steps: teststeps,
}
@@ -424,8 +424,10 @@ func (c *CaseHar) prepareTestStep(entry *Entry) (*hrp.TStep, error) {
step := &stepFromHAR{
TStep: hrp.TStep{
Request: &hrp.Request{},
Validators: make([]interface{}, 0),
Request: &hrp.Request{},
StepConfig: hrp.StepConfig{
Validators: make([]interface{}, 0),
},
},
}
if err := step.makeRequestMethod(entry); err != nil {
+2 -2
View File
@@ -7,9 +7,9 @@ import (
"github.com/httprunner/httprunner/v4/hrp"
)
func LoadJSONCase(path string) (*hrp.TestCase, error) {
func LoadJSONCase(path string) (*hrp.TestCaseDef, error) {
log.Info().Str("path", path).Msg("load json case file")
caseJSON := new(hrp.TestCase)
caseJSON := new(hrp.TestCaseDef)
err := hrp.LoadFileObject(path, caseJSON)
if err != nil {
return nil, errors.Wrap(err, "load json file failed")
+8 -6
View File
@@ -111,7 +111,7 @@ var contentTypeMap = map[string]string{
"xml": "application/xml",
}
func LoadPostmanCase(path string) (*hrp.TestCase, error) {
func LoadPostmanCase(path string) (*hrp.TestCaseDef, error) {
log.Info().Str("path", path).Msg("load postman case file")
casePostman, err := loadCasePostman(path)
if err != nil {
@@ -135,12 +135,12 @@ func loadCasePostman(path string) (*CasePostman, error) {
return casePostman, nil
}
func (c *CasePostman) ToTestCase() (*hrp.TestCase, error) {
func (c *CasePostman) ToTestCase() (*hrp.TestCaseDef, error) {
teststeps, err := c.prepareTestSteps()
if err != nil {
return nil, err
}
tCase := &hrp.TestCase{
tCase := &hrp.TestCaseDef{
Config: c.prepareConfig(),
Steps: teststeps,
}
@@ -199,8 +199,10 @@ func (c *CasePostman) prepareTestStep(item *TItem) (*hrp.TStep, error) {
step := &stepFromPostman{
TStep: hrp.TStep{
Request: &hrp.Request{},
Validators: make([]interface{}, 0),
Request: &hrp.Request{},
StepConfig: hrp.StepConfig{
Validators: make([]interface{}, 0),
},
},
}
if err := step.makeRequestName(item); err != nil {
@@ -233,7 +235,7 @@ type stepFromPostman struct {
// makeRequestName indicates the step name the same as item name
func (s *stepFromPostman) makeRequestName(item *TItem) error {
s.Name = item.Name
s.StepName = item.Name
return nil
}
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/httprunner/httprunner/v4/hrp"
)
func LoadSwaggerCase(path string) (*hrp.TestCase, error) {
func LoadSwaggerCase(path string) (*hrp.TestCaseDef, error) {
// load swagger file
caseSwagger := new(spec.Swagger)
err := hrp.LoadFileObject(path, caseSwagger)
+2 -2
View File
@@ -8,9 +8,9 @@ import (
"github.com/httprunner/httprunner/v4/hrp"
)
func LoadYAMLCase(path string) (*hrp.TestCase, error) {
func LoadYAMLCase(path string) (*hrp.TestCaseDef, error) {
// load yaml case file
caseJSON := new(hrp.TestCase)
caseJSON := new(hrp.TestCaseDef)
err := hrp.LoadFileObject(path, caseJSON)
if err != nil {
return nil, errors.Wrap(err, "load yaml file failed")
+1 -1
View File
@@ -114,7 +114,7 @@ type TCaseConverter struct {
fromFile string
profilePath string
outputDir string
tCase *hrp.TestCase
tCase *hrp.TestCaseDef
}
// LoadCase loads source file and convert to TCase type
+2 -2
View File
@@ -60,7 +60,7 @@ func TestLoadHARWithProfileOverride(t *testing.T) {
func TestMakeRequestWithProfile(t *testing.T) {
caseConverter := &TCaseConverter{
tCase: &hrp.TestCase{
tCase: &hrp.TestCaseDef{
Steps: []*hrp.TStep{
{
Request: &hrp.Request{
@@ -101,7 +101,7 @@ func TestMakeRequestWithProfile(t *testing.T) {
func TestMakeRequestWithProfileOverride(t *testing.T) {
caseConverter := &TCaseConverter{
tCase: &hrp.TestCase{
tCase: &hrp.TestCaseDef{
Steps: []*hrp.TStep{
{
Request: &hrp.Request{
+16 -14
View File
@@ -32,19 +32,6 @@ const (
ACTION_SetIme ActionMethod = "set_ime"
ACTION_GetSource ActionMethod = "get_source"
// UI validation
// selectors
SelectorName string = "ui_name"
SelectorLabel string = "ui_label"
SelectorOCR string = "ui_ocr"
SelectorImage string = "ui_image"
SelectorForegroundApp string = "ui_foreground_app"
// assertions
AssertionEqual string = "equal"
AssertionNotEqual string = "not_equal"
AssertionExists string = "exists"
AssertionNotExists string = "not_exists"
// UI handling
ACTION_Home ActionMethod = "home"
ACTION_TapXY ActionMethod = "tap_xy"
@@ -69,6 +56,21 @@ const (
ACTION_DownloadApp ActionMethod = "download_app"
)
const (
// UI validation
// selectors
SelectorName string = "ui_name"
SelectorLabel string = "ui_label"
SelectorOCR string = "ui_ocr"
SelectorImage string = "ui_image"
SelectorForegroundApp string = "ui_foreground_app"
// assertions
AssertionEqual string = "equal"
AssertionNotEqual string = "not_equal"
AssertionExists string = "exists"
AssertionNotExists string = "not_exists"
)
type MobileAction struct {
Method ActionMethod `json:"method,omitempty" yaml:"method,omitempty"`
Params interface{} `json:"params,omitempty" yaml:"params,omitempty"`
@@ -741,7 +743,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) (err error) {
case ACTION_ClosePopups:
return dExt.ClosePopupsHandler()
case ACTION_EndToEndDelay:
dExt.CollectEndToEndDelay(action.GetOptions()...)
CollectEndToEndDelay(dExt, action.GetOptions()...)
return nil
}
return nil
+1 -1
View File
@@ -476,7 +476,7 @@ func WithDriverPlugin(plugin funplugin.IPlugin) DriverOption {
}
}
// current implemeted device: IOSDevice, AndroidDevice
// current implemeted device: IOSDevice, AndroidDevice, HarmonyDevice
type IDevice interface {
Init() error // init android device
UUID() string // ios udid or android serial
+1 -1
View File
@@ -28,7 +28,7 @@ type EndToEndDelay struct {
Timelines []timeLog `json:"timelines"`
}
func (dExt *DriverExt) CollectEndToEndDelay(options ...ActionOption) {
func CollectEndToEndDelay(dExt *DriverExt, options ...ActionOption) {
dataOptions := NewActionOptions(options...)
startTime := time.Now()