Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Commit

Permalink
support send key
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed May 25, 2017
1 parent a410f32 commit d96a798
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 29 deletions.
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package main

import (
"bufio"
"net"
"path/filepath"

"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

Expand All @@ -34,6 +34,7 @@ var (
udid string
yosemiteServer string
yosemiteGroup string
debug bool

rt = mux.NewRouter()
)
Expand Down Expand Up @@ -77,6 +78,7 @@ func main() {
flag.IntVarP(&lisPort, "port", "p", 8100, "Proxy listen port")
flag.StringVarP(&udid, "udid", "u", "", "device udid")
flag.StringVarP(&pWda, "wda", "W", "", "WebDriverAgent project directory [optional]")
flag.BoolVarP(&debug, "debug", "d", false, "Open debug mode")

flag.StringVarP(&yosemiteServer, "yosemite-server", "S",
os.Getenv("YOSEMITE_SERVER"),
Expand Down Expand Up @@ -164,6 +166,9 @@ func main() {
lineStr = string(line)
}
lineStr := strings.TrimSpace(string(line))
if debug {
fmt.Printf("[WDA] %s\n", lineStr)
}
if strings.Contains(lineStr, "Successfully wrote Manifest cache to") {
log.Println("[WDA] test ipa successfully generated")
}
Expand Down
93 changes: 67 additions & 26 deletions web/assets/remote-control.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,18 @@ <h3 class="panel-title">设备详情</h3>
</tbody>
</table>
</div>
<button class="btn btn-default" @click="home()">Home</button>
<div class="form-group">
<button class="btn btn-default" @click="home()">
<span class="glyphicon glyphicon-home"></span> Home
</button>
</div>
<div class="input-group">
<input type="text" class="form-control" v-model="inputText" placeholder="Input text ..." @keyup.enter="sendText(inputText+'\n')">
<span class="input-group-btn">
<button class="btn btn-default" type="button" @click="sendText(inputText)">SendText</button>
</span>
</div>
<!-- /input-group -->
</div>
</div>
</div>
Expand All @@ -122,8 +133,17 @@ <h3 class="panel-title">设备详情</h3>
},
refreshCount: 0,
sessionId: null,
pageHidden: false,
inputText: '',
},
mounted: function() {
var self = this;
document.addEventListener(
'visibilitychange',
function() {
self.pageHidden = document.hidden;
}, false
)
this.refreshScreen();
this.initTouchListener();
this.initScreenSize();
Expand Down Expand Up @@ -160,38 +180,55 @@ <h3 class="panel-title">设备详情</h3>
swipe: function(fromX, fromY, toX, toY) {
var self = this;
return $.ajax({
url: "/session/" + self.sessionId + "/wda/dragfromtoforduration",
url: "/session/" + self.sessionId + "/wda/dragfromtoforduration",
method: "POST",
data: JSON.stringify({
fromX: fromX,
fromY: fromY,
toX: toX,
toY: toY,
duration: 0.2,
})
})
},
home: function() {
return $.ajax({
url: "/wda/homescreen",
method: "POST",
data: JSON.stringify({
fromX: fromX,
fromY: fromY,
toX: toX,
toY: toY,
duration: 0.2,
})
})
.then(function(ret) {
console.log(ret);
})
},
home: function() {
sendText: function(text) {
return $.ajax({
url: "/wda/homescreen",
method: "POST",
}).then(function(ret) {
console.log(ret);
})
url: "/session/" + this.sessionId + "/wda/keys",
method: "POST",
data: JSON.stringify({
value: text.split('')
})
})
.then(function(ret) {
console.log(ret);
})
},
refreshScreen: function() {
return $.ajax({
url: "/screenshot",
method: "GET",
}).then(function(ret) {
var imgSrc = "data:image/png;base64," + ret.value;
$("#screen").attr("src", imgSrc);
this.refreshCount += 1;
if (this.pageHidden) {
console.log("Hidden");
setTimeout(this.refreshScreen, 200);
}.bind(this))
return;
}
return $.getJSON("/screenshot")
.done(function(ret) {
var imgSrc = "data:image/png;base64," + ret.value;
$("#screen").attr("src", imgSrc);
this.refreshCount += 1;
setTimeout(this.refreshScreen, 200);
}.bind(this))
.fail(function(ret) {
console.log("load screen failed", ret)
alert("Load screen failed");
})
},
initScreenSize: function() {
$.ajax({
Expand Down Expand Up @@ -269,19 +306,20 @@ <h3 class="panel-title">设备详情</h3>
var first = screen.firstPosition,
second = screen.secondPosition;

element.style.cursor = 'not-allowed'
var defer;
if (second && second.x) {
console.log("Swipe", first, second);
defer = self.swipe(first.x, first.y, second.x, second.y);
} else {
console.log("Tap", first);
defer = self.tap(first.x, first.y).then(function(ret) {
console.log(ret);
})
defer = self.tap(first.x, first.y)
}
defer.then(function() {
console.log("Release operation")
deactiveFinger(0);
deactiveFinger(1);
element.style.cursor = 'auto'
})
}

Expand All @@ -303,6 +341,9 @@ <h3 class="panel-title">设备详情</h3>
}

function mouseDownListener(event) {
if (element.style.cursor == 'not-allowed') {
return;
}
var p = convertPosition(event);
var index = 0;
$(".finger-" + index)
Expand Down

0 comments on commit d96a798

Please sign in to comment.