calabash-android 0.4.9.pre2 → 0.4.9.pre3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3fab2a76c6cc2a3bf77ae148335958aff340aee
4
- data.tar.gz: 3c226619ad79a99a983804ce4d1beb5493dc2fa4
3
+ metadata.gz: 7382b7dab96dabda3ddc20acc43dcf35dd064673
4
+ data.tar.gz: db95474aa5d4d4a16e5226da72c1e961d880666e
5
5
  SHA512:
6
- metadata.gz: 089f8c510215dd629d917750ba4da0331f6e10581f94e2791552e7736d04eb9b6870f04f40b71afafc5392149c0855db5a4b83b2ff33a5446cdc881516971c31
7
- data.tar.gz: 6cf4519e2285e506875f58a72d84c8f05912cb6c2a27f1edda1947bd9d9370f649fb3be8da93a2b2932adda633199723a2a01f8180b4e987aa25e50dc7513a76
6
+ metadata.gz: 066c58155a9d3e3c0a63384340c0e2998fa19fdb75521ccbb0020bfd12acd2e316fb519a0da7400ee024bb150ae1bea0d63f3ab0e4a8d58b7f69e55e9f64d9d0
7
+ data.tar.gz: fe8ccf72731d38737eadccc1ee3ab10535f3e3c44098e409f49081d092b6d45abff9bf2112a8b5dcb9d5815584f6ffe5df4bab27db03deb1b97df7b5082f48b7
@@ -1,5 +1,5 @@
1
1
  module Calabash
2
2
  module Android
3
- VERSION = "0.4.9.pre2"
3
+ VERSION = "0.4.9.pre3"
4
4
  end
5
5
  end
@@ -1,12 +1,24 @@
1
1
  package sh.calaba.instrumentationbackend.actions;
2
2
 
3
+ import java.io.IOException;
3
4
  import java.util.ArrayList;
5
+ import java.util.Collection;
4
6
  import java.util.List;
5
7
  import java.util.Map;
6
8
  import java.util.concurrent.Callable;
9
+ import java.util.concurrent.ExecutionException;
10
+ import java.util.concurrent.Future;
11
+ import java.util.concurrent.TimeUnit;
12
+ import java.util.concurrent.TimeoutException;
7
13
  import java.util.concurrent.atomic.AtomicReference;
8
14
 
15
+ import sh.calaba.instrumentationbackend.json.JSONUtils;
16
+ import sh.calaba.instrumentationbackend.query.ast.DoubleFuture;
9
17
  import sh.calaba.instrumentationbackend.query.ast.UIQueryUtils;
18
+ import sh.calaba.org.codehaus.jackson.JsonParseException;
19
+ import sh.calaba.org.codehaus.jackson.map.JsonMappingException;
20
+ import sh.calaba.org.codehaus.jackson.map.ObjectMapper;
21
+ import android.util.Log;
10
22
 
11
23
  @SuppressWarnings({ "rawtypes", "unchecked" })
12
24
  public class ViewDump {
@@ -37,13 +49,51 @@ public class ViewDump {
37
49
 
38
50
  private Map<?, ?> sameTreeWithoutElements(Map<?, ?> dump) {
39
51
  Map node = UIQueryUtils.mapWithElAsNull(dump);
40
- List<Map> nodeChildren = (List<Map>) node.get("children");
52
+ List nodeChildren = (List) node.get("children");
41
53
  List<Map> childrenNoEl = new ArrayList<Map>(nodeChildren.size());
42
- for (Map child : nodeChildren) {
43
- childrenNoEl.add(sameTreeWithoutElements(child));
54
+
55
+ for (Object child : nodeChildren) {
56
+ if (child instanceof Map) {
57
+ childrenNoEl.add(sameTreeWithoutElements((Map)child));
58
+ }
59
+ else {
60
+ Log.i("Calabash", child.toString());
61
+ Future webResults = (Future) child;
62
+
63
+ try {
64
+ Map webResultsMap = (Map) webResults.get(10,TimeUnit.SECONDS);
65
+ String json = (String) webResultsMap.get("result");
66
+ ObjectMapper mapper = new ObjectMapper();
67
+ List jsonResults = mapper.readValue(json, List.class);
68
+ for(Object m : jsonResults) {
69
+ Map domElement = UIQueryUtils.mapWithElAsNull(UIQueryUtils.serializeViewToDump(m));
70
+ childrenNoEl.add(domElement);
71
+ }
72
+
73
+
74
+ } catch (InterruptedException e) {
75
+
76
+ } catch (ExecutionException e) {
77
+
78
+ } catch (TimeoutException e) {
79
+
80
+ } catch (JsonParseException e) {
81
+ // TODO Auto-generated catch block
82
+ e.printStackTrace();
83
+ throw new RuntimeException(e);
84
+ } catch (JsonMappingException e) {
85
+ // TODO Auto-generated catch block
86
+ e.printStackTrace();
87
+ } catch (IOException e) {
88
+ // TODO Auto-generated catch block
89
+ e.printStackTrace();
90
+ }
91
+ }
44
92
  }
45
93
  node.put("children",childrenNoEl);
46
94
  return node;
95
+
96
+
47
97
  }
48
98
 
49
99
 
@@ -11,6 +11,7 @@ import java.util.Map;
11
11
  import sh.calaba.instrumentationbackend.InstrumentationBackend;
12
12
  import sh.calaba.instrumentationbackend.actions.webview.CalabashChromeClient.WebFuture;
13
13
  import sh.calaba.org.codehaus.jackson.map.ObjectMapper;
14
+ import android.util.Log;
14
15
  import android.webkit.WebView;
15
16
 
16
17
  public class QueryHelper {
@@ -94,7 +95,7 @@ public class QueryHelper {
94
95
 
95
96
  script = script.replaceFirst("%@", selector);
96
97
  script = script.replaceFirst("%@", type);
97
-
98
+
98
99
  CalabashChromeClient chromeClient = CalabashChromeClient.prepareWebView(webView);
99
100
  webView.loadUrl("javascript:calabash_result = " + script + ";prompt('calabash:' + calabash_result);");
100
101
  return chromeClient.getResult();
@@ -17,6 +17,7 @@ import java.util.concurrent.atomic.AtomicReference;
17
17
  import org.antlr.runtime.tree.CommonTree;
18
18
 
19
19
  import sh.calaba.instrumentationbackend.InstrumentationBackend;
20
+ import sh.calaba.instrumentationbackend.actions.webview.CalabashChromeClient.WebFuture;
20
21
  import sh.calaba.instrumentationbackend.actions.webview.QueryHelper;
21
22
  import sh.calaba.instrumentationbackend.query.CompletedFuture;
22
23
  import sh.calaba.instrumentationbackend.query.Query;
@@ -25,6 +26,7 @@ import sh.calaba.instrumentationbackend.query.antlr.UIQueryParser;
25
26
  import sh.calaba.org.codehaus.jackson.map.ObjectMapper;
26
27
  import sh.calaba.org.codehaus.jackson.type.TypeReference;
27
28
  import android.text.InputType;
29
+ import android.util.Log;
28
30
  import android.view.View;
29
31
  import android.webkit.WebView;
30
32
  import android.widget.Button;
@@ -35,6 +37,7 @@ public class UIQueryUtils {
35
37
 
36
38
  @SuppressWarnings({ "unchecked", "rawtypes" })
37
39
  public static List subviews(Object o) {
40
+
38
41
  try {
39
42
  Method getChild = o.getClass().getMethod("getChildAt", int.class);
40
43
  getChild.setAccessible(true);
@@ -59,6 +62,19 @@ public class UIQueryUtils {
59
62
 
60
63
  }
61
64
 
65
+ @SuppressWarnings({ "rawtypes" })
66
+ public static Future webViewSubViews(WebView o) {
67
+
68
+ Log.i("Calabash", "About to webViewSubViews");
69
+
70
+
71
+ WebFuture controls = QueryHelper.executeAsyncJavascriptInWebviews(o,
72
+ "calabash.js", "input,button","css");
73
+
74
+ return controls;
75
+
76
+ }
77
+
62
78
  @SuppressWarnings({ "unchecked", "rawtypes" })
63
79
  public static List parents(Object o) {
64
80
  try {
@@ -167,9 +183,11 @@ public class UIQueryUtils {
167
183
  return ViewMapper.getIdForView(view);
168
184
  }
169
185
 
170
- @SuppressWarnings("rawtypes")
186
+ @SuppressWarnings({ "rawtypes", "unchecked" })
171
187
  public static Future evaluateAsyncInMainThread(final Callable callable)
172
- throws Exception {
188
+ throws Exception {
189
+
190
+
173
191
  final AtomicReference<Future> result = new AtomicReference<Future>();
174
192
  final AtomicReference<Exception> errorResult = new AtomicReference<Exception>();
175
193
 
@@ -300,17 +318,26 @@ public class UIQueryUtils {
300
318
 
301
319
  @SuppressWarnings({ "rawtypes", "unchecked" })
302
320
  protected static Map<?, ?> dumpRecursively(Map parentView,
303
- List<View> children) {
321
+ List children) {
304
322
  ArrayList childrenArray = new ArrayList(32);
305
323
  for (int i = 0; i < children.size(); i++) {
306
- View view = children.get(i);
324
+ Object view = children.get(i);
307
325
  Map serializedChild = serializeViewToDump(view);
308
326
  List<Integer> childPath = new ArrayList<Integer>(
309
327
  (List) parentView.get("path"));
310
328
  childPath.add(i);
311
329
  serializedChild.put("path", childPath);
312
- childrenArray.add(dumpRecursively(serializedChild,
313
- UIQueryUtils.subviews(view)));
330
+ List childrenList = null;
331
+ if (view instanceof WebView) {
332
+ Future webViewSubViews = webViewSubViews((WebView) view);
333
+ childrenArray.add(webViewSubViews);
334
+ }
335
+ else {
336
+ childrenList = UIQueryUtils.subviews(view);
337
+ childrenArray.add(dumpRecursively(serializedChild,
338
+ childrenList));
339
+ }
340
+
314
341
  }
315
342
 
316
343
  parentView.put("children", childrenArray);
@@ -339,31 +366,138 @@ public class UIQueryUtils {
339
366
  return currentView;
340
367
  }
341
368
 
369
+ /*
370
+ *
371
+ "enabled" => true,
372
+ "visible" => true,
373
+ "children" => [],
374
+ "label" => nil,
375
+ "rect" => {
376
+ "center_y" => 158.5,
377
+ "center_x" => 300.0,
378
+ "height" => 25,
379
+ "y" => 146,
380
+ "width" => 600,
381
+ "x" => 0
382
+ },
383
+ "type" => "android.widget.TextView",
384
+ "id" => "FacebookTextView",
385
+ "el" => nil,
386
+ "name" => "",
387
+ "action" => nil,
388
+ "value" => "",
389
+ "path" => [
390
+ [0] 0,
391
+ [1] 0,
392
+ [2] 2,
393
+ [3] 0,
394
+ [4] 2
395
+ ],
396
+ "hit-point" => {
397
+ "y" => 158.5,
398
+ "x" => 300.0
399
+ },
400
+ "entry_types" => [
401
+ [0] "0"
402
+ ]
403
+ */
342
404
  @SuppressWarnings({ "rawtypes", "unchecked" })
343
- public static Map<?, ?> serializeViewToDump(View view) {
344
- if (view == null) {
405
+ public static Map<?, ?> serializeViewToDump(Object viewOrMap) {
406
+ if (viewOrMap == null) {
345
407
  return null;
346
408
  }
409
+
410
+ if (viewOrMap instanceof Map)
411
+ {
412
+ Map map = (Map) viewOrMap;
413
+ map.put("el", map);
414
+
415
+ Map rect = (Map) map.get("rect");
416
+ Map hitPoint = extractHitPointFromRect(rect);
417
+
418
+ map.put("hit-point", hitPoint);
419
+ Map result = new HashMap();
420
+ result.put("type", "touch");
421
+ result.put("gesture", "tap");
422
+ map.put("action", result);
423
+ map.put("enabled", true);
424
+ map.put("visible", true);
425
+ String nodeName = (String) map.get("nodeName");
426
+ if (nodeName != null && nodeName.toLowerCase().equals("input")) {
427
+ String domType = extractDomType((String)map.get("html"));
428
+ map.put("domType", domType);
429
+ Log.i("Calabash - domtype", domType);
430
+ if (domType!=null && domType.equals("password")) {
431
+ map.put("entry_types", Collections.singletonList("password"));
432
+ }
433
+ else {
434
+ map.put("entry_types", Collections.singletonList("text"));
435
+ }
436
+
437
+ }
438
+
439
+
440
+
441
+ map.put("value", null);
442
+ map.put("type", "dom");
443
+ map.put("name", null);
444
+ map.put("label", null);
445
+ return map;
446
+
447
+ }
448
+ else
449
+ {
450
+ Map m = new HashMap();
451
+
452
+ View view = (View) viewOrMap;
453
+ m.put("id", getId(view));
454
+ m.put("el", view);
455
+
456
+ Map rect = ViewMapper.getRectForView(view);
457
+ Map hitPoint = extractHitPointFromRect(rect);
458
+
459
+ m.put("rect", rect);
460
+ m.put("hit-point", hitPoint);
461
+ m.put("action", actionForView(view));
462
+ m.put("enabled", view.isEnabled());
463
+ m.put("visible", isVisible(view));
464
+ m.put("entry_types", elementEntryTypes(view));
465
+ m.put("value", extractValueFromView(view));
466
+ m.put("type", ViewMapper.getClassNameForView(view));
467
+ m.put("name", getNameForView(view));
468
+ m.put("label", ViewMapper.getContentDescriptionForView(view));
469
+ return m;
470
+ }
471
+
472
+
473
+
474
+
475
+ }
347
476
 
348
- Map m = new HashMap();
349
-
350
- m.put("id", getId(view));
351
- m.put("el", view);
352
-
353
- Map rect = ViewMapper.getRectForView(view);
354
- Map hitPoint = extractHitPointFromRect(rect);
355
-
356
- m.put("rect", rect);
357
- m.put("hit-point", hitPoint);
358
- m.put("action", actionForView(view));
359
- m.put("enabled", view.isEnabled());
360
- m.put("visible", isVisible(view));
361
- m.put("entry_types", elementEntryTypes(view));
362
- m.put("value", extractValueFromView(view));
363
- m.put("type", ViewMapper.getClassNameForView(view));
364
- m.put("name", getNameForView(view));
365
- m.put("label", ViewMapper.getContentDescriptionForView(view));
366
- return m;
477
+ public static String extractDomType(String string) {
478
+ String[] split = string.split("type=");
479
+ if (split.length > 1) {
480
+ String lastPart = split[1];
481
+ if (lastPart == null) {
482
+ return null;
483
+ }
484
+ if (lastPart.charAt(0) == '"' || lastPart.charAt(0) == '\'') {
485
+ int endIndex = -1;
486
+ for (int i=1;i<lastPart.length();i++) {
487
+ if (lastPart.charAt(i) == '\'' || lastPart.charAt(i) == '"') {
488
+ endIndex = i;
489
+ break;
490
+ }
491
+ }
492
+
493
+ if (endIndex > 0) {
494
+ return lastPart.substring(1,endIndex);
495
+ }
496
+
497
+ }
498
+ }
499
+ return null;
500
+
367
501
  }
368
502
 
369
503
  public static List<String> elementEntryTypes(View view) {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calabash-android
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.9.pre2
4
+ version: 0.4.9.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Maturana Larsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-15 00:00:00.000000000 Z
11
+ date: 2013-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber