MCPcopy
hub / github.com/httprunner/httprunner / NewUIADriver

Function NewUIADriver

hrp/pkg/uixt/android_uia2_driver.go:27–56  ·  view source on GitHub ↗
(capabilities Capabilities, urlPrefix string)

Source from the content-addressed store, hash-verified

25}
26
27func NewUIADriver(capabilities Capabilities, urlPrefix string) (driver *uiaDriver, err error) {
28 log.Info().Msg("init uiautomator2 driver")
29 if capabilities == nil {
30 capabilities = NewCapabilities()
31 }
32 driver = new(uiaDriver)
33 if driver.urlPrefix, err = url.Parse(urlPrefix); err != nil {
34 return nil, err
35 }
36 var localPort int
37 {
38 tmpURL, _ := url.Parse(driver.urlPrefix.String())
39 hostname := tmpURL.Hostname()
40 if strings.HasPrefix(hostname, forwardToPrefix) {
41 localPort, _ = strconv.Atoi(strings.TrimPrefix(hostname, forwardToPrefix))
42 }
43 }
44 conn, err := net.Dial("tcp", fmt.Sprintf(":%d", localPort))
45 if err != nil {
46 return nil, fmt.Errorf("adb forward: %w", err)
47 }
48 driver.client = convertToHTTPClient(conn)
49
50 session, err := driver.NewSession(capabilities)
51 if err != nil {
52 return nil, errors.Wrap(err, "create UIAutomator session failed")
53 }
54 driver.sessionId = session.SessionId
55 return driver, nil
56}
57
58type BatteryStatus int
59

Callers 15

NewUSBDriverMethod · 0.85
NewHTTPDriverMethod · 0.85
TestDriver_NewSessionFunction · 0.85
TestNewDriverFunction · 0.85
TestDriver_QuitFunction · 0.85
TestDriver_StatusFunction · 0.85
TestDriver_ScreenshotFunction · 0.85
TestDriver_RotationFunction · 0.85
TestDriver_DeviceSizeFunction · 0.85
TestDriver_SourceFunction · 0.85
TestDriver_BatteryInfoFunction · 0.85

Calls 5

NewCapabilitiesFunction · 0.85
convertToHTTPClientFunction · 0.85
ParseMethod · 0.80
StringMethod · 0.65
NewSessionMethod · 0.65

Tested by 15

TestDriver_NewSessionFunction · 0.68
TestNewDriverFunction · 0.68
TestDriver_QuitFunction · 0.68
TestDriver_StatusFunction · 0.68
TestDriver_ScreenshotFunction · 0.68
TestDriver_RotationFunction · 0.68
TestDriver_DeviceSizeFunction · 0.68
TestDriver_SourceFunction · 0.68
TestDriver_BatteryInfoFunction · 0.68
TestDriver_DeviceInfoFunction · 0.68
TestDriver_TapFunction · 0.68