mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-11 23:41:44 +08:00
change: remove MJPEG stream
This commit is contained in:
@@ -1,16 +1,8 @@
|
|||||||
package uixt
|
package uixt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
_ "image/gif"
|
_ "image/gif"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"mime"
|
|
||||||
"mime/multipart"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/httprunner/funplugin"
|
"github.com/httprunner/funplugin"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -27,10 +19,6 @@ type DriverExt struct {
|
|||||||
|
|
||||||
// funplugin
|
// funplugin
|
||||||
plugin funplugin.IPlugin
|
plugin funplugin.IPlugin
|
||||||
|
|
||||||
frame *bytes.Buffer
|
|
||||||
doneMjpegStream chan bool
|
|
||||||
interruptSignal chan os.Signal
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDriverExt(device Device, driver WebDriver, options ...DriverOption) (dExt *DriverExt, err error) {
|
func newDriverExt(device Device, driver WebDriver, options ...DriverOption) (dExt *DriverExt, err error) {
|
||||||
@@ -41,15 +29,11 @@ func newDriverExt(device Device, driver WebDriver, options ...DriverOption) (dEx
|
|||||||
|
|
||||||
driver.GetSession().Clear()
|
driver.GetSession().Clear()
|
||||||
dExt = &DriverExt{
|
dExt = &DriverExt{
|
||||||
Device: device,
|
Device: device,
|
||||||
Driver: driver,
|
Driver: driver,
|
||||||
plugin: driverOptions.plugin,
|
plugin: driverOptions.plugin,
|
||||||
interruptSignal: make(chan os.Signal, 1),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signal.Notify(dExt.interruptSignal, syscall.SIGTERM, syscall.SIGINT)
|
|
||||||
dExt.doneMjpegStream = make(chan bool, 1)
|
|
||||||
|
|
||||||
if driverOptions.withImageService {
|
if driverOptions.withImageService {
|
||||||
if dExt.ImageService, err = newVEDEMImageService(); err != nil {
|
if dExt.ImageService, err = newVEDEMImageService(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -135,58 +119,3 @@ func (dExt *DriverExt) DoValidation(check, assert, expected string, message ...s
|
|||||||
Msg("validate UI success")
|
Msg("validate UI success")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) ConnectMjpegStream(httpClient *http.Client) (err error) {
|
|
||||||
if httpClient == nil {
|
|
||||||
return errors.New(`'httpClient' can't be nil`)
|
|
||||||
}
|
|
||||||
|
|
||||||
var req *http.Request
|
|
||||||
if req, err = http.NewRequest(http.MethodGet, "http://*", nil); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp *http.Response
|
|
||||||
if resp, err = httpClient.Do(req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// defer func() { _ = resp.Body.Close() }()
|
|
||||||
|
|
||||||
var boundary string
|
|
||||||
if _, param, err := mime.ParseMediaType(resp.Header.Get("Content-Type")); err != nil {
|
|
||||||
return err
|
|
||||||
} else {
|
|
||||||
boundary = strings.Trim(param["boundary"], "-")
|
|
||||||
}
|
|
||||||
|
|
||||||
mjpegReader := multipart.NewReader(resp.Body, boundary)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-dExt.doneMjpegStream:
|
|
||||||
_ = resp.Body.Close()
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
var part *multipart.Part
|
|
||||||
if part, err = mjpegReader.NextPart(); err != nil {
|
|
||||||
dExt.frame = nil
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
raw := new(bytes.Buffer)
|
|
||||||
if _, err = raw.ReadFrom(part); err != nil {
|
|
||||||
dExt.frame = nil
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
dExt.frame = raw
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dExt *DriverExt) CloseMjpegStream() {
|
|
||||||
dExt.doneMjpegStream <- true
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -148,11 +148,6 @@ func (dExt *DriverExt) FindUIResult(options ...ActionOption) (point PointF, err
|
|||||||
|
|
||||||
// GetScreenShot takes screenshot and saves image file to $CWD/screenshots/ folder
|
// GetScreenShot takes screenshot and saves image file to $CWD/screenshots/ folder
|
||||||
func (dExt *DriverExt) GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error) {
|
func (dExt *DriverExt) GetScreenShot(fileName string) (raw *bytes.Buffer, path string, err error) {
|
||||||
// iOS 优先使用 MJPEG 流进行截图,性能最优
|
|
||||||
// 如果 MJPEG 流未开启,则使用 WebDriver 的截图接口
|
|
||||||
if dExt.frame != nil {
|
|
||||||
return dExt.frame, "", nil
|
|
||||||
}
|
|
||||||
if raw, err = dExt.Driver.Screenshot(); err != nil {
|
if raw, err = dExt.Driver.Screenshot(); err != nil {
|
||||||
log.Error().Err(err).Msg("capture screenshot data failed")
|
log.Error().Err(err).Msg("capture screenshot data failed")
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
|
|||||||
Reference in New Issue
Block a user