mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-07 08:49:37 +08:00
feat: app launch and terminate
This commit is contained in:
30
hrp/step.go
30
hrp/step.go
@@ -17,19 +17,23 @@ const (
|
|||||||
type MobileMethod string
|
type MobileMethod string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
appInstall MobileMethod = "install"
|
appInstall MobileMethod = "install"
|
||||||
appStart MobileMethod = "app_start"
|
appUninstall MobileMethod = "uninstall"
|
||||||
cameraStart MobileMethod = "camera_start"
|
appStart MobileMethod = "app_start"
|
||||||
cameraStop MobileMethod = "camera_stop"
|
appLaunch MobileMethod = "app_launch" // 等待 app 打开并堵塞到 app 首屏加载完成,可以传入 app 的启动参数、环境变量
|
||||||
recordStart MobileMethod = "record_start"
|
appLaunchUnattached MobileMethod = "app_launch_unattached" // 只负责通知打开 app,不堵塞等待,不可传入启动参数
|
||||||
recordStop MobileMethod = "record_stop"
|
appTerminate MobileMethod = "app_terminate"
|
||||||
uiHome MobileMethod = "home"
|
appStop MobileMethod = "app_stop"
|
||||||
uiClick MobileMethod = "click"
|
cameraStart MobileMethod = "camera_start"
|
||||||
uiDoubleClick MobileMethod = "double_click"
|
cameraStop MobileMethod = "camera_stop"
|
||||||
uiLongClick MobileMethod = "long_click"
|
recordStart MobileMethod = "record_start"
|
||||||
uiSwipe MobileMethod = "swipe"
|
recordStop MobileMethod = "record_stop"
|
||||||
uiInput MobileMethod = "input"
|
uiHome MobileMethod = "home"
|
||||||
appClick MobileMethod = "app_click"
|
uiClick MobileMethod = "click"
|
||||||
|
uiDoubleClick MobileMethod = "double_click"
|
||||||
|
uiLongClick MobileMethod = "long_click"
|
||||||
|
uiSwipe MobileMethod = "swipe"
|
||||||
|
uiInput MobileMethod = "input"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MobileAction struct {
|
type MobileAction struct {
|
||||||
|
|||||||
@@ -136,14 +136,6 @@ func (s *StepAndroid) Input(text string) *StepAndroid {
|
|||||||
return &StepAndroid{step: s.step}
|
return &StepAndroid{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepAndroid) StartAppByClick(name string) *StepAndroid {
|
|
||||||
s.step.Android.Actions = append(s.step.Android.Actions, MobileAction{
|
|
||||||
Method: appClick,
|
|
||||||
Params: name,
|
|
||||||
})
|
|
||||||
return &StepAndroid{step: s.step}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate switches to step validation.
|
// Validate switches to step validation.
|
||||||
func (s *StepAndroid) Validate() *StepAndroidValidation {
|
func (s *StepAndroid) Validate() *StepAndroidValidation {
|
||||||
return &StepAndroidValidation{
|
return &StepAndroidValidation{
|
||||||
|
|||||||
@@ -33,6 +33,30 @@ func (s *StepIOS) InstallApp(path string) *StepIOS {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StepIOS) AppLaunch(bundleId string) *StepIOS {
|
||||||
|
s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{
|
||||||
|
Method: appLaunch,
|
||||||
|
Params: bundleId,
|
||||||
|
})
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StepIOS) AppLaunchUnattached(bundleId string) *StepIOS {
|
||||||
|
s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{
|
||||||
|
Method: appLaunchUnattached,
|
||||||
|
Params: bundleId,
|
||||||
|
})
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StepIOS) AppTerminate(bundleId string) *StepIOS {
|
||||||
|
s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{
|
||||||
|
Method: appTerminate,
|
||||||
|
Params: bundleId,
|
||||||
|
})
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StepIOS) Home() *StepIOS {
|
func (s *StepIOS) Home() *StepIOS {
|
||||||
s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{
|
s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{
|
||||||
Method: uiHome,
|
Method: uiHome,
|
||||||
@@ -113,14 +137,6 @@ func (s *StepIOS) Input(text string) *StepIOS {
|
|||||||
return &StepIOS{step: s.step}
|
return &StepIOS{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepIOS) StartAppByClick(name string) *StepIOS {
|
|
||||||
s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{
|
|
||||||
Method: appClick,
|
|
||||||
Params: name,
|
|
||||||
})
|
|
||||||
return &StepIOS{step: s.step}
|
|
||||||
}
|
|
||||||
|
|
||||||
// run last action with given times
|
// run last action with given times
|
||||||
func (s *StepIOS) Times(n int) *StepIOS {
|
func (s *StepIOS) Times(n int) *StepIOS {
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
@@ -377,9 +393,28 @@ func (w *wdaClient) doAction(action MobileAction) error {
|
|||||||
case appInstall:
|
case appInstall:
|
||||||
// TODO
|
// TODO
|
||||||
return errActionNotImplemented
|
return errActionNotImplemented
|
||||||
case appStart:
|
case appLaunch:
|
||||||
// TODO
|
if bundleId, ok := action.Params.(string); ok {
|
||||||
return errActionNotImplemented
|
return w.Driver.AppLaunch(bundleId)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("app_launch params should be bundleId(string), got %v", action.Params)
|
||||||
|
case appLaunchUnattached:
|
||||||
|
if bundleId, ok := action.Params.(string); ok {
|
||||||
|
return w.Driver.AppLaunchUnattached(bundleId)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("app_launch_unattached params should be bundleId(string), got %v", action.Params)
|
||||||
|
case appTerminate:
|
||||||
|
if bundleId, ok := action.Params.(string); ok {
|
||||||
|
success, err := w.Driver.AppTerminate(bundleId)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to terminate app")
|
||||||
|
}
|
||||||
|
if !success {
|
||||||
|
log.Warn().Str("bundleId", bundleId).Msg("app was not running")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("app_terminate params should be bundleId(string), got %v", action.Params)
|
||||||
case uiHome:
|
case uiHome:
|
||||||
return w.Driver.Homescreen()
|
return w.Driver.Homescreen()
|
||||||
case uiClick:
|
case uiClick:
|
||||||
@@ -460,9 +495,6 @@ func (w *wdaClient) doAction(action MobileAction) error {
|
|||||||
// send \b\b\b to delete 3 chars
|
// send \b\b\b to delete 3 chars
|
||||||
param := fmt.Sprintf("%v", action.Params)
|
param := fmt.Sprintf("%v", action.Params)
|
||||||
return w.Driver.SendKeys(param)
|
return w.Driver.SendKeys(param)
|
||||||
case appClick:
|
|
||||||
// TODO
|
|
||||||
return errActionNotImplemented
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,27 @@ func TestIOSSearchApp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIOSAppLaunch(t *testing.T) {
|
||||||
|
testCase := &TestCase{
|
||||||
|
Config: NewConfig("启动 & 关闭 App"),
|
||||||
|
TestSteps: []IStep{
|
||||||
|
NewStep("终止今日头条").
|
||||||
|
IOS().AppTerminate("com.ss.iphone.article.News"),
|
||||||
|
NewStep("启动今日头条").
|
||||||
|
IOS().AppLaunch("com.ss.iphone.article.News"),
|
||||||
|
NewStep("终止今日头条").
|
||||||
|
IOS().AppTerminate("com.ss.iphone.article.News"),
|
||||||
|
NewStep("启动今日头条").
|
||||||
|
IOS().AppLaunchUnattached("com.ss.iphone.article.News"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := NewRunner(t).Run(testCase)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIOSWeixin(t *testing.T) {
|
func TestIOSWeixin(t *testing.T) {
|
||||||
testCase := &TestCase{
|
testCase := &TestCase{
|
||||||
Config: NewConfig("ios ui action on 微信"),
|
Config: NewConfig("ios ui action on 微信"),
|
||||||
|
|||||||
Reference in New Issue
Block a user