fix: exit with code

This commit is contained in:
debugtalk
2022-10-17 21:33:15 +08:00
parent ceb4fa2ca9
commit c5f81f2593
11 changed files with 62 additions and 38 deletions

View File

@@ -4,7 +4,6 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"net"
"net/url"
@@ -13,7 +12,10 @@ import (
"time"
"github.com/electricbubble/gadb"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/code"
)
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"))
var rawResp rawResponse
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 })
if err = json.Unmarshal(rawResp, reply); err != nil {
@@ -869,7 +872,8 @@ func (ud *uiaDriver) Screenshot() (raw *bytes.Buffer, err error) {
var decodeStr []byte
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)

View File

@@ -34,7 +34,7 @@ const (
// 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.
// 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.
// 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.

View File

@@ -96,7 +96,11 @@ func (s *veDEMOCRService) getOCRResult(imageBuf []byte) ([]OCRResult, error) {
if err == nil {
break
}
logID := getLogID(resp.Header)
var logID string
if resp != nil {
logID = getLogID(resp.Header)
}
log.Error().Err(err).
Str("logID", logID).
Int("imageBufSize", size).
@@ -116,7 +120,7 @@ func (s *veDEMOCRService) getOCRResult(imageBuf []byte) ([]OCRResult, error) {
}
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",
resp.StatusCode, string(results)))
}
@@ -258,8 +262,8 @@ func (s *veDEMOCRService) FindTexts(texts []string, imageBuf []byte, options ...
}
if !success {
return rects,
fmt.Errorf("texts %s not found in %v", texts, ocrTexts)
return rects, errors.Wrap(code.OCRTextNotFoundError,
fmt.Sprintf("texts %s not found in %v", texts, ocrTexts))
}
return rects, nil

View File

@@ -8,6 +8,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v4/hrp/internal/builtin"
"github.com/httprunner/httprunner/v4/hrp/internal/code"
)
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
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 {
@@ -118,7 +120,9 @@ func (dExt *DriverExt) LoopUntil(findAction, findCondition, foundAction Action,
// wait interval between each findAction
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 {