refactor: cache window size & scale in driver

This commit is contained in:
lilong.129
2025-02-14 10:35:22 +08:00
parent 6c3f21134b
commit c8d776009c
7 changed files with 33 additions and 27 deletions

View File

@@ -20,7 +20,6 @@ import (
"github.com/rs/zerolog/log"
"github.com/httprunner/httprunner/v5/internal/json"
"github.com/httprunner/httprunner/v5/pkg/uixt/types"
)
type Session struct {
@@ -28,10 +27,6 @@ type Session struct {
baseURL *url.URL
client *http.Client
// cache to avoid repeated query
scale float64
windowSize types.Size
// cache uia2/wda request and response
requests []*DriverRequests
// cache screenshot ocr results
@@ -151,8 +146,8 @@ func (wd *Session) Request(method string, rawURL string, rawBody []byte) (rawRes
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
var req *http.Request
if req, err = http.NewRequestWithContext(ctx, method, rawURL, bytes.NewBuffer(rawBody)); err != nil {
req, err := http.NewRequestWithContext(ctx, method, rawURL, bytes.NewBuffer(rawBody))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json;charset=UTF-8")