mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix: compress screenshot image file
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
_ "image/png"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -216,14 +216,14 @@ func saveScreenShot(raw *bytes.Buffer, fileName string) (string, error) {
|
||||
|
||||
// compress image and save to file
|
||||
switch format {
|
||||
case "jpeg":
|
||||
jpegOptions := &jpeg.Options{Quality: 90}
|
||||
case "jpeg", "png":
|
||||
jpegOptions := &jpeg.Options{Quality: 95}
|
||||
err = jpeg.Encode(file, img, jpegOptions)
|
||||
case "png":
|
||||
encoder := png.Encoder{
|
||||
CompressionLevel: png.BestCompression,
|
||||
}
|
||||
err = encoder.Encode(file, img)
|
||||
// case "png":
|
||||
// encoder := png.Encoder{
|
||||
// CompressionLevel: png.BestCompression,
|
||||
// }
|
||||
// err = encoder.Encode(file, img)
|
||||
case "gif":
|
||||
gifOptions := &gif.Options{
|
||||
NumColors: 256,
|
||||
|
||||
23
hrp/pkg/uixt/screenshot_test.go
Normal file
23
hrp/pkg/uixt/screenshot_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
//go:build localtest
|
||||
|
||||
package uixt
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetScreenShot(t *testing.T) {
|
||||
setupAndroidAdbDriver(t)
|
||||
|
||||
fileName := "test_screenshot"
|
||||
_, path, err := driverExt.GetScreenShot(fileName)
|
||||
if err != nil {
|
||||
t.Fatalf("GetScreenShot failed: %v", err)
|
||||
}
|
||||
|
||||
if path == "" {
|
||||
t.Fatal("screenshot path is empty")
|
||||
}
|
||||
|
||||
t.Logf("screenshot saved at: %s", path)
|
||||
}
|
||||
Reference in New Issue
Block a user