mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-13 00:11:28 +08:00
fix: exit with code
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
@@ -20,5 +21,5 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
cmd.Execute()
|
os.Exit(cmd.Execute())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/cmd/adb"
|
"github.com/httprunner/httprunner/v4/hrp/cmd/adb"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/cmd/ios"
|
"github.com/httprunner/httprunner/v4/hrp/cmd/ios"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
"github.com/httprunner/httprunner/v4/hrp/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,7 +46,8 @@ Copyright 2017 debugtalk`,
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Version: version.VERSION,
|
Version: version.VERSION,
|
||||||
TraverseChildren: true,
|
TraverseChildren: true, // parses flags on all parents before executing child command
|
||||||
|
SilenceUsage: true, // silence usage when an error occurs
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -56,7 +58,7 @@ var (
|
|||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
func Execute() {
|
func Execute() int {
|
||||||
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
|
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
|
||||||
rootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format")
|
rootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format")
|
||||||
rootCmd.PersistentFlags().StringVar(&venv, "venv", "", "specify python3 venv path")
|
rootCmd.PersistentFlags().StringVar(&venv, "venv", "", "specify python3 venv path")
|
||||||
@@ -64,9 +66,8 @@ func Execute() {
|
|||||||
ios.Init(rootCmd)
|
ios.Init(rootCmd)
|
||||||
adb.Init(rootCmd)
|
adb.Init(rootCmd)
|
||||||
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
err := rootCmd.Execute()
|
||||||
os.Exit(1)
|
return code.GetErrorCode(err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setLogLevel(level string) {
|
func setLogLevel(level string) {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp"
|
"github.com/httprunner/httprunner/v4/hrp"
|
||||||
@@ -20,17 +18,14 @@ var runCmd = &cobra.Command{
|
|||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
setLogLevel(logLevel)
|
setLogLevel(logLevel)
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
var paths []hrp.ITestCase
|
var paths []hrp.ITestCase
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
path := hrp.TestCasePath(arg)
|
path := hrp.TestCasePath(arg)
|
||||||
paths = append(paths, &path)
|
paths = append(paths, &path)
|
||||||
}
|
}
|
||||||
runner := makeHRPRunner()
|
runner := makeHRPRunner()
|
||||||
err := runner.Run(paths...)
|
return runner.Run(paths...)
|
||||||
if err != nil {
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,30 +21,45 @@ var (
|
|||||||
|
|
||||||
// runner: [60, 100)
|
// runner: [60, 100)
|
||||||
|
|
||||||
// ios related: [100, 120)
|
// ios related: [100, 130)
|
||||||
var (
|
var (
|
||||||
IOSScreenShotError = errors.New("ios screenshot error") // 100
|
IOSScreenShotError = errors.New("ios screenshot error") // 110
|
||||||
)
|
)
|
||||||
|
|
||||||
// android related: [120, 140)
|
// android related: [130, 160)
|
||||||
|
|
||||||
// OCR related: [140, 160)
|
|
||||||
var (
|
var (
|
||||||
OCREnvMissedError = errors.New("veDEM OCR env missed error") // 140
|
AndroidScreenShotError = errors.New("android screenshot error") // 150
|
||||||
OCRRequestError = errors.New("vedem ocr prepare request error") // 141
|
|
||||||
OCRServiceConnectionError = errors.New("vedem ocr service connect error") // 142
|
|
||||||
OCRResponseStatusCodeNot200 = errors.New("vedem ocr response status code is not 200") // 143
|
|
||||||
OCRResponseError = errors.New("vedem ocr parse response error") // 143
|
|
||||||
OCRTextNotFoundError = errors.New("vedem ocr text not found") // 144
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CV related: [160, 180)
|
// OCR related: [160, 180)
|
||||||
|
var (
|
||||||
|
OCREnvMissedError = errors.New("veDEM OCR env missed error") // 160
|
||||||
|
OCRRequestError = errors.New("vedem ocr prepare request error") // 161
|
||||||
|
OCRServiceConnectionError = errors.New("vedem ocr service connect error") // 162
|
||||||
|
OCRResponseError = errors.New("vedem ocr parse response error") // 163
|
||||||
|
OCRTextNotFoundError = errors.New("vedem ocr text not found") // 164
|
||||||
|
)
|
||||||
|
|
||||||
|
// CV related: [180, 200)
|
||||||
|
|
||||||
// report related: [200, 220)
|
// report related: [200, 220)
|
||||||
|
|
||||||
var errorsMap = map[error]int{
|
var errorsMap = map[error]int{
|
||||||
LoadJSONError: 10,
|
LoadJSONError: 10,
|
||||||
LoadYAMLError: 11,
|
LoadYAMLError: 11,
|
||||||
|
|
||||||
|
// ios related
|
||||||
|
IOSScreenShotError: 110,
|
||||||
|
|
||||||
|
// android related
|
||||||
|
AndroidScreenShotError: 130,
|
||||||
|
|
||||||
|
// OCR related
|
||||||
|
OCREnvMissedError: 160,
|
||||||
|
OCRRequestError: 161,
|
||||||
|
OCRServiceConnectionError: 162,
|
||||||
|
OCRResponseError: 163,
|
||||||
|
OCRTextNotFoundError: 164,
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetErrorCode(err error) int {
|
func GetErrorCode(err error) int {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v4.3.0-beta-10161439
|
v4.3.0-beta-10172144
|
||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -13,7 +12,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/electricbubble/gadb"
|
"github.com/electricbubble/gadb"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errDriverNotImplemented = errors.New("driver method not implemented")
|
var errDriverNotImplemented = errors.New("driver method not implemented")
|
||||||
@@ -860,7 +862,8 @@ func (ud *uiaDriver) Screenshot() (raw *bytes.Buffer, err error) {
|
|||||||
// register(getHandler, new CaptureScreenshot("/wd/hub/session/:sessionId/screenshot"))
|
// register(getHandler, new CaptureScreenshot("/wd/hub/session/:sessionId/screenshot"))
|
||||||
var rawResp rawResponse
|
var rawResp rawResponse
|
||||||
if rawResp, err = ud.httpGET("/session", ud.sessionId, "screenshot"); err != nil {
|
if rawResp, err = ud.httpGET("/session", ud.sessionId, "screenshot"); err != nil {
|
||||||
return nil, err
|
return nil, errors.Wrap(code.AndroidScreenShotError,
|
||||||
|
fmt.Sprintf("get UIA screenshot data failed: %v", err))
|
||||||
}
|
}
|
||||||
reply := new(struct{ Value string })
|
reply := new(struct{ Value string })
|
||||||
if err = json.Unmarshal(rawResp, reply); err != nil {
|
if err = json.Unmarshal(rawResp, reply); err != nil {
|
||||||
@@ -869,7 +872,8 @@ func (ud *uiaDriver) Screenshot() (raw *bytes.Buffer, err error) {
|
|||||||
|
|
||||||
var decodeStr []byte
|
var decodeStr []byte
|
||||||
if decodeStr, err = base64.StdEncoding.DecodeString(reply.Value); err != nil {
|
if decodeStr, err = base64.StdEncoding.DecodeString(reply.Value); err != nil {
|
||||||
return nil, err
|
return nil, errors.Wrap(code.AndroidScreenShotError,
|
||||||
|
fmt.Sprintf("decode UIA screenshot data failed: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
raw = bytes.NewBuffer(decodeStr)
|
raw = bytes.NewBuffer(decodeStr)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const (
|
|||||||
// It may help to prevent out of memory or timeout errors while getting the elements source tree,
|
// It may help to prevent out of memory or timeout errors while getting the elements source tree,
|
||||||
// but it might restrict the depth of source tree.
|
// but it might restrict the depth of source tree.
|
||||||
// A part of elements source tree might be lost if the value was too small. Defaults to 50
|
// A part of elements source tree might be lost if the value was too small. Defaults to 50
|
||||||
snapshotMaxDepth = 16
|
snapshotMaxDepth = 10
|
||||||
// Allows to customize accept/dismiss alert button selector.
|
// Allows to customize accept/dismiss alert button selector.
|
||||||
// It helps you to handle an arbitrary element as accept button in accept alert command.
|
// It helps you to handle an arbitrary element as accept button in accept alert command.
|
||||||
// The selector should be a valid class chain expression, where the search root is the alert element itself.
|
// The selector should be a valid class chain expression, where the search root is the alert element itself.
|
||||||
|
|||||||
@@ -96,7 +96,11 @@ func (s *veDEMOCRService) getOCRResult(imageBuf []byte) ([]OCRResult, error) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
logID := getLogID(resp.Header)
|
|
||||||
|
var logID string
|
||||||
|
if resp != nil {
|
||||||
|
logID = getLogID(resp.Header)
|
||||||
|
}
|
||||||
log.Error().Err(err).
|
log.Error().Err(err).
|
||||||
Str("logID", logID).
|
Str("logID", logID).
|
||||||
Int("imageBufSize", size).
|
Int("imageBufSize", size).
|
||||||
@@ -116,7 +120,7 @@ func (s *veDEMOCRService) getOCRResult(imageBuf []byte) ([]OCRResult, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return nil, errors.Wrap(code.OCRResponseStatusCodeNot200,
|
return nil, errors.Wrap(code.OCRResponseError,
|
||||||
fmt.Sprintf("unexpected response status code: %d, results: %v",
|
fmt.Sprintf("unexpected response status code: %d, results: %v",
|
||||||
resp.StatusCode, string(results)))
|
resp.StatusCode, string(results)))
|
||||||
}
|
}
|
||||||
@@ -258,8 +262,8 @@ func (s *veDEMOCRService) FindTexts(texts []string, imageBuf []byte, options ...
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
return rects,
|
return rects, errors.Wrap(code.OCRTextNotFoundError,
|
||||||
fmt.Errorf("texts %s not found in %v", texts, ocrTexts)
|
fmt.Sprintf("texts %s not found in %v", texts, ocrTexts))
|
||||||
}
|
}
|
||||||
|
|
||||||
return rects, nil
|
return rects, nil
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
|
||||||
|
"github.com/httprunner/httprunner/v4/hrp/internal/code"
|
||||||
)
|
)
|
||||||
|
|
||||||
func assertRelative(p float64) bool {
|
func assertRelative(p float64) bool {
|
||||||
@@ -97,7 +98,8 @@ func (dExt *DriverExt) SwipeUntil(direction interface{}, findCondition Action, f
|
|||||||
// wait for swipe action to completed and content to load completely
|
// wait for swipe action to completed and content to load completely
|
||||||
time.Sleep(time.Duration(1000*interval) * time.Millisecond)
|
time.Sleep(time.Duration(1000*interval) * time.Millisecond)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("swipe %s %d times, match condition failed", direction, maxRetryTimes)
|
return errors.Wrap(code.OCRTextNotFoundError,
|
||||||
|
fmt.Sprintf("swipe %s %d times, match condition failed", direction, maxRetryTimes))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) LoopUntil(findAction, findCondition, foundAction Action, options ...DataOption) error {
|
func (dExt *DriverExt) LoopUntil(findAction, findCondition, foundAction Action, options ...DataOption) error {
|
||||||
@@ -118,7 +120,9 @@ func (dExt *DriverExt) LoopUntil(findAction, findCondition, foundAction Action,
|
|||||||
// wait interval between each findAction
|
// wait interval between each findAction
|
||||||
time.Sleep(time.Duration(1000*interval) * time.Millisecond)
|
time.Sleep(time.Duration(1000*interval) * time.Millisecond)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("loop %d times, match find condition failed", maxRetryTimes)
|
|
||||||
|
return errors.Wrap(code.OCRTextNotFoundError,
|
||||||
|
fmt.Sprintf("loop %d times, match find condition failed", maxRetryTimes))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) swipeToTapApp(appName string, action MobileAction) error {
|
func (dExt *DriverExt) swipeToTapApp(appName string, action MobileAction) error {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
__version__ = "v4.3.0-beta-10161439"
|
__version__ = "v4.3.0-beta-10172144"
|
||||||
__description__ = "One-stop solution for HTTP(S) testing."
|
__description__ = "One-stop solution for HTTP(S) testing."
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "httprunner"
|
name = "httprunner"
|
||||||
version = "v4.3.0-beta-10161439"
|
version = "v4.3.0-beta-10172144"
|
||||||
description = "One-stop solution for HTTP(S) testing."
|
description = "One-stop solution for HTTP(S) testing."
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|||||||
Reference in New Issue
Block a user