mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 03:30:01 +08:00
change: move code
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2505261530
|
v5.0.0-beta-2505261608
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ func (r *Router) GetDriver(c *gin.Context) (driverExt *uixt.XTDriver, err error)
|
|||||||
func (r *Router) GetDevice(c *gin.Context) (device uixt.IDevice, err error) {
|
func (r *Router) GetDevice(c *gin.Context) (device uixt.IDevice, err error) {
|
||||||
platform := c.Param("platform")
|
platform := c.Param("platform")
|
||||||
serial := c.Param("serial")
|
serial := c.Param("serial")
|
||||||
device, err = uixt.NewDevice(platform, serial)
|
device, err = uixt.NewDeviceWithDefault(platform, serial)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
RenderErrorInitDriver(c, err)
|
RenderErrorInitDriver(c, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package uixt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@@ -30,6 +31,9 @@ func NewBrowserDevice(opts ...option.BrowserDeviceOption) (device *BrowserDevice
|
|||||||
}
|
}
|
||||||
log.Info().Str("browserID", device.Options.BrowserID).Msg("init browser device")
|
log.Info().Str("browserID", device.Options.BrowserID).Msg("init browser device")
|
||||||
|
|
||||||
|
if err := device.Setup(); err != nil {
|
||||||
|
return nil, fmt.Errorf("setup browser device failed: %w", err)
|
||||||
|
}
|
||||||
return device, nil
|
return device, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ func setupXTDriver(_ context.Context, args map[string]any) (*XTDriver, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
driverExt, err := NewDriverExt(platform, serial)
|
driverExt, err := NewXTDriverWithDefault(platform, serial)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/danielpaulus/go-ios/ios"
|
"github.com/danielpaulus/go-ios/ios"
|
||||||
@@ -1190,66 +1189,6 @@ func (t *ToolDrag) ConvertActionToCallToolRequest(action MobileAction) (mcp.Call
|
|||||||
return mcp.CallToolRequest{}, fmt.Errorf("invalid drag params: %v", action.Params)
|
return mcp.CallToolRequest{}, fmt.Errorf("invalid drag params: %v", action.Params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDriverExt(platform, serial string) (*XTDriver, error) {
|
|
||||||
device, err := NewDevice(platform, serial)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// init driver
|
|
||||||
driver, err := device.NewDriver()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("init driver failed: %w", err)
|
|
||||||
}
|
|
||||||
if err := driver.Setup(); err != nil {
|
|
||||||
return nil, fmt.Errorf("setup driver failed: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// init XTDriver
|
|
||||||
driverExt, err := NewXTDriver(driver,
|
|
||||||
option.WithCVService(option.CVServiceTypeVEDEM))
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("init XT driver failed: %w", err)
|
|
||||||
}
|
|
||||||
return driverExt, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDevice(platform, serial string) (device IDevice, err error) {
|
|
||||||
if serial == "" {
|
|
||||||
return nil, fmt.Errorf("serial is empty")
|
|
||||||
}
|
|
||||||
switch strings.ToLower(platform) {
|
|
||||||
case "android":
|
|
||||||
device, err = NewAndroidDevice(
|
|
||||||
option.WithSerialNumber(serial))
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case "ios":
|
|
||||||
device, err = NewIOSDevice(
|
|
||||||
option.WithUDID(serial),
|
|
||||||
option.WithWDAPort(8700),
|
|
||||||
option.WithWDAMjpegPort(8800),
|
|
||||||
option.WithResetHomeOnStartup(false),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case "browser":
|
|
||||||
device, err = NewBrowserDevice(option.WithBrowserID(serial))
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("invalid platform: %s", platform)
|
|
||||||
}
|
|
||||||
err = device.Setup()
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msg("setup device failed")
|
|
||||||
}
|
|
||||||
return device, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// mapToStruct convert map[string]any to target struct
|
// mapToStruct convert map[string]any to target struct
|
||||||
func mapToStruct(m map[string]any, out interface{}) error {
|
func mapToStruct(m map[string]any, out interface{}) error {
|
||||||
b, err := json.Marshal(m)
|
b, err := json.Marshal(m)
|
||||||
|
|||||||
+63
-3
@@ -3,6 +3,7 @@ package uixt
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v5/uixt/ai"
|
"github.com/httprunner/httprunner/v5/uixt/ai"
|
||||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||||
@@ -107,8 +108,67 @@ func (dExt *XTDriver) ExecuteAction(action MobileAction) (err error) {
|
|||||||
return fmt.Errorf("invoke tool %s failed", tool.Name())
|
return fmt.Errorf("invoke tool %s failed", tool.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Str("method", string(action.Method)).
|
log.Debug().Str("tool", string(tool.Name())).
|
||||||
Str("tool", string(tool.Name())).
|
Msg("execute action via MCP tool")
|
||||||
Msg("executed action via MCP tool")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewXTDriverWithDefault is a helper function to create a XTDriver with default options
|
||||||
|
func NewXTDriverWithDefault(platform, serial string) (*XTDriver, error) {
|
||||||
|
device, err := NewDeviceWithDefault(platform, serial)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// init driver
|
||||||
|
driver, err := device.NewDriver()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("init driver failed: %w", err)
|
||||||
|
}
|
||||||
|
if err := driver.Setup(); err != nil {
|
||||||
|
return nil, fmt.Errorf("setup driver failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// init XTDriver
|
||||||
|
driverExt, err := NewXTDriver(driver,
|
||||||
|
option.WithCVService(option.CVServiceTypeVEDEM))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("init XT driver failed: %w", err)
|
||||||
|
}
|
||||||
|
return driverExt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDeviceWithDefault is a helper function to create a device with default options
|
||||||
|
func NewDeviceWithDefault(platform, serial string) (device IDevice, err error) {
|
||||||
|
if serial == "" {
|
||||||
|
return nil, fmt.Errorf("serial is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
switch strings.ToLower(platform) {
|
||||||
|
case "android":
|
||||||
|
device, err = NewAndroidDevice(
|
||||||
|
option.WithSerialNumber(serial))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case "ios":
|
||||||
|
device, err = NewIOSDevice(
|
||||||
|
option.WithUDID(serial),
|
||||||
|
option.WithWDAPort(8700),
|
||||||
|
option.WithWDAMjpegPort(8800),
|
||||||
|
option.WithResetHomeOnStartup(false),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case "browser":
|
||||||
|
device, err = NewBrowserDevice(option.WithBrowserID(serial))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("invalid platform: %s", platform)
|
||||||
|
}
|
||||||
|
|
||||||
|
return device, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user