mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
fix: compress screenshot image file
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/gif"
|
"image/gif"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"image/png"
|
_ "image/png"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -216,14 +216,14 @@ func saveScreenShot(raw *bytes.Buffer, fileName string) (string, error) {
|
|||||||
|
|
||||||
// compress image and save to file
|
// compress image and save to file
|
||||||
switch format {
|
switch format {
|
||||||
case "jpeg":
|
case "jpeg", "png":
|
||||||
jpegOptions := &jpeg.Options{Quality: 90}
|
jpegOptions := &jpeg.Options{Quality: 95}
|
||||||
err = jpeg.Encode(file, img, jpegOptions)
|
err = jpeg.Encode(file, img, jpegOptions)
|
||||||
case "png":
|
// case "png":
|
||||||
encoder := png.Encoder{
|
// encoder := png.Encoder{
|
||||||
CompressionLevel: png.BestCompression,
|
// CompressionLevel: png.BestCompression,
|
||||||
}
|
// }
|
||||||
err = encoder.Encode(file, img)
|
// err = encoder.Encode(file, img)
|
||||||
case "gif":
|
case "gif":
|
||||||
gifOptions := &gif.Options{
|
gifOptions := &gif.Options{
|
||||||
NumColors: 256,
|
NumColors: 256,
|
||||||
|
|||||||
@@ -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