refactor: android ui automation

This commit is contained in:
xucong053
2022-09-28 13:46:34 +08:00
parent 3a661a5be5
commit 5753955668
13 changed files with 1912 additions and 1772 deletions

View File

@@ -44,11 +44,15 @@ func InitUIAClient(device *AndroidDevice) (*DriverExt, error) {
fmt.Println(driver)
var driverExt *DriverExt
// TODO
// driverExt, err = Extend(driver)
// if err != nil {
// return nil, errors.Wrap(err, "failed to extend UIA Driver")
// }
driverExt, err = Extend(driver)
if err != nil {
return nil, errors.Wrap(err, "failed to extend UIA Driver")
}
if device.LogOn {
// TODO
}
return driverExt, nil
}
@@ -61,6 +65,12 @@ func WithSerialNumber(serial string) AndroidDeviceOption {
}
}
func WithMjpegPortA(port int) AndroidDeviceOption {
return func(device *AndroidDevice) {
device.MjpegPort = port
}
}
func WithAdbIP(ip string) AndroidDeviceOption {
return func(device *AndroidDevice) {
device.IP = ip
@@ -113,6 +123,7 @@ type AndroidDevice struct {
SerialNumber string `json:"serial,omitempty" yaml:"serial,omitempty"`
IP string `json:"ip,omitempty" yaml:"ip,omitempty"`
Port int `json:"port,omitempty" yaml:"port,omitempty"`
MjpegPort int `json:"mjpeg_port,omitempty" yaml:"mjpeg_port,omitempty"`
LogOn bool `json:"log_on,omitempty" yaml:"log_on,omitempty"`
}
@@ -149,12 +160,6 @@ func (dev *AndroidDevice) NewUSBDriver(capabilities Capabilities) (driver *uiaDr
driver.adbDevice = dev.d
driver.localPort = localPort
conn, err := net.Dial("tcp", fmt.Sprintf(":%d", localPort))
if err != nil {
return nil, fmt.Errorf("adb forward: %w", err)
}
driver.client = convertToHTTPClient(conn)
return driver, nil
}