mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
change: rename DeviceLogcat to AdbLogcat
This commit is contained in:
@@ -68,6 +68,8 @@ func GetAndroidDeviceOptions(dev *AndroidDevice) (deviceOptions []AndroidDeviceO
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// uiautomator2 server must be started before
|
||||||
|
// adb shell am instrument -w io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner
|
||||||
func NewAndroidDevice(options ...AndroidDeviceOption) (device *AndroidDevice, err error) {
|
func NewAndroidDevice(options ...AndroidDeviceOption) (device *AndroidDevice, err error) {
|
||||||
deviceList, err := DeviceList()
|
deviceList, err := DeviceList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -114,7 +116,7 @@ func DeviceList() (devices []gadb.Device, err error) {
|
|||||||
|
|
||||||
type AndroidDevice struct {
|
type AndroidDevice struct {
|
||||||
d gadb.Device
|
d gadb.Device
|
||||||
logcat *DeviceLogcat
|
logcat *AdbLogcat
|
||||||
SerialNumber string `json:"serial,omitempty" yaml:"serial,omitempty"`
|
SerialNumber string `json:"serial,omitempty" yaml:"serial,omitempty"`
|
||||||
IP string `json:"ip,omitempty" yaml:"ip,omitempty"`
|
IP string `json:"ip,omitempty" yaml:"ip,omitempty"`
|
||||||
Port int `json:"port,omitempty" yaml:"port,omitempty"`
|
Port int `json:"port,omitempty" yaml:"port,omitempty"`
|
||||||
@@ -201,7 +203,7 @@ func getFreePort() (int, error) {
|
|||||||
return l.Addr().(*net.TCPAddr).Port, nil
|
return l.Addr().(*net.TCPAddr).Port, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeviceLogcat struct {
|
type AdbLogcat struct {
|
||||||
serial string
|
serial string
|
||||||
logBuffer *bytes.Buffer
|
logBuffer *bytes.Buffer
|
||||||
errs []error
|
errs []error
|
||||||
@@ -210,8 +212,8 @@ type DeviceLogcat struct {
|
|||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAdbLogcat(serial string) *DeviceLogcat {
|
func NewAdbLogcat(serial string) *AdbLogcat {
|
||||||
return &DeviceLogcat{
|
return &AdbLogcat{
|
||||||
serial: serial,
|
serial: serial,
|
||||||
logBuffer: new(bytes.Buffer),
|
logBuffer: new(bytes.Buffer),
|
||||||
stopping: make(chan struct{}),
|
stopping: make(chan struct{}),
|
||||||
@@ -220,7 +222,7 @@ func NewAdbLogcat(serial string) *DeviceLogcat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CatchLogcatContext starts logcat with timeout context
|
// CatchLogcatContext starts logcat with timeout context
|
||||||
func (l *DeviceLogcat) CatchLogcatContext(timeoutCtx context.Context) (err error) {
|
func (l *AdbLogcat) CatchLogcatContext(timeoutCtx context.Context) (err error) {
|
||||||
if err = l.CatchLogcat(); err != nil {
|
if err = l.CatchLogcat(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -234,7 +236,7 @@ func (l *DeviceLogcat) CatchLogcatContext(timeoutCtx context.Context) (err error
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DeviceLogcat) Stop() error {
|
func (l *AdbLogcat) Stop() error {
|
||||||
select {
|
select {
|
||||||
case <-l.stopping:
|
case <-l.stopping:
|
||||||
default:
|
default:
|
||||||
@@ -245,7 +247,7 @@ func (l *DeviceLogcat) Stop() error {
|
|||||||
return l.Errors()
|
return l.Errors()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DeviceLogcat) Errors() (err error) {
|
func (l *AdbLogcat) Errors() (err error) {
|
||||||
for _, e := range l.errs {
|
for _, e := range l.errs {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("%v |[DeviceLogcatErr] %v", err, e)
|
err = fmt.Errorf("%v |[DeviceLogcatErr] %v", err, e)
|
||||||
@@ -256,7 +258,7 @@ func (l *DeviceLogcat) Errors() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DeviceLogcat) CatchLogcat() (err error) {
|
func (l *AdbLogcat) CatchLogcat() (err error) {
|
||||||
if l.cmd != nil {
|
if l.cmd != nil {
|
||||||
log.Warn().Msg("logcat already start")
|
log.Warn().Msg("logcat already start")
|
||||||
return nil
|
return nil
|
||||||
@@ -284,7 +286,7 @@ func (l *DeviceLogcat) CatchLogcat() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DeviceLogcat) BufferedLogcat() (err error) {
|
func (l *AdbLogcat) BufferedLogcat() (err error) {
|
||||||
// -d: dump the current buffered logcat result and exits
|
// -d: dump the current buffered logcat result and exits
|
||||||
cmd := myexec.Command("adb", "-s", l.serial, "logcat", "-d")
|
cmd := myexec.Command("adb", "-s", l.serial, "logcat", "-d")
|
||||||
cmd.Stdout = l.logBuffer
|
cmd.Stdout = l.logBuffer
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ type uiaDriver struct {
|
|||||||
Driver
|
Driver
|
||||||
|
|
||||||
adbDevice gadb.Device
|
adbDevice gadb.Device
|
||||||
logcat *DeviceLogcat
|
logcat *AdbLogcat
|
||||||
localPort int
|
localPort int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,7 +478,7 @@ func (ud *uiaDriver) AppTerminate(bundleId string) (successful bool, err error)
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ud.adbDevice.RunShellCommand("am force-stop", bundleId)
|
_, err = ud.adbDevice.RunShellCommand("am", "force-stop", bundleId)
|
||||||
return err == nil, err
|
return err == nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user