This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f17da43
commit 9623188
Showing
1 changed file
with
53 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"runtime" | ||
"time" | ||
) | ||
|
||
type uiautomatorLauncher struct { | ||
running bool | ||
} | ||
|
||
func (u *uiautomatorLauncher) Start() error { | ||
if u.running { | ||
return errors.New("uiautomator already started") | ||
} | ||
if runtime.GOOS == "windows" { | ||
u.running = true | ||
return nil | ||
} | ||
go u.safeRun() | ||
return nil | ||
} | ||
|
||
func (u *uiautomatorLauncher) IsRunning() bool { | ||
return u.running | ||
} | ||
|
||
func (u *uiautomatorLauncher) safeRun() { | ||
u.running = true | ||
retry := 5 | ||
for retry > 0 { | ||
retry-- | ||
start := time.Now() | ||
if err := u.runUiautomator(); err != nil { | ||
log.Printf("uiautomator quit: %v", err) | ||
} | ||
if time.Since(start) > 1*time.Minute { | ||
retry = 5 | ||
} | ||
time.Sleep(2 * time.Second) | ||
} | ||
log.Println("uiautomator can not started") | ||
u.running = false | ||
} | ||
|
||
func (u *uiautomatorLauncher) runUiautomator() error { | ||
c := exec.Command("am", "instrument", "-w", "-r", | ||
"-e", "debug", "false", | ||
"-e", "class", "com.github.uiautomator.stub.Stub", | ||
"com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner") | ||
c.Stdout = os.Stdout | ||
c.Stderr = os.Stderr | ||
return c.Run() | ||
} | ||
|
||
var uiautomator uiautomatorLauncher | ||
|
||
func safeRunUiautomator() error { | ||
return uiautomator.Start() | ||
} | ||
// type uiautomatorLauncher struct { | ||
// running bool | ||
// } | ||
|
||
// func (u *uiautomatorLauncher) Start() error { | ||
// if u.running { | ||
// return errors.New("uiautomator already started") | ||
// } | ||
// if runtime.GOOS == "windows" { | ||
// u.running = true | ||
// return nil | ||
// } | ||
// go u.safeRun() | ||
// return nil | ||
// } | ||
|
||
// func (u *uiautomatorLauncher) IsRunning() bool { | ||
// return u.running | ||
// } | ||
|
||
// func (u *uiautomatorLauncher) safeRun() { | ||
// u.running = true | ||
// retry := 5 | ||
// for retry > 0 { | ||
// retry-- | ||
// start := time.Now() | ||
// if err := u.runUiautomator(); err != nil { | ||
// log.Printf("uiautomator quit: %v", err) | ||
// } | ||
// if time.Since(start) > 1*time.Minute { | ||
// retry = 5 | ||
// } | ||
// time.Sleep(2 * time.Second) | ||
// } | ||
// log.Println("uiautomator can not started") | ||
// u.running = false | ||
// } | ||
|
||
// func (u *uiautomatorLauncher) runUiautomator() error { | ||
// c := exec.Command("am", "instrument", "-w", "-r", | ||
// "-e", "debug", "false", | ||
// "-e", "class", "com.github.uiautomator.stub.Stub", | ||
// "com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner") | ||
// c.Stdout = os.Stdout | ||
// c.Stderr = os.Stderr | ||
// return c.Run() | ||
// } | ||
|
||
// var uiautomator uiautomatorLauncher | ||
|
||
// func safeRunUiautomator() error { | ||
// return uiautomator.Start() | ||
// } |