calabash-android 0.4.0.pre1 → 0.4.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/calabash-android-build.rb +6 -0
- data/bin/calabash-android-setup.rb +2 -3
- data/lib/calabash-android/canned_steps.md +1 -1
- data/lib/calabash-android/helpers.rb +35 -2
- data/lib/calabash-android/lib/TestServer.apk +0 -0
- data/lib/calabash-android/operations.rb +13 -6
- data/lib/calabash-android/version.rb +1 -1
- data/test-server/instrumentation-backend/.classpath +2 -1
- data/test-server/instrumentation-backend/antlr.sh +2 -0
- data/test-server/instrumentation-backend/antlr/UIQuery.g +70 -0
- data/test-server/instrumentation-backend/antlr/UIQuery.tokens +12 -0
- data/test-server/instrumentation-backend/build-libs/antlr-3.4-complete.jar +0 -0
- data/test-server/instrumentation-backend/build-libs/junit.jar +0 -0
- data/test-server/instrumentation-backend/build.xml +56 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRFileStream.java +78 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRInputStream.java +70 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRReaderStream.java +95 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ANTLRStringStream.java +230 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/BaseRecognizer.java +894 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/BitSet.java +325 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/BufferedTokenStream.java +272 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/CharStream.java +57 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/CharStreamState.java +45 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ClassicToken.java +141 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/CommonToken.java +191 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/CommonTokenStream.java +153 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/DFA.java +250 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/EarlyExitException.java +41 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/FailedPredicateException.java +54 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/IntStream.java +122 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/LegacyCommonTokenStream.java +394 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/Lexer.java +340 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedNotSetException.java +41 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedRangeException.java +45 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedSetException.java +44 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedTokenException.java +45 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MismatchedTreeNodeException.java +49 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/MissingTokenException.java +56 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/NoViableAltException.java +57 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/Parser.java +98 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/ParserRuleReturnScope.java +52 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/RecognitionException.java +180 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/RecognizerSharedState.java +144 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/RuleReturnScope.java +42 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/SerializedGrammar.java +204 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/Token.java +92 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenRewriteStream.java +569 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenSource.java +54 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/TokenStream.java +75 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/UnbufferedTokenStream.java +82 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/UnwantedTokenException.java +53 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/BlankDebugEventListener.java +77 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventHub.java +292 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventListener.java +323 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventRepeater.java +88 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugEventSocketProxy.java +358 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugParser.java +101 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTokenStream.java +156 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeAdaptor.java +250 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeNodeStream.java +155 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/DebugTreeParser.java +112 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/ParseTreeBuilder.java +109 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/Profiler.java +772 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/RemoteDebugEventSocketListener.java +541 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/TraceDebugEventListener.java +108 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/debug/Tracer.java +69 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/DoubleKeyMap.java +62 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/FastQueue.java +100 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/IntArray.java +87 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/LookaheadStream.java +161 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/misc/Stats.java +189 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BaseTree.java +349 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BaseTreeAdaptor.java +279 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/BufferedTreeNodeStream.java +489 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonErrorNode.java +108 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTree.java +185 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTreeAdaptor.java +168 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/CommonTreeNodeStream.java +171 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/ParseTree.java +119 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteCardinalityException.java +47 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteEarlyExitException.java +39 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteEmptyStreamException.java +35 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleElementStream.java +210 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleNodeStream.java +70 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleSubtreeStream.java +86 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/RewriteRuleTokenStream.java +76 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/Tree.java +127 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeAdaptor.java +263 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeFilter.java +135 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeIterator.java +132 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeNodeStream.java +106 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeParser.java +169 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreePatternLexer.java +135 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreePatternParser.java +154 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeRewriter.java +124 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeRuleReturnScope.java +41 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeVisitor.java +69 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeVisitorAction.java +47 -0
- data/test-server/instrumentation-backend/src/org/antlr/runtime/tree/TreeWizard.java +531 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java +22 -7
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +4 -4
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Result.java +0 -1
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java +161 -129
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/SetActivityOrientation.java +5 -7
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/GetViewProperty.java +1 -7
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/Query.java +70 -61
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/UIQuery.tokens +12 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ViewMapper.java +63 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQuery.tokens +10 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryLexer.java +945 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/antlr/UIQueryParser.java +463 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/InvalidUIQueryException.java +10 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryAST.java +8 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTClassName.java +115 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTWith.java +157 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryDirection.java +5 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryEvaluator.java +205 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryUtils.java +135 -0
- data/test-server/instrumentation-backend/tests/sh/calaba/instrumentationbackend/query/tests/UIQueryTest.java +134 -0
- metadata +106 -3
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/activity/SetOrientation.java +0 -39
data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/ClearAppData.java
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
package sh.calaba.instrumentationbackend;
|
2
2
|
|
3
|
-
import
|
3
|
+
import java.io.File;
|
4
|
+
|
5
|
+
import android.accounts.Account;
|
6
|
+
import android.accounts.AccountManager;
|
7
|
+
import android.annotation.SuppressLint;
|
4
8
|
import android.os.Bundle;
|
5
9
|
import android.test.InstrumentationTestRunner;
|
6
|
-
import sh.calaba.instrumentationbackend.actions.HttpServer;
|
7
10
|
|
8
|
-
import java.io.File;
|
9
|
-
import java.lang.reflect.Method;
|
10
11
|
|
11
12
|
public class ClearAppData extends InstrumentationTestRunner {
|
12
13
|
@Override
|
@@ -17,8 +18,22 @@ public class ClearAppData extends InstrumentationTestRunner {
|
|
17
18
|
if (cacheDir() != null) {
|
18
19
|
delete(cacheDir().getParentFile());
|
19
20
|
}
|
21
|
+
try {
|
22
|
+
final AccountManager manager = AccountManager.get(getTargetContext());
|
23
|
+
final Account[] accounts = manager.getAccounts();
|
24
|
+
|
25
|
+
for (Account account : accounts) {
|
26
|
+
try {
|
27
|
+
manager.removeAccount(account, null, null);
|
28
|
+
} catch (Exception e) {
|
29
|
+
System.out.println("Unable to remove " + account.name + " of type " + account.type);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
} catch (Exception e) {
|
33
|
+
System.out.println("Error removing accounts");
|
34
|
+
}
|
20
35
|
}
|
21
|
-
|
36
|
+
|
22
37
|
//If provided a file will delete it.
|
23
38
|
//If provided a directory will recursively delete files but preserve directories
|
24
39
|
private void delete(File file_or_directory) {
|
@@ -36,8 +51,8 @@ public class ClearAppData extends InstrumentationTestRunner {
|
|
36
51
|
file_or_directory.delete();
|
37
52
|
}
|
38
53
|
}
|
39
|
-
|
40
|
-
|
54
|
+
|
55
|
+
private File externalCacheDir() {
|
41
56
|
return getTargetContext().getExternalCacheDir();
|
42
57
|
}
|
43
58
|
|
@@ -1,17 +1,17 @@
|
|
1
1
|
package sh.calaba.instrumentationbackend;
|
2
2
|
|
3
|
-
import android.Manifest;
|
4
|
-
import android.content.pm.PackageManager;
|
5
|
-
import com.jayway.android.robotium.solo.PublicViewFetcher;
|
6
3
|
import sh.calaba.instrumentationbackend.actions.Actions;
|
7
4
|
import sh.calaba.instrumentationbackend.actions.HttpServer;
|
5
|
+
import android.Manifest;
|
8
6
|
import android.app.Activity;
|
9
7
|
import android.app.Instrumentation;
|
10
8
|
import android.content.Context;
|
11
|
-
import android.
|
9
|
+
import android.content.pm.PackageManager;
|
12
10
|
import android.location.LocationManager;
|
11
|
+
import android.test.ActivityInstrumentationTestCase2;
|
13
12
|
import android.util.Log;
|
14
13
|
|
14
|
+
import com.jayway.android.robotium.solo.PublicViewFetcher;
|
15
15
|
import com.jayway.android.robotium.solo.SoloEnhanced;
|
16
16
|
|
17
17
|
public class InstrumentationBackend extends ActivityInstrumentationTestCase2 {
|
@@ -1,156 +1,188 @@
|
|
1
1
|
package sh.calaba.instrumentationbackend.actions;
|
2
2
|
|
3
|
-
import java.io
|
3
|
+
import java.io.ByteArrayInputStream;
|
4
|
+
import java.io.ByteArrayOutputStream;
|
5
|
+
import java.io.File;
|
6
|
+
import java.io.IOException;
|
7
|
+
import java.io.PrintWriter;
|
8
|
+
import java.io.StringWriter;
|
9
|
+
import java.util.List;
|
4
10
|
import java.util.Map;
|
5
11
|
import java.util.Properties;
|
6
|
-
import java.util.List;
|
7
12
|
import java.util.concurrent.locks.Condition;
|
8
13
|
import java.util.concurrent.locks.Lock;
|
9
14
|
import java.util.concurrent.locks.ReentrantLock;
|
10
15
|
|
11
|
-
import android.Manifest;
|
12
|
-
import android.app.Activity;
|
13
|
-
import android.app.ActivityManager;
|
14
|
-
import android.content.pm.PackageManager;
|
15
|
-
import android.graphics.Bitmap;
|
16
|
-
import android.view.View;
|
17
16
|
import sh.calaba.instrumentationbackend.Command;
|
18
17
|
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
19
18
|
import sh.calaba.instrumentationbackend.Result;
|
20
|
-
import sh.calaba.instrumentationbackend.query.QueryResult;
|
21
19
|
import sh.calaba.instrumentationbackend.query.Query;
|
20
|
+
import sh.calaba.instrumentationbackend.query.QueryResult;
|
22
21
|
import sh.calaba.org.codehaus.jackson.map.DeserializationConfig.Feature;
|
23
22
|
import sh.calaba.org.codehaus.jackson.map.ObjectMapper;
|
24
|
-
import android.util.Log;
|
25
23
|
import sh.calaba.org.codehaus.jackson.type.TypeReference;
|
24
|
+
import android.graphics.Bitmap;
|
25
|
+
import android.util.Log;
|
26
|
+
import android.view.View;
|
26
27
|
|
27
28
|
public class HttpServer extends NanoHTTPD {
|
28
29
|
private static final String TAG = "InstrumentationBackend";
|
29
|
-
|
30
|
-
|
30
|
+
private boolean running = true;
|
31
|
+
private boolean ready = false;
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
private final Lock lock = new ReentrantLock();
|
34
|
+
private final Condition shutdownCondition = lock.newCondition();
|
34
35
|
|
35
36
|
private final ObjectMapper mapper = createJsonMapper();
|
36
37
|
|
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
|
-
|
38
|
+
private static HttpServer instance;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Creates and returns the singleton instance for HttpServer.
|
42
|
+
*
|
43
|
+
* Can only be called once. Otherwise, you'll get an IllegalStateException.
|
44
|
+
*/
|
45
|
+
public synchronized static HttpServer instantiate() {
|
46
|
+
if (instance != null) {
|
47
|
+
throw new IllegalStateException("Can only instantiate once!");
|
48
|
+
}
|
49
|
+
instance = new HttpServer();
|
50
|
+
return instance;
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Returns the singleton instance for HttpServer.
|
55
|
+
*
|
56
|
+
* If {@link #instantiate()} hasn't already been called, an
|
57
|
+
* IllegalStateException is thrown.
|
58
|
+
*/
|
59
|
+
public synchronized static HttpServer getInstance() {
|
60
|
+
if (instance == null) {
|
61
|
+
throw new IllegalStateException("Must be initialized!");
|
62
|
+
}
|
63
|
+
return instance;
|
64
|
+
}
|
63
65
|
|
64
66
|
private HttpServer() {
|
65
67
|
super(7102, new File("/"));
|
66
68
|
}
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
70
|
+
@SuppressWarnings("rawtypes")
|
71
|
+
public Response serve(String uri, String method, Properties header,
|
72
|
+
Properties params, Properties files) {
|
73
|
+
System.out.println("URI: " + uri);
|
74
|
+
if (uri.endsWith("/ping")) {
|
75
|
+
return new NanoHTTPD.Response(HTTP_OK, MIME_HTML, "pong");
|
76
|
+
|
77
|
+
} else if (uri.endsWith("/map")) {
|
78
|
+
try {
|
79
|
+
String commandString = params.getProperty("json");
|
80
|
+
ObjectMapper mapper = new ObjectMapper();
|
81
|
+
Map command = mapper.readValue(commandString, Map.class);
|
82
|
+
|
83
|
+
String uiQuery = (String) command.get("query");
|
84
|
+
Map op = (Map) command.get("operation");
|
85
|
+
String methodName = (String) op.get("method_name");
|
86
|
+
List arguments = (List) op.get("arguments");
|
87
|
+
|
88
|
+
QueryResult queryResult = new Query(uiQuery,arguments).execute();
|
89
|
+
|
90
|
+
return new NanoHTTPD.Response(HTTP_OK, "application/json;charset=utf-8",
|
91
|
+
queryResult.asJson());
|
92
|
+
} catch (IOException e) {
|
93
|
+
e.printStackTrace();
|
94
|
+
} catch (Exception e ) {
|
95
|
+
System.err.println("Query failed!");
|
82
96
|
e.printStackTrace();
|
83
|
-
return new Response(HTTP_INTERNALERROR, MIME_PLAINTEXT, "Could not parse arguments as JSON");
|
84
97
|
}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
return new NanoHTTPD.Response(HTTP_INTERNALERROR, MIME_HTML, "Query failed");
|
99
|
+
} else if (uri.endsWith("/query")) {
|
100
|
+
try {
|
101
|
+
String commandString = params.getProperty("json");
|
102
|
+
ObjectMapper mapper = new ObjectMapper();
|
103
|
+
Map<String, String> command = mapper.readValue(commandString,
|
104
|
+
new TypeReference<Map<String, String>>() {
|
105
|
+
});
|
106
|
+
QueryResult result = new Query(command.get("query")).executeInMainThread();
|
107
|
+
return new NanoHTTPD.Response(HTTP_OK, MIME_HTML,
|
108
|
+
result.asJson());
|
109
|
+
} catch (IOException e) {
|
110
|
+
e.printStackTrace();
|
111
|
+
return new Response(HTTP_INTERNALERROR, MIME_PLAINTEXT,
|
112
|
+
"Could not parse arguments as JSON");
|
113
|
+
}
|
114
|
+
} else if (uri.endsWith("/kill")) {
|
115
|
+
lock.lock();
|
116
|
+
try {
|
117
|
+
running = false;
|
118
|
+
System.out.println("Stopping test server");
|
119
|
+
stop();
|
120
|
+
|
121
|
+
shutdownCondition.signal();
|
122
|
+
return new NanoHTTPD.Response(HTTP_OK, MIME_HTML,
|
123
|
+
"Affirmative!");
|
124
|
+
} finally {
|
125
|
+
lock.unlock();
|
126
|
+
}
|
127
|
+
|
128
|
+
} else if (uri.endsWith("/ready")) {
|
129
|
+
return new Response(HTTP_OK, MIME_HTML, Boolean.toString(ready));
|
101
130
|
|
102
131
|
} else if (uri.endsWith("/screenshot")) {
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
System.out.println("params: "+ params);
|
124
|
-
System.out.println("files: "+ files);
|
132
|
+
try {
|
133
|
+
Bitmap bitmap;
|
134
|
+
View rootView = getRootView();
|
135
|
+
rootView.setDrawingCacheEnabled(true);
|
136
|
+
rootView.buildDrawingCache(true);
|
137
|
+
bitmap = Bitmap.createBitmap(rootView.getDrawingCache());
|
138
|
+
rootView.setDrawingCacheEnabled(false);
|
139
|
+
|
140
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
141
|
+
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
|
142
|
+
return new NanoHTTPD.Response(HTTP_OK, "image/png",
|
143
|
+
new ByteArrayInputStream(out.toByteArray()));
|
144
|
+
} catch (Exception e) {
|
145
|
+
StringWriter sw = new StringWriter();
|
146
|
+
PrintWriter pw = new PrintWriter(sw);
|
147
|
+
e.printStackTrace(pw);
|
148
|
+
return new NanoHTTPD.Response(HTTP_INTERNALERROR, null,
|
149
|
+
sw.toString());
|
150
|
+
}
|
151
|
+
}
|
125
152
|
|
153
|
+
System.out.println("header: " + header);
|
154
|
+
System.out.println("params: " + params);
|
155
|
+
System.out.println("files: " + files);
|
126
156
|
|
127
|
-
|
128
|
-
System.out.println("command: "+ commandString);
|
157
|
+
String commandString = params.getProperty("json");
|
158
|
+
System.out.println("command: " + commandString);
|
129
159
|
String result = toJson(runCommand(commandString));
|
130
160
|
System.out.println("result:" + result);
|
131
|
-
|
132
|
-
return new NanoHTTPD.Response(
|
161
|
+
|
162
|
+
return new NanoHTTPD.Response(HTTP_OK, MIME_HTML, result);
|
133
163
|
}
|
134
164
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
165
|
+
private View getRootView() {
|
166
|
+
for (int i = 0; i < 25; i++) {
|
167
|
+
try {
|
168
|
+
View decorView = InstrumentationBackend.solo
|
169
|
+
.getCurrentActivity().getWindow().getDecorView();
|
170
|
+
if (decorView != null) {
|
171
|
+
View rootView = decorView
|
172
|
+
.findViewById(android.R.id.content);
|
173
|
+
if (rootView != null) {
|
174
|
+
return rootView;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
System.out.println("Retry: " + i);
|
178
|
+
|
179
|
+
Thread.sleep(200);
|
180
|
+
} catch (Exception e) {
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
throw new RuntimeException("Could not find any views");
|
185
|
+
}
|
154
186
|
|
155
187
|
private ObjectMapper createJsonMapper() {
|
156
188
|
ObjectMapper mapper = new ObjectMapper();
|
@@ -177,22 +209,22 @@ public class HttpServer extends NanoHTTPD {
|
|
177
209
|
}
|
178
210
|
}
|
179
211
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
212
|
+
public void waitUntilShutdown() throws InterruptedException {
|
213
|
+
lock.lock();
|
214
|
+
try {
|
215
|
+
while (running) {
|
216
|
+
shutdownCondition.await();
|
217
|
+
}
|
218
|
+
} finally {
|
219
|
+
lock.unlock();
|
220
|
+
}
|
221
|
+
}
|
190
222
|
|
191
223
|
public static void log(String message) {
|
192
224
|
Log.i(TAG, message);
|
193
225
|
}
|
194
226
|
|
195
|
-
|
196
|
-
|
197
|
-
|
227
|
+
public void setReady() {
|
228
|
+
ready = true;
|
229
|
+
}
|
198
230
|
}
|
@@ -8,19 +8,17 @@ public class SetActivityOrientation implements Action {
|
|
8
8
|
|
9
9
|
@Override
|
10
10
|
public Result execute(String... args) {
|
11
|
-
if (args.length == 0) {
|
11
|
+
if (args == null || args.length == 0) {
|
12
12
|
throw new IllegalArgumentException("No orientation provided. Use 'landscape' or 'portrait'");
|
13
13
|
}
|
14
14
|
String orientation = args[0].toLowerCase();
|
15
15
|
|
16
|
-
if (orientation
|
17
|
-
throw new IllegalArgumentException("Invalid orientation '" + orientation + "'. Use 'landscape' or 'portrait'");
|
18
|
-
}
|
19
|
-
|
20
|
-
if (orientation == "landscape") {
|
16
|
+
if (orientation.equals("landscape")) {
|
21
17
|
InstrumentationBackend.solo.setActivityOrientation(0);
|
22
|
-
} else {
|
18
|
+
} else if(orientation.equals("portrait")) {
|
23
19
|
InstrumentationBackend.solo.setActivityOrientation(1);
|
20
|
+
} else {
|
21
|
+
throw new IllegalArgumentException("Invalid orientation '" + orientation + "'. Use 'landscape' or 'portrait'");
|
24
22
|
}
|
25
23
|
// Wait 100ms for orientation change to happen.
|
26
24
|
sleep(100);
|
@@ -23,13 +23,7 @@ public class GetViewProperty extends WaitForViewById implements Action {
|
|
23
23
|
try {
|
24
24
|
View view = getViewById(viewId, 60000);
|
25
25
|
if( view != null ) {
|
26
|
-
|
27
|
-
//
|
28
|
-
// String propertyName = args[1].toLowerCase();
|
29
|
-
// String value = getPropertyValue(propertyName, view, args);
|
30
|
-
// result.setMessage( value );
|
31
|
-
|
32
|
-
String propertyName = args[1].toLowerCase();
|
26
|
+
String propertyName = args[1];
|
33
27
|
return getPropertyValue(propertyName, view, args);
|
34
28
|
} else {
|
35
29
|
return new Result(false, "Timed out while waiting for view with id:'" + viewId + "'");
|