mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-22 17:00:17 +08:00
change: add back action of mobile ui automation
This commit is contained in:
@@ -233,9 +233,12 @@ func (ud *uiaDriver) Scale() (scale float64, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PressBack simulates a short press on the BACK button.
|
// PressBack simulates a short press on the BACK button.
|
||||||
func (ud *uiaDriver) PressBack() (err error) {
|
func (ud *uiaDriver) PressBack(options ...DataOption) (err error) {
|
||||||
// register(postHandler, new PressBack("/wd/hub/session/:sessionId/back"))
|
// register(postHandler, new PressBack("/wd/hub/session/:sessionId/back"))
|
||||||
_, err = ud.httpPOST(nil, "/session", ud.sessionId, "back")
|
_, err = ud.httpPOST(nil, "/session", ud.sessionId, "back")
|
||||||
|
if err != nil {
|
||||||
|
_, err = ud.adbDevice.RunShellCommand("input", "keyevent", "4")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ const (
|
|||||||
ACTION_DoubleTap MobileMethod = "double_tap"
|
ACTION_DoubleTap MobileMethod = "double_tap"
|
||||||
ACTION_Swipe MobileMethod = "swipe"
|
ACTION_Swipe MobileMethod = "swipe"
|
||||||
ACTION_Input MobileMethod = "input"
|
ACTION_Input MobileMethod = "input"
|
||||||
|
ACTION_Back MobileMethod = "back"
|
||||||
|
|
||||||
// custom actions
|
// custom actions
|
||||||
ACTION_SwipeToTapApp MobileMethod = "swipe_to_tap_app" // swipe left & right to find app and tap
|
ACTION_SwipeToTapApp MobileMethod = "swipe_to_tap_app" // swipe left & right to find app and tap
|
||||||
@@ -618,6 +619,8 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
options = append(options, WithDataIdentifier(action.Identifier))
|
options = append(options, WithDataIdentifier(action.Identifier))
|
||||||
}
|
}
|
||||||
return dExt.Driver.Input(param, options...)
|
return dExt.Driver.Input(param, options...)
|
||||||
|
case ACTION_Back:
|
||||||
|
return dExt.Driver.PressBack()
|
||||||
case CtlSleep:
|
case CtlSleep:
|
||||||
if param, ok := action.Params.(json.Number); ok {
|
if param, ok := action.Params.(json.Number); ok {
|
||||||
seconds, _ := param.Float64()
|
seconds, _ := param.Float64()
|
||||||
@@ -651,10 +654,10 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) getAbsScope(x1, y1, x2, y2 float64) (int, int, int, int) {
|
func (dExt *DriverExt) getAbsScope(x1, y1, x2, y2 float64) (int, int, int, int) {
|
||||||
return int(x1 * float64(dExt.windowSize.Width) * dExt.scale),
|
return int(x1 * float64(dExt.windowSize.Width)),
|
||||||
int(y1 * float64(dExt.windowSize.Height) * dExt.scale),
|
int(y1 * float64(dExt.windowSize.Height)),
|
||||||
int(x2 * float64(dExt.windowSize.Width) * dExt.scale),
|
int(x2 * float64(dExt.windowSize.Width)),
|
||||||
int(y2 * float64(dExt.windowSize.Height) * dExt.scale)
|
int(y2 * float64(dExt.windowSize.Height))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) DoValidation(check, assert, expected string, message ...string) bool {
|
func (dExt *DriverExt) DoValidation(check, assert, expected string, message ...string) bool {
|
||||||
|
|||||||
@@ -1046,6 +1046,9 @@ type WebDriver interface {
|
|||||||
// PressButton Presses the corresponding hardware button on the device
|
// PressButton Presses the corresponding hardware button on the device
|
||||||
PressButton(devBtn DeviceButton) error
|
PressButton(devBtn DeviceButton) error
|
||||||
|
|
||||||
|
// PressBack Presses the back button
|
||||||
|
PressBack(options ...DataOption) error
|
||||||
|
|
||||||
// IOHIDEvent Emulated triggering of the given low-level IOHID device event.
|
// IOHIDEvent Emulated triggering of the given low-level IOHID device event.
|
||||||
// duration: The event duration in float seconds (XCTest uses 0.005 for a single press event)
|
// duration: The event duration in float seconds (XCTest uses 0.005 for a single press event)
|
||||||
IOHIDEvent(pageID EventPageID, usageID EventUsageID, duration ...float64) error
|
IOHIDEvent(pageID EventPageID, usageID EventUsageID, duration ...float64) error
|
||||||
|
|||||||
@@ -526,6 +526,27 @@ func (wd *wdaDriver) KeyboardDismiss(keyNames ...string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PressBack simulates a short press on the BACK button.
|
||||||
|
func (wd *wdaDriver) PressBack(options ...DataOption) (err error) {
|
||||||
|
windowSize, err := wd.WindowSize()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data := map[string]interface{}{
|
||||||
|
"fromX": float64(windowSize.Width) * 0,
|
||||||
|
"fromY": float64(windowSize.Height) * 0.5,
|
||||||
|
"toX": float64(windowSize.Width) * 0.6,
|
||||||
|
"toY": float64(windowSize.Height) * 0.5,
|
||||||
|
}
|
||||||
|
|
||||||
|
// new data options in post data for extra WDA configurations
|
||||||
|
d := NewData(data, options...)
|
||||||
|
|
||||||
|
_, err = wd.httpPOST(d.Data, "/session", wd.sessionId, "/wda/dragfromtoforduration")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (wd *wdaDriver) PressButton(devBtn DeviceButton) (err error) {
|
func (wd *wdaDriver) PressButton(devBtn DeviceButton) (err error) {
|
||||||
// [[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)]
|
// [[FBRoute POST:@"/wda/pressButton"] respondWithTarget:self action:@selector(handlePressButtonCommand:)]
|
||||||
data := map[string]interface{}{"name": devBtn}
|
data := map[string]interface{}{"name": devBtn}
|
||||||
|
|||||||
@@ -181,6 +181,18 @@ func (s *StepMobile) DoubleTap(params string, options ...uixt.ActionOption) *Ste
|
|||||||
return &StepMobile{step: s.step}
|
return &StepMobile{step: s.step}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StepMobile) Back(options ...uixt.ActionOption) *StepMobile {
|
||||||
|
action := uixt.MobileAction{
|
||||||
|
Method: uixt.ACTION_Back,
|
||||||
|
Params: nil,
|
||||||
|
}
|
||||||
|
for _, option := range options {
|
||||||
|
option(&action)
|
||||||
|
}
|
||||||
|
s.mobileStep().Actions = append(s.mobileStep().Actions, action)
|
||||||
|
return &StepMobile{step: s.step}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StepMobile) Swipe(sx, sy, ex, ey float64, options ...uixt.ActionOption) *StepMobile {
|
func (s *StepMobile) Swipe(sx, sy, ex, ey float64, options ...uixt.ActionOption) *StepMobile {
|
||||||
action := uixt.MobileAction{
|
action := uixt.MobileAction{
|
||||||
Method: uixt.ACTION_Swipe,
|
Method: uixt.ACTION_Swipe,
|
||||||
|
|||||||
Reference in New Issue
Block a user