feat: start & stop camera

This commit is contained in:
debugtalk
2022-07-31 15:29:29 +08:00
parent 10a3b15efd
commit 4847fbd0f3
4 changed files with 94 additions and 13 deletions

View File

@@ -24,18 +24,20 @@ const (
appLaunchUnattached MobileMethod = "app_launch_unattached" // 只负责通知打开 app不堵塞等待不可传入启动参数
appTerminate MobileMethod = "app_terminate"
appStop MobileMethod = "app_stop"
cameraStart MobileMethod = "camera_start"
cameraStop MobileMethod = "camera_stop"
recordStart MobileMethod = "record_start"
recordStop MobileMethod = "record_stop"
uiHome MobileMethod = "home"
uiClick MobileMethod = "click"
uiDoubleClick MobileMethod = "double_click"
uiLongClick MobileMethod = "long_click"
uiSwipe MobileMethod = "swipe"
uiInput MobileMethod = "input"
ctlScreenShot MobileMethod = "screenshot"
ctlSleep MobileMethod = "sleep"
ctlStartCamera MobileMethod = "camera_start" // alias for app_launch camera
ctlStopCamera MobileMethod = "camera_stop" // alias for app_terminate camera
recordStart MobileMethod = "record_start"
recordStop MobileMethod = "record_stop"
// UI handling
uiHome MobileMethod = "home"
uiClick MobileMethod = "click"
uiDoubleClick MobileMethod = "double_click"
uiLongClick MobileMethod = "long_click"
uiSwipe MobileMethod = "swipe"
uiInput MobileMethod = "input"
)
type MobileAction struct {

View File

@@ -34,7 +34,7 @@ func (s *StepAndroid) StartAppByIntent(activity string) *StepAndroid {
func (s *StepAndroid) StartCamera() *StepAndroid {
s.step.Android.Actions = append(s.step.Android.Actions, MobileAction{
Method: cameraStart,
Method: ctlStartCamera,
Params: nil,
})
return &StepAndroid{step: s.step}
@@ -42,7 +42,7 @@ func (s *StepAndroid) StartCamera() *StepAndroid {
func (s *StepAndroid) StopCamera() *StepAndroid {
s.step.Android.Actions = append(s.step.Android.Actions, MobileAction{
Method: cameraStop,
Method: ctlStopCamera,
Params: nil,
})
return &StepAndroid{step: s.step}

View File

@@ -198,6 +198,22 @@ func (s *StepIOS) ScreenShot() *StepIOS {
return &StepIOS{step: s.step}
}
func (s *StepIOS) StartCamera() *StepIOS {
s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{
Method: ctlStartCamera,
Params: nil,
})
return &StepIOS{step: s.step}
}
func (s *StepIOS) StopCamera() *StepIOS {
s.step.IOS.Actions = append(s.step.IOS.Actions, MobileAction{
Method: ctlStopCamera,
Params: nil,
})
return &StepIOS{step: s.step}
}
// Validate switches to step validation.
func (s *StepIOS) Validate() *StepIOSValidation {
return &StepIOSValidation{
@@ -612,7 +628,20 @@ func (w *wdaClient) doAction(action MobileAction) error {
case ctlScreenShot:
// take snapshot
log.Info().Msg("take snapshot for current screen")
w.screenShot()
return w.screenShot()
case ctlStartCamera:
// start camera, alias for app_launch com.apple.camera
return w.Driver.AppLaunch("com.apple.camera")
case ctlStopCamera:
// stop camera, alias for app_terminate com.apple.camera
success, err := w.Driver.AppTerminate("com.apple.camera")
if err != nil {
return errors.Wrap(err, "failed to terminate camera")
}
if !success {
log.Warn().Msg("camera was not running")
}
return nil
}
return nil
}

View File

@@ -117,6 +117,56 @@ func TestIOSWeixinLive(t *testing.T) {
}
}
func TestIOSCameraPhotoCapture(t *testing.T) {
testCase := &TestCase{
Config: NewConfig("ios camera photo capture"),
TestSteps: []IStep{
NewStep("launch camera").
IOS().Home().
StopCamera().
StartCamera().
Validate().
AssertNameExists("PhotoCapture", "拍照按钮不存在"),
NewStep("start recording").
IOS().Click("PhotoCapture"),
},
}
err := NewRunner(t).Run(testCase)
if err != nil {
t.Fatal(err)
}
}
func TestIOSCameraVideoCapture(t *testing.T) {
testCase := &TestCase{
Config: NewConfig("ios camera video capture"),
TestSteps: []IStep{
NewStep("launch camera").
IOS().Home().
StopCamera().
StartCamera().
Validate().
AssertNameExists("PhotoCapture", "录像按钮不存在"),
NewStep("switch to video capture").
IOS().
SwipeRight().
Validate().
AssertNameExists("VideoCapture", "拍摄按钮不存在"),
NewStep("start recording").
IOS().
Click("VideoCapture"). // 开始录像
Sleep(5).
Click("VideoCapture"), // 停止录像
},
}
err := NewRunner(t).Run(testCase)
if err != nil {
t.Fatal(err)
}
}
func TestIOSDouyinAction(t *testing.T) {
testCase := &TestCase{
Config: NewConfig("ios ui action on 抖音"),