mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
fix: failed to compress image for requesting vedm algorithm service
This commit is contained in:
@@ -41,7 +41,11 @@ var listAndroidDevicesCmd = &cobra.Command{
|
||||
if isDetail {
|
||||
fmt.Println(format(d.DeviceInfo()))
|
||||
} else {
|
||||
fmt.Println(d.Serial(), d.Usb())
|
||||
if usb, err := d.Usb(); err != nil {
|
||||
fmt.Println(d.Serial())
|
||||
} else {
|
||||
fmt.Println(d.Serial(), usb)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -42,7 +42,7 @@ func init() {
|
||||
runCmd.Flags().BoolVarP(&continueOnFailure, "continue-on-failure", "c", false, "continue running next step when failure occurs")
|
||||
runCmd.Flags().BoolVar(&requestsLogOff, "log-requests-off", false, "turn off request & response details logging")
|
||||
runCmd.Flags().BoolVar(&httpStatOn, "http-stat", false, "turn on HTTP latency stat (DNSLookup, TCP Connection, etc.)")
|
||||
runCmd.Flags().BoolVar(&pluginLogOn, "log-plugin", false, "turn on plugin logging")
|
||||
runCmd.Flags().BoolVar(&pluginLogOn, "log-plugin", true, "turn on plugin logging")
|
||||
runCmd.Flags().StringVarP(&proxyUrl, "proxy-url", "p", "", "set proxy url")
|
||||
runCmd.Flags().BoolVarP(&saveTests, "save-tests", "s", false, "save tests summary")
|
||||
runCmd.Flags().BoolVarP(&genHTMLReport, "gen-html-report", "g", false, "generate html report")
|
||||
|
||||
@@ -108,7 +108,7 @@ func (c Client) DeviceList() (devices []*Device, err error) {
|
||||
}
|
||||
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) < 5 || len(fields[0]) == 0 {
|
||||
if len(fields) < 4 || len(fields[0]) == 0 {
|
||||
log.Error().Str("line", line).Msg("get unexpected line")
|
||||
continue
|
||||
}
|
||||
@@ -117,6 +117,9 @@ func (c Client) DeviceList() (devices []*Device, err error) {
|
||||
mapAttrs := map[string]string{}
|
||||
for _, field := range sliceAttrs {
|
||||
split := strings.Split(field, ":")
|
||||
if len(split) == 1 {
|
||||
continue
|
||||
}
|
||||
key, val := split[0], split[1]
|
||||
mapAttrs[key] = val
|
||||
}
|
||||
|
||||
@@ -107,20 +107,37 @@ func (d *Device) features() (features Features, err error) {
|
||||
return features, nil
|
||||
}
|
||||
|
||||
func (d *Device) Product() string {
|
||||
return d.attrs["product"]
|
||||
func (d Device) HasAttribute(key string) bool {
|
||||
_, ok := d.attrs[key]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (d *Device) Model() string {
|
||||
return d.attrs["model"]
|
||||
func (d Device) Product() (string, error) {
|
||||
if d.HasAttribute("product") {
|
||||
return d.attrs["product"], nil
|
||||
}
|
||||
return "", errors.New("does not have attribute: product")
|
||||
}
|
||||
|
||||
func (d *Device) Usb() string {
|
||||
return d.attrs["usb"]
|
||||
func (d Device) Model() (string, error) {
|
||||
if d.HasAttribute("model") {
|
||||
return d.attrs["model"], nil
|
||||
}
|
||||
return "", errors.New("does not have attribute: model")
|
||||
}
|
||||
|
||||
func (d *Device) transportId() string {
|
||||
return d.attrs["transport_id"]
|
||||
func (d *Device) Usb() (string, error) {
|
||||
if d.HasAttribute("usb") {
|
||||
return d.attrs["usb"], nil
|
||||
}
|
||||
return "", errors.New("does not have attribute: usb")
|
||||
}
|
||||
|
||||
func (d Device) transportId() (string, error) {
|
||||
if d.HasAttribute("transport_id") {
|
||||
return d.attrs["transport_id"], nil
|
||||
}
|
||||
return "", errors.New("does not have attribute: transport_id")
|
||||
}
|
||||
|
||||
func (d *Device) DeviceInfo() map[string]string {
|
||||
@@ -132,8 +149,13 @@ func (d *Device) Serial() string {
|
||||
return d.serial
|
||||
}
|
||||
|
||||
func (d *Device) IsUsb() bool {
|
||||
return d.Usb() != ""
|
||||
func (d *Device) IsUsb() (bool, error) {
|
||||
usb, err := d.Usb()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return usb != "", nil
|
||||
}
|
||||
|
||||
func (d *Device) State() (DeviceState, error) {
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/gif"
|
||||
_ "image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
_ "image/png"
|
||||
"math/rand"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
@@ -190,8 +190,26 @@ func (dExt *DriverExt) takeScreenShot(fileName string) (raw *bytes.Buffer, path
|
||||
}
|
||||
|
||||
func compressImageBuffer(raw *bytes.Buffer) (compressed *bytes.Buffer, err error) {
|
||||
// TODO: compress image data
|
||||
return raw, nil
|
||||
// 解码原始图像数据
|
||||
img, format, err := image.Decode(raw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 创建一个用来保存压缩后数据的buffer
|
||||
var buf bytes.Buffer
|
||||
|
||||
switch format {
|
||||
// Convert to jpeg uniformly and compress with a compression rate of 95
|
||||
case "jpeg", "png":
|
||||
jpegOptions := &jpeg.Options{Quality: 95}
|
||||
err = jpeg.Encode(&buf, img, jpegOptions)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported image format: %s", format)
|
||||
}
|
||||
|
||||
// 返回压缩后的图像数据
|
||||
return &buf, nil
|
||||
}
|
||||
|
||||
// saveScreenShot saves image file with file name
|
||||
@@ -207,7 +225,8 @@ func (dExt *DriverExt) saveScreenShot(raw *bytes.Buffer, fileName string) (strin
|
||||
return "", errors.Wrap(err, "decode screenshot image failed")
|
||||
}
|
||||
|
||||
screenshotPath := filepath.Join(fmt.Sprintf("%s.%s", fileName, format))
|
||||
// The default format uses jpeg for compression
|
||||
screenshotPath := filepath.Join(fmt.Sprintf("%s.%s", fileName, "jpeg"))
|
||||
file, err := os.Create(screenshotPath)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "create screenshot image file failed")
|
||||
@@ -217,12 +236,9 @@ func (dExt *DriverExt) saveScreenShot(raw *bytes.Buffer, fileName string) (strin
|
||||
}()
|
||||
|
||||
switch format {
|
||||
case "png":
|
||||
err = png.Encode(file, img)
|
||||
case "jpeg":
|
||||
err = jpeg.Encode(file, img, nil)
|
||||
case "gif":
|
||||
err = gif.Encode(file, img, nil)
|
||||
case "jpeg", "png":
|
||||
jpegOptions := &jpeg.Options{}
|
||||
err = jpeg.Encode(file, img, jpegOptions)
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported image format: %s", format)
|
||||
}
|
||||
|
||||
@@ -218,6 +218,7 @@ func (s *veDEMImageService) GetImage(imageBuf *bytes.Buffer, options ...ActionOp
|
||||
bodyWriter.WriteField("uiTypes", uiType)
|
||||
}
|
||||
|
||||
// 使用高精度集群
|
||||
bodyWriter.WriteField("ocrCluster", "highPrecision")
|
||||
|
||||
if actionOptions.Timeout > 0 {
|
||||
@@ -488,8 +489,8 @@ func (box Box) IsEmpty() bool {
|
||||
func (box Box) IsIdentical(box2 Box) bool {
|
||||
// set the coordinate precision to 1 pixel
|
||||
return box.Point.IsIdentical(box2.Point) &&
|
||||
math.Abs(box.Width-box2.Width) < 1 &&
|
||||
math.Abs(box.Height-box2.Height) < 1
|
||||
builtin.IsZeroFloat64(math.Abs(box.Width-box2.Width)) &&
|
||||
builtin.IsZeroFloat64(math.Abs(box.Height-box2.Height))
|
||||
}
|
||||
|
||||
func (box Box) Center() PointF {
|
||||
@@ -544,7 +545,7 @@ func (u UIResultMap) FilterUIResults(uiTypes []string) (uiResults UIResults, err
|
||||
return
|
||||
}
|
||||
}
|
||||
err = errors.Errorf("UI types %v not detected", uiTypes)
|
||||
err = errors.Wrap(code.CVResultNotFoundError, fmt.Sprintf("UI types %v not detected", uiTypes))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
// swipe to next feed video
|
||||
log.Info().Msg("swipe to next feed video")
|
||||
swipeStartTime := time.Now()
|
||||
if err = dExt.SwipeRelative(0.9, 0.8, 0.9, 0.1, WithOffsetRandomRange(-10, 10)); err != nil {
|
||||
if err = dExt.SwipeRelative(0.85, 0.83-(float64(crawler.failedCount)*0.01), 0.85, 0.1, WithOffsetRandomRange(-10, 10)); err != nil {
|
||||
log.Error().Err(err).Msg("feed swipe up failed")
|
||||
return err
|
||||
}
|
||||
@@ -182,10 +182,10 @@ func (dExt *DriverExt) VideoCrawler(configs *VideoCrawlerConfigs) (err error) {
|
||||
currentVideo, err := crawler.getCurrentVideo()
|
||||
if err != nil || currentVideo.Type == "" {
|
||||
crawler.failedCount++
|
||||
if crawler.failedCount >= 10 {
|
||||
if crawler.failedCount >= 3 {
|
||||
// failed 10 consecutive times
|
||||
return errors.Wrap(code.TrackingGetError,
|
||||
"get current feed video failed 10 consecutive times")
|
||||
"get current feed video failed 3 consecutive times")
|
||||
}
|
||||
log.Warn().
|
||||
Int64("failedCount", crawler.failedCount).
|
||||
|
||||
Reference in New Issue
Block a user