-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
117 lines (103 loc) · 2.8 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var wd = require('wd');
var path = require('path');
var TouchAction = require('wd').TouchAction;
var MultiAction = require('wd').MultiAction;
var webviewApp = path.resolve(require.resolve('multi-touch-draw-app'), '..', require('multi-touch-draw-app')[1]);
var driver = wd.remote('localhost', 4723);
var pi = Math.PI;
var caps = {
platformName: 'iOS',
platformVersion: '8.4',
deviceName: 'iPhone 6',
app: webviewApp
}
var drawLine =function(x1, y1, x2, y2){
var line = (new TouchAction(driver))
.press({x:x1,y:y1})
.moveTo({x:x2, y:y2})
.release();
driver.performTouchAction(line);
}
var circleAction = function() {
var cos = Math.cos;
var sin = Math.sin;
var pi = Math.PI;
var theta = 0;
var h = 400;
var k = 400;
var r = 100;
var prev = {x: h+r*cos(theta), y: k+r*sin(theta)}
var action = new TouchAction(driver);
action.press(prev);
for (theta; theta < 2*pi; theta+=2*pi/36) {
var next = {x: h+r*cos(theta), y: k+r*sin(theta)}
var offset = {x: next.x-prev.x, y: next.y-prev.y}
action.moveTo(offset);
prev = next;
}
action.release();
return action;
}
var h = 150;
var k = 150;
var r = 100;
var arcAction = function(start, end) {
var cos = Math.cos;
var sin = Math.sin;
var theta = start;
var prev = {x: h+r*cos(theta), y: k+r*sin(theta)}
var action = new TouchAction(driver);
action.press(prev);
for (; theta < end; theta+=2*pi/100) {
var next = {x: h+r*cos(theta), y: k+r*sin(theta)}
var offset = {x: next.x-prev.x, y: next.y-prev.y}
action.moveTo(offset);
prev = next;
}
action.release();
return action;
}
var innerArcAction = function(start, end) {
var cos = Math.cos;
var sin = Math.sin;
var theta = start;
var step = 4*pi/100;
var min_radius = 30;
var prev = {x: h-r*cos(theta), y: k+r*sin(theta)}
var action = new TouchAction(driver);
action.press(prev);
for (; theta < end; theta+=step) {
var rad = 7.5991*Math.pow(theta-start-pi, 2)+25;
var next = {x: h-rad*cos(theta), y: k+rad*sin(theta)}
var offset = {x: next.x-prev.x, y: next.y-prev.y}
action.moveTo(offset);
prev = next;
}
action.release();
return action;
}
var multiAction = function() {
var multi = new MultiAction();
multi.add(
arcAction(0, 2*pi/3*1),
arcAction(2*pi/3*1, 2*pi/3*2),
arcAction(2*pi/3*2, 2*pi/3*3)
);
return multi;
}
var innerArcMulti = function() {
var multi = new MultiAction();
multi.add(
innerArcAction(2*pi/3*1 + pi/3, 2*pi/3*1 + pi + pi/8 + pi/3),
innerArcAction(2*pi/3*2 + pi/3, 2*pi/3*2 + pi + pi/8 + pi/3),
innerArcAction(2*pi/3*3 + pi/3, 2*pi/3*3 + pi + pi/8 + pi/3)
);
return multi;
}
driver.init(caps, function() {
driver.sleep('2000', function(){
driver.performMultiAction(multiAction(), function() {
driver.performMultiAction(innerArcMulti());
});
})
});