mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-06 00:09:37 +08:00
change: move code
This commit is contained in:
@@ -2,6 +2,7 @@ package uixt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"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")
|
||||
|
||||
if err := device.Setup(); err != nil {
|
||||
return nil, fmt.Errorf("setup browser device failed: %w", err)
|
||||
}
|
||||
return device, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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)
|
||||
}
|
||||
|
||||
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
|
||||
func mapToStruct(m map[string]any, out interface{}) error {
|
||||
b, err := json.Marshal(m)
|
||||
|
||||
66
uixt/sdk.go
66
uixt/sdk.go
@@ -3,6 +3,7 @@ package uixt
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/uixt/ai"
|
||||
"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())
|
||||
}
|
||||
|
||||
log.Debug().Str("method", string(action.Method)).
|
||||
Str("tool", string(tool.Name())).
|
||||
Msg("executed action via MCP tool")
|
||||
log.Debug().Str("tool", string(tool.Name())).
|
||||
Msg("execute action via MCP tool")
|
||||
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