mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-22 04:52:42 +08:00
change: add server ext
This commit is contained in:
41
server/ext/context.go
Normal file
41
server/ext/context.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package server_ext
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/pkg/uixt"
|
||||
"github.com/httprunner/httprunner/v5/pkg/uixt/ai"
|
||||
"github.com/httprunner/httprunner/v5/pkg/uixt/driver_ext"
|
||||
"github.com/httprunner/httprunner/v5/server"
|
||||
)
|
||||
|
||||
func GetDriver(c *gin.Context) (driverExt *driver_ext.XTDriver, err error) {
|
||||
platform := c.Param("platform")
|
||||
deviceObj, exists := c.Get("device")
|
||||
var device uixt.IDevice
|
||||
var driver uixt.IDriver
|
||||
if !exists {
|
||||
device, err = server.GetDevice(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
device = deviceObj.(uixt.IDevice)
|
||||
}
|
||||
switch strings.ToLower(platform) {
|
||||
case "android":
|
||||
driver, err = driver_ext.NewStubAndroidDriver(device.(*uixt.AndroidDevice))
|
||||
case "ios":
|
||||
driver, err = driver_ext.NewStubIOSDriver(device.(*uixt.IOSDevice))
|
||||
}
|
||||
if err != nil {
|
||||
server.RenderErrorInitDriver(c, err)
|
||||
return
|
||||
}
|
||||
c.Set("driver", driver)
|
||||
driverExt = driver_ext.NewXTDriver(driver,
|
||||
ai.WithCVService(ai.CVServiceTypeVEDEM))
|
||||
return driverExt, nil
|
||||
}
|
||||
Reference in New Issue
Block a user