Skip to content

Commit

Permalink
refactor: 重构 PressKeyCode
Browse files Browse the repository at this point in the history
  • Loading branch information
electricbubble committed Aug 10, 2020
1 parent 4534993 commit 72ee387
Show file tree
Hide file tree
Showing 3 changed files with 901 additions and 7 deletions.
19 changes: 14 additions & 5 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,18 +614,27 @@ func (d *Driver) PressBack() (err error) {
// }
// TODO register(postHandler, new LongPressKeyCode("/wd/hub/session/:sessionId/appium/device/long_press_keycode"))

// PressKeyCode simulates a short press using a key code.
func (d *Driver) PressKeyCode(keyCode, metaState, flags int) (err error) {
// TODO register(postHandler, new PressKeyCode("/wd/hub/session/:sessionId/appium/device/press_keycode"))
func (d *Driver) _pressKeyCode(keyCode KeyCode, metaState KeyMeta, flags ...int) (err error) {
// TODO register(postHandler, new PressKeyCodeAsync("/wd/hub/session/:sessionId/appium/device/press_keycode"))
data := map[string]interface{}{
"keycode": keyCode,
"metastate": metaState,
"flags": flags,
}
if len(flags) != 0 {
data["flags"] = flags[0]
}
_, err = d.executePost(data, "/session", d.sessionId, "appium/device/press_keycode")
return
}

// PressKeyCodeAsync simulates a short press using a key code.
func (d *Driver) PressKeyCodeAsync(keyCode KeyCode, metaState ...KeyMeta) (err error) {
if len(metaState) == 0 {
metaState = []KeyMeta{0}
}
return d._pressKeyCode(keyCode, metaState[0])
}

func (d *Driver) TouchDown(x, y int) (err error) {
// register(postHandler, new TouchDown("/wd/hub/session/:sessionId/touch/down"))
data := map[string]interface{}{
Expand Down Expand Up @@ -925,7 +934,7 @@ func (d *Driver) FindElement(by BySelector) (elem *Element, err error) {
return d._findElement(by.getMethodAndSelector())
}

type Condition func(s *Driver) (bool, error)
type Condition func(d *Driver) (bool, error)

func (d *Driver) _waitWithTimeoutAndInterval(condition Condition, timeout, interval time.Duration) (err error) {
startTime := time.Now()
Expand Down
11 changes: 9 additions & 2 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,15 @@ func TestDriver_PressKeyCode(t *testing.T) {

SetDebug(true)

// TODO PressKeyCode
err = driver.PressKeyCode(-1, -1, -1)
err = driver.PressKeyCodeAsync(KCx)
if err != nil {
t.Fatal(err)
}
err = driver.PressKeyCodeAsync(KCx, KMCapLocked)
if err != nil {
t.Fatal(err)
}
err = driver.PressKeyCodeAsync(KCExplorer)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading

0 comments on commit 72ee387

Please sign in to comment.