mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
feat: NewUIXTRunner
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2506141211
|
v5.0.0-beta-2506150042
|
||||||
|
|||||||
+58
-12
@@ -2,12 +2,16 @@ package hrp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"strconv"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v5/code"
|
"github.com/httprunner/httprunner/v5/code"
|
||||||
@@ -20,6 +24,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UIXTRunner struct {
|
type UIXTRunner struct {
|
||||||
|
Ctx context.Context
|
||||||
Configs *UIXTConfig
|
Configs *UIXTConfig
|
||||||
Session *SessionRunner
|
Session *SessionRunner
|
||||||
DriverExt *uixt.XTDriver
|
DriverExt *uixt.XTDriver
|
||||||
@@ -31,6 +36,8 @@ type UIXTRunner struct {
|
|||||||
type UIXTConfig struct {
|
type UIXTConfig struct {
|
||||||
uixt.DriverCacheConfig
|
uixt.DriverCacheConfig
|
||||||
|
|
||||||
|
Ctx context.Context
|
||||||
|
Cancel context.CancelFunc
|
||||||
JSONCase ITestCase
|
JSONCase ITestCase
|
||||||
UIA2 bool // UIAutomator2(Android)
|
UIA2 bool // UIAutomator2(Android)
|
||||||
LogOn bool // 开启打点日志
|
LogOn bool // 开启打点日志
|
||||||
@@ -41,6 +48,11 @@ type UIXTConfig struct {
|
|||||||
|
|
||||||
WDAPort int
|
WDAPort int
|
||||||
WDAMjpegPort int
|
WDAMjpegPort int
|
||||||
|
|
||||||
|
OSType string // platform
|
||||||
|
Serial string
|
||||||
|
PackageName string
|
||||||
|
LLMService option.LLMServiceType // LLM 服务类型
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -71,14 +83,7 @@ func NewUIXTRunner(configs *UIXTConfig) (runner *UIXTRunner, err error) {
|
|||||||
}
|
}
|
||||||
config.SetAIOptions(configs.AIOptions...)
|
config.SetAIOptions(configs.AIOptions...)
|
||||||
|
|
||||||
testcase := TestCase{
|
switch configs.OSType {
|
||||||
Config: config,
|
|
||||||
TestSteps: testSteps,
|
|
||||||
}
|
|
||||||
|
|
||||||
var caseRunner *CaseRunner
|
|
||||||
|
|
||||||
switch configs.Platform {
|
|
||||||
case "ios":
|
case "ios":
|
||||||
port, err := configs.getWDALocalPort(configs.Serial)
|
port, err := configs.getWDALocalPort(configs.Serial)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -97,9 +102,28 @@ func NewUIXTRunner(configs *UIXTConfig) (runner *UIXTRunner, err error) {
|
|||||||
config.SetHarmony(
|
config.SetHarmony(
|
||||||
option.WithConnectKey(configs.Serial),
|
option.WithConnectKey(configs.Serial),
|
||||||
)
|
)
|
||||||
|
case "darwin":
|
||||||
|
width, height := 1920, 1080
|
||||||
|
osWidth := os.Getenv("OSWidth")
|
||||||
|
osHeight := os.Getenv("OSHeight")
|
||||||
|
if osHeight != "" && osWidth != "" {
|
||||||
|
width, err = strconv.Atoi(osWidth)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn().Msg("get OSWidth failed, use default value")
|
||||||
|
}
|
||||||
|
height, err = strconv.Atoi(osHeight)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn().Msg("get OSHeight failed, use default value")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Info().Int("width", width).Int("height", height).Msg("get darwin screen size")
|
||||||
|
config.SetBrowser(
|
||||||
|
option.WithBrowserLogOn(false),
|
||||||
|
option.WithBrowserPageSize(width, height),
|
||||||
|
)
|
||||||
default:
|
default:
|
||||||
// default to android
|
// default to android
|
||||||
configs.Platform = "android"
|
configs.OSType = "android"
|
||||||
config.SetAndroid(
|
config.SetAndroid(
|
||||||
option.WithSerialNumber(configs.Serial),
|
option.WithSerialNumber(configs.Serial),
|
||||||
option.WithUIA2(configs.UIA2),
|
option.WithUIA2(configs.UIA2),
|
||||||
@@ -107,15 +131,25 @@ func NewUIXTRunner(configs *UIXTConfig) (runner *UIXTRunner, err error) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testcase := TestCase{
|
||||||
|
Config: config,
|
||||||
|
TestSteps: testSteps,
|
||||||
|
}
|
||||||
|
|
||||||
// create runner with HTML report enabled for UIXT
|
// create runner with HTML report enabled for UIXT
|
||||||
hrpRunner := NewRunner(nil).SetSaveTests(true).GenHTMLReport()
|
hrpRunner := NewRunner(nil).SetSaveTests(true).GenHTMLReport()
|
||||||
caseRunner, err = NewCaseRunner(testcase, hrpRunner)
|
caseRunner, err := NewCaseRunner(testcase, hrpRunner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "init case runner failed")
|
return nil, errors.Wrap(err, "init case runner failed")
|
||||||
}
|
}
|
||||||
sessionRunner := caseRunner.NewSession()
|
sessionRunner := caseRunner.NewSession()
|
||||||
|
|
||||||
dExt, err := uixt.GetOrCreateXTDriver(configs.DriverCacheConfig)
|
driverCacheConfig := uixt.DriverCacheConfig{
|
||||||
|
Platform: configs.OSType,
|
||||||
|
Serial: configs.Serial,
|
||||||
|
AIOptions: config.AIOptions.Options(),
|
||||||
|
}
|
||||||
|
dExt, err := uixt.GetOrCreateXTDriver(driverCacheConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "get driver failed")
|
return nil, errors.Wrap(err, "get driver failed")
|
||||||
}
|
}
|
||||||
@@ -125,12 +159,24 @@ func NewUIXTRunner(configs *UIXTConfig) (runner *UIXTRunner, err error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(configs.Ctx)
|
||||||
|
// create a channel to receive signals
|
||||||
|
interruptSignal := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(interruptSignal, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
|
// cancel when interrupted
|
||||||
|
go func() {
|
||||||
|
<-interruptSignal
|
||||||
|
log.Warn().Msg("interrupted in uixt runner")
|
||||||
|
cancel()
|
||||||
|
}()
|
||||||
|
|
||||||
runner = &UIXTRunner{
|
runner = &UIXTRunner{
|
||||||
|
Ctx: ctx,
|
||||||
Configs: configs,
|
Configs: configs,
|
||||||
Session: sessionRunner,
|
Session: sessionRunner,
|
||||||
DriverExt: dExt,
|
DriverExt: dExt,
|
||||||
}
|
}
|
||||||
|
|
||||||
return runner, nil
|
return runner, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user