calabash-android 0.3.3.pre3 → 0.3.3.pre5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. data/bin/calabash-android +12 -0
  2. data/bin/calabash-android-console.rb +21 -0
  3. data/bin/calabash-android-generate.rb +0 -2
  4. data/{features-skeleton/.irbrc → irbrc} +4 -2
  5. data/lib/calabash-android/lib/TestServer.apk +0 -0
  6. data/lib/calabash-android/operations.rb +2 -1
  7. data/lib/calabash-android/version.rb +1 -1
  8. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Command.java +17 -2
  9. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +13 -0
  10. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListData.java +85 -0
  11. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemProperties.java +2 -3
  12. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/search/EnterQueryByIndex.java +1 -7
  13. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/CalabashChromeClient.java +5 -4
  14. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/DumpBodyHtml.java +4 -10
  15. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/DumpHtml.java +3 -10
  16. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/EnterTextByCssSelector.java +21 -27
  17. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteAsyncJavascript.java +3 -9
  18. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java +13 -20
  19. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/GetLoadProgress.java +2 -3
  20. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/PressByCssSelector.java +12 -18
  21. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/QueryHelper.java +10 -12
  22. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ScrollTo.java +1 -1
  23. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetPropertyByCssSelector.java +5 -13
  24. metadata +5 -4
  25. data/features-skeleton/irb_android.sh +0 -22
@@ -9,6 +9,7 @@ require File.join(File.dirname(__FILE__), "calabash-android-generate")
9
9
  require File.join(File.dirname(__FILE__), "calabash-android-build")
10
10
  require File.join(File.dirname(__FILE__), "calabash-android-run")
11
11
  require File.join(File.dirname(__FILE__), "calabash-android-setup")
12
+ require File.join(File.dirname(__FILE__), "calabash-android-console")
12
13
 
13
14
  @features_dir = File.join(FileUtils.pwd, "features")
14
15
  @support_dir = File.join(@features_dir, "support")
@@ -52,6 +53,17 @@ elsif cmd == 'run'
52
53
  elsif cmd == 'gen'
53
54
  calabash_scaffold
54
55
  exit 0
56
+ elsif cmd == 'console'
57
+ if ARGV.empty?
58
+ puts "Please specify an app"
59
+ exit 1
60
+ end
61
+ unless File.exist? ARGV.first
62
+ puts "No such file #{ARGV.first}"
63
+ exit 1
64
+ end
65
+ calabash_console ARGV.first
66
+ exit 0
55
67
  elsif cmd == 'setup'
56
68
  calabash_setup
57
69
  exit 0
@@ -0,0 +1,21 @@
1
+ def calabash_console(app_path = nil)
2
+ test_server_path = test_server_path(app_path)
3
+
4
+ unless ENV["TEST_SERVER_PORT"]
5
+ ENV["TEST_SERVER_PORT"] = "34777"
6
+ end
7
+
8
+ unless ENV["IRBRC"]
9
+ ENV["IRBRC"] = File.join(File.dirname(__FILE__), '..', 'irbrc')
10
+ end
11
+
12
+ unless ENV["PACKAGE_NAME"]
13
+ ENV["PACKAGE_NAME"] = package_name(app_path)
14
+ end
15
+
16
+ unless ENV["MAIN_ACTIVITY"]
17
+ ENV["MAIN_ACTIVITY"] = main_activity(app_path)
18
+ end
19
+
20
+ system "irb"
21
+ end
@@ -12,8 +12,6 @@ def calabash_scaffold
12
12
  exit 2 unless STDIN.gets.chomp == ''
13
13
 
14
14
  FileUtils.cp_r(@source_dir, @features_dir)
15
- FileUtils.mv "#{@features_dir}/.irbrc", "."
16
- FileUtils.mv "#{@features_dir}/irb_android.sh", "."
17
15
 
18
16
  msg("Info") do
19
17
  puts "features subdirectory created. \n"
@@ -6,7 +6,7 @@ ARGV.concat [ "--readline",
6
6
  "--prompt-mode",
7
7
  "simple" ]
8
8
 
9
- # 25 entries in the list
9
+ # 50 entries in the list
10
10
  IRB.conf[:SAVE_HISTORY] = 50
11
11
 
12
12
  # Store results in home directory with specified file name
@@ -15,4 +15,6 @@ IRB.conf[:HISTORY_FILE] = ".irb-history"
15
15
  require 'calabash-android/operations'
16
16
  include Calabash::Android::Operations
17
17
 
18
- start_test_server_in_background
18
+ def embed(*args)
19
+ puts "Embed is a Cucumber method and is not available in this console."
20
+ end
@@ -243,7 +243,8 @@ module Operations
243
243
  path = "#{prefix}#{name}_#{@@screenshot_count}.png"
244
244
 
245
245
  if ENV["SCREENSHOT_VIA_USB"] == "true"
246
- screenshot_cmd = "java -jar #{File.join(File.dirname(__FILE__), 'lib', 'screenShotTaker.jar')} #{path}"
246
+ device_args = "-s #{@serial}" if @serial
247
+ screenshot_cmd = "java -jar #{File.join(File.dirname(__FILE__), 'lib', 'screenShotTaker.jar')} #{path} #{device_args}"
247
248
  log screenshot_cmd
248
249
  raise "Could not take screenshot" unless system(screenshot_cmd)
249
250
  else
@@ -1,5 +1,5 @@
1
1
  module Calabash
2
2
  module Android
3
- VERSION = "0.3.3.pre3"
3
+ VERSION = "0.3.3.pre5"
4
4
  end
5
5
  end
@@ -1,7 +1,9 @@
1
1
  package sh.calaba.instrumentationbackend;
2
2
 
3
3
  import java.util.Arrays;
4
+ import java.util.concurrent.atomic.AtomicReference;
4
5
 
6
+ import android.os.Looper;
5
7
  import sh.calaba.instrumentationbackend.actions.Action;
6
8
 
7
9
 
@@ -41,8 +43,21 @@ public class Command {
41
43
  }
42
44
 
43
45
  public Result execute() {
44
- Action action = InstrumentationBackend.actions.lookup(getCommand());
45
- return action.execute(getArguments());
46
+ final Action action = InstrumentationBackend.actions.lookup(getCommand());
47
+
48
+ if ( Looper.getMainLooper().getThread() != Thread.currentThread()) {
49
+ return action.execute(getArguments());
50
+ }
51
+
52
+ final AtomicReference<Result> result = new AtomicReference<Result>();
53
+ InstrumentationBackend.instrumentation.runOnMainSync(new Runnable() {
54
+ @Override
55
+ public void run() {
56
+ result.set(action.execute(getArguments()));
57
+ }
58
+ });
59
+ return result.get();
60
+
46
61
  }
47
62
 
48
63
  }
@@ -2,8 +2,11 @@ package sh.calaba.instrumentationbackend;
2
2
 
3
3
  import sh.calaba.instrumentationbackend.actions.Actions;
4
4
  import sh.calaba.instrumentationbackend.actions.HttpServer;
5
+ import android.app.Activity;
5
6
  import android.app.Instrumentation;
7
+ import android.content.Context;
6
8
  import android.test.ActivityInstrumentationTestCase2;
9
+ import android.location.LocationManager;
7
10
  import android.util.Log;
8
11
 
9
12
  import com.jayway.android.robotium.solo.SoloEnhanced;
@@ -53,6 +56,8 @@ public class InstrumentationBackend extends ActivityInstrumentationTestCase2 {
53
56
  e.printStackTrace();
54
57
  }
55
58
 
59
+ removeTestLocationProviders(this.getActivity());
60
+
56
61
  this.getActivity().finish();
57
62
  super.tearDown();
58
63
 
@@ -65,4 +70,12 @@ public class InstrumentationBackend extends ActivityInstrumentationTestCase2 {
65
70
  public static void logError(String message) {
66
71
  Log.e(TAG, message);
67
72
  }
73
+
74
+ private static void removeTestLocationProviders(Activity activity) {
75
+ final LocationManager locationService =
76
+ (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
77
+ for (final String provider : locationService.getAllProviders()) {
78
+ locationService.removeTestProvider(provider);
79
+ }
80
+ }
68
81
  }
@@ -0,0 +1,85 @@
1
+ package sh.calaba.instrumentationbackend.actions.list;
2
+
3
+ import java.util.ArrayList;
4
+
5
+ import sh.calaba.instrumentationbackend.InstrumentationBackend;
6
+ import sh.calaba.instrumentationbackend.Result;
7
+ import sh.calaba.instrumentationbackend.actions.Action;
8
+ import android.widget.ListView;
9
+
10
+ /**
11
+ * Provides access to a list through its adapter.
12
+ *
13
+ * args:
14
+ * <ul>
15
+ * <li>1-based list index (first list is used if not specified)</li>
16
+ * </ul>
17
+ *
18
+ * eg: (all items of the 1st list) <code>performAction( 'get_list_data' )</code>
19
+ * eg: (all items of the 2nd list) <code>performAction( 'get_list_data', 2 )</code>
20
+ *
21
+ * @return <code>bonusInformation</code>: a JSON-formatted Array<String> that is an
22
+ * Array of objects with a single property "value". The value of this property is generated by calling
23
+ * <code>list.getAdapter().getItem().toString()</code>, so make sure you implement the toString() method
24
+ * on the objects that go to the adapter AND that it returns a value valid for JSON.
25
+ *
26
+ * In ruby we can then parse the response:
27
+ * <pre>
28
+ * result = performAction('get_list_data')
29
+ * bonusInfo = result['bonusInformation'][0]
30
+ * JSON.parse(bonusInfo).each do |item|
31
+ * puts "#{item["value"]}"
32
+ * end
33
+ * </pre>
34
+ *
35
+ * @author Juan Delgado (juan@ustwo.co.uk)
36
+ */
37
+
38
+ public class GetListData implements Action {
39
+
40
+ @Override
41
+ public Result execute(String... args) {
42
+
43
+ int listIndex;
44
+
45
+ if( args.length == 0 ) {
46
+ listIndex = 0;
47
+ } else {
48
+ listIndex = (Integer.parseInt(args[0]) - 1);
49
+ }
50
+
51
+ ArrayList<ListView> listViews = InstrumentationBackend.solo.getCurrentListViews();
52
+
53
+ if( listViews == null || listViews.size() <= listIndex ) {
54
+ return new Result(false, "Could not find list #" + (listIndex + 1));
55
+ }
56
+
57
+ ListView list = listViews.get(listIndex);
58
+ Result result = new Result(true);
59
+
60
+ StringBuilder json = new StringBuilder("[");
61
+
62
+ int count = list.getAdapter().getCount();
63
+ for( int i = 0; i < count; i++ ) {
64
+ json.append("{\"value\": \"");
65
+ json.append(list.getAdapter().getItem(i).toString());
66
+ json.append("\"},");
67
+ }
68
+
69
+ if(count > 0)
70
+ {
71
+ json.deleteCharAt( json.length() - 1 ); // remove the last comma
72
+ }
73
+
74
+ json.append("]");
75
+
76
+ result.addBonusInformation(json.toString());
77
+
78
+ return result;
79
+ }
80
+
81
+ @Override
82
+ public String key() {
83
+ return "get_list_data";
84
+ }
85
+ }
@@ -90,7 +90,6 @@ public class GetListItemProperties implements Action {
90
90
  addViewInfo( json, (ViewGroup)row );
91
91
  }
92
92
 
93
- json.deleteCharAt( json.length() - 1 ); // remove the last comma
94
93
  json.append('}');
95
94
  return json.toString();
96
95
  }
@@ -99,8 +98,8 @@ public class GetListItemProperties implements Action {
99
98
  int resId = view.getId();
100
99
  String resIdName = view.getResources().getResourceEntryName(resId);
101
100
 
102
- json.append("\"id\":\"").append(resIdName).append("\", \"text:\"").append( ((TextView)view).getText() ).append("\"");
103
-
101
+ json.append("\"id\":\"").append(resIdName).append("\", \"text\":\"").append( ((TextView)view).getText() ).append("\"");
102
+
104
103
  json.append(", \"color\":").append( view.getCurrentTextColor() );
105
104
  Drawable background = view.getBackground();
106
105
  if( background instanceof ColorDrawable ) {
@@ -12,13 +12,7 @@ public class EnterQueryByIndex implements Action {
12
12
  final String query = args[0];
13
13
  final SearchView view = (SearchView) InstrumentationBackend.solo.getView(
14
14
  SearchView.class, Integer.parseInt(args[1]) - 1);
15
-
16
- InstrumentationBackend.instrumentation.runOnMainSync(new Runnable() {
17
- @Override
18
- public void run() {
19
- view.setQuery(query, true);
20
- }
21
- });
15
+ view.setQuery(query, true);
22
16
 
23
17
  return Result.successResult();
24
18
  }
@@ -4,6 +4,7 @@ import java.lang.reflect.Field;
4
4
  import java.lang.reflect.Method;
5
5
  import java.util.ArrayList;
6
6
  import java.util.List;
7
+ import java.util.concurrent.atomic.AtomicReference;
7
8
 
8
9
  import sh.calaba.instrumentationbackend.InstrumentationBackend;
9
10
  import android.os.Build;
@@ -52,9 +53,9 @@ public class CalabashChromeClient extends WebChromeClient {
52
53
  }
53
54
  }
54
55
 
55
- public WebView getWebView() {
56
- return webView;
57
- }
56
+ public WebView getWebView() {
57
+ return webView;
58
+ }
58
59
 
59
60
  public String getResult() {
60
61
  eventHandled.block(3000);
@@ -64,7 +65,7 @@ public class CalabashChromeClient extends WebChromeClient {
64
65
  return result.message;
65
66
  }
66
67
 
67
- private class Result {
68
+ private class Result {
68
69
  String message;
69
70
  }
70
71
 
@@ -13,16 +13,10 @@ public class DumpBodyHtml implements Action {
13
13
 
14
14
  final Result result = Result.successResult();
15
15
  for (CalabashChromeClient ccc : CalabashChromeClient.findAndPrepareWebViews()) {
16
- final WebView webView = ccc.getWebView();
17
- InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(new Runnable() {
18
- @Override
19
- public void run() {
20
-
21
- webView.loadUrl("javascript:(function() {" +
22
- "prompt('calabash:' + document.body.innerHTML);" +
23
- "})()");
24
- }
25
- });
16
+ WebView webView = ccc.getWebView();
17
+ webView.loadUrl("javascript:(function() {" +
18
+ "prompt('calabash:' + document.body.innerHTML);" +
19
+ "})()");
26
20
  String r = ccc.getResult();
27
21
  System.out.println("Html:");
28
22
  System.out.println("" + r);
@@ -14,16 +14,9 @@ public class DumpHtml implements Action {
14
14
  Result result = Result.successResult();
15
15
  for (CalabashChromeClient ccc : CalabashChromeClient.findAndPrepareWebViews()) {
16
16
  final WebView webView = ccc.getWebView();
17
-
18
- InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(new Runnable() {
19
- @Override
20
- public void run() {
21
-
22
- webView.loadUrl("javascript:(function() {" +
23
- "prompt('calabash:' + document.body.parentNode.innerHTML);" +
24
- "})()");
25
- }
26
- });
17
+ webView.loadUrl("javascript:(function() {" +
18
+ "prompt('calabash:' + document.body.parentNode.innerHTML);" +
19
+ "})()");
27
20
  String r = ccc.getResult();
28
21
  System.out.println("Html:");
29
22
  System.out.println("" + r);
@@ -16,17 +16,13 @@ public class EnterTextByCssSelector implements Action {
16
16
  final String value = args[1];
17
17
 
18
18
  for (CalabashChromeClient ccc : CalabashChromeClient.findAndPrepareWebViews()) {
19
- final WebView webView = ccc.getWebView();
20
-
21
-
22
- InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(new Runnable() {
23
- @Override
24
- public void run() {
25
- String functions = " function simulateKeyEvent(elem, character) {\n" +
19
+ WebView webView = ccc.getWebView();
20
+
21
+ String functions = " function simulateKeyEvent(elem, character) {\n" +
26
22
  " var ch = character.charCodeAt(0);\n" +
27
23
  "\n" +
28
24
  " var evt;\n" +
29
- "\n" +
25
+ "\n" +
30
26
  " evt = document.createEvent('KeyboardEvent');\n" +
31
27
  " evt.initKeyboardEvent('keydown', true, true, window, 0, 0, 0, 0, 0, ch);\n" +
32
28
  " elem.dispatchEvent(evt);\n" +
@@ -41,8 +37,8 @@ public class EnterTextByCssSelector implements Action {
41
37
  " }\n" +
42
38
  "";
43
39
 
44
- functions +=
45
- " function enterTextIntoInputField(elem, text) {\n" +
40
+ functions +=
41
+ " function enterTextIntoInputField(elem, text) {\n" +
46
42
  " for (var i = 0; i < text.length; i++) {\n" +
47
43
  " var ch = text.charAt(i);\n" +
48
44
  " elem.value += ch;\n" +
@@ -51,35 +47,33 @@ public class EnterTextByCssSelector implements Action {
51
47
  " }\n" +
52
48
  "";
53
49
 
54
- functions +=
55
- " function fireHTMLEvent(elem, eventName) {\n" +
50
+ functions +=
51
+ " function fireHTMLEvent(elem, eventName) {\n" +
56
52
  " var evt = document.createEvent(\"HTMLEvents\");\n" +
57
53
  " evt.initEvent(eventName, true, true );\n" +
58
54
  " return !elem.dispatchEvent(evt);\n" +
59
55
  " }\n" +
60
56
  "";
61
57
 
62
- functions +=
63
- " function selectInputField(elem) {\n" +
58
+ functions +=
59
+ " function selectInputField(elem) {\n" +
64
60
  " elem.click();\n" +
65
61
  " elem.focus();\n" +
66
62
  " }\n" +
67
63
  "";
68
64
 
69
- functions +=
70
- " function deselectInputField(elem) {\n" +
71
- " fireHTMLEvent(elem, 'change');\n" +
72
- " fireHTMLEvent(elem, 'blur');\n" +
73
- " }\n" +
74
- "";
65
+ functions +=
66
+ " function deselectInputField(elem) {\n" +
67
+ " fireHTMLEvent(elem, 'change');\n" +
68
+ " fireHTMLEvent(elem, 'blur');\n" +
69
+ " }\n" +
70
+ "";
75
71
 
76
- webView.loadUrl("javascript:(function() {" +
77
- functions +
78
- "var elem = document.querySelector(\"" + cssSelector + "\"); selectInputField(elem); enterTextIntoInputField(elem, '" + value + "'); deselectInputField(elem); " +
79
- "prompt('calabash:true');" +
80
- "})()");
81
- }
82
- });
72
+ webView.loadUrl("javascript:(function() {" +
73
+ functions +
74
+ "var elem = document.querySelector(\"" + cssSelector + "\"); selectInputField(elem); enterTextIntoInputField(elem, '" + value + "'); deselectInputField(elem); " +
75
+ "prompt('calabash:true');" +
76
+ "})()");
83
77
 
84
78
  String r = ccc.getResult();
85
79
  System.out.println("enterTextIntoInputField: " + r);
@@ -18,7 +18,7 @@ public class ExecuteAsyncJavascript implements Action {
18
18
  }
19
19
 
20
20
  CalabashChromeClient ccc = list.get(0);
21
- final WebView webView = ccc.getWebView();
21
+ WebView webView = ccc.getWebView();
22
22
  final String script = "javascript:(function() {"
23
23
  + " function cb(ret) {"
24
24
  + " prompt('calabash:'+ret);"
@@ -33,14 +33,8 @@ public class ExecuteAsyncJavascript implements Action {
33
33
  + "}())";
34
34
 
35
35
  System.out.println("execute javascript: " + script);
36
-
37
- InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(
38
- new Runnable() {
39
- @Override
40
- public void run() {
41
- webView.loadUrl(script);
42
- }
43
- });
36
+
37
+ webView.loadUrl(script);
44
38
 
45
39
  String r = ccc.getResult();
46
40
  System.out.println("javascript result: " + r);
@@ -18,28 +18,21 @@ public class ExecuteJavascript implements Action {
18
18
  }
19
19
 
20
20
  CalabashChromeClient ccc = list.get(0);
21
- final WebView webView = ccc.getWebView();
22
- final String script = "javascript:(function() {"
23
- + " var r;"
24
- + " try {"
25
- + " r = (function() {"
26
- + args[0] + ";"
27
- + " }());"
28
- + " } catch (e) {"
29
- + " r = 'Exception: ' + e;"
30
- + " }"
31
- + " prompt('calabash:'+r);"
32
- + "}())";
21
+ WebView webView = ccc.getWebView();
22
+ String script = "javascript:(function() {"
23
+ + " var r;"
24
+ + " try {"
25
+ + " r = (function() {"
26
+ + args[0] + ";"
27
+ + " }());"
28
+ + " } catch (e) {"
29
+ + " r = 'Exception: ' + e;"
30
+ + " }"
31
+ + " prompt('calabash:'+r);"
32
+ + "}())";
33
33
 
34
34
  System.out.println("execute javascript: " + script);
35
-
36
- InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(
37
- new Runnable() {
38
- @Override
39
- public void run() {
40
- webView.loadUrl(script);
41
- }
42
- });
35
+ webView.loadUrl(script);
43
36
 
44
37
  String r = ccc.getResult();
45
38
  System.out.println("javascript result: " + r);
@@ -9,9 +9,8 @@ public class GetLoadProgress implements Action {
9
9
  @Override
10
10
  public Result execute(String... args) {
11
11
  CalabashChromeClient ccc = CalabashChromeClient.findAndPrepareWebViews().get(0);
12
- final WebView webView = ccc.getWebView();
13
- int p = webView.getProgress();
14
- return new Result(true, "" + p);
12
+ WebView webView = ccc.getWebView();
13
+ return new Result(true, "" + webView.getProgress());
15
14
  }
16
15
 
17
16
  @Override
@@ -13,24 +13,18 @@ public class PressByCssSelector implements Action {
13
13
  @Override
14
14
  public Result execute(final String... args) {
15
15
  for (CalabashChromeClient ccc : CalabashChromeClient.findAndPrepareWebViews()) {
16
- final WebView webView = ccc.getWebView();
17
- InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(new Runnable() {
18
- @Override
19
- public void run() {
20
-
21
-
22
- webView.loadUrl("javascript:(function() {" +
23
- "var element = document.querySelector(\"" + args[0] + "\");" +
24
- "if (element != null) {" +
25
- " var oEvent = document.createEvent ('MouseEvent');" +
26
- " oEvent.initMouseEvent('click', true, true,window, 1, 1, 1, 1, 1, false, false, false, false, 0, element);" +
27
- " element.dispatchEvent( oEvent );" +
28
- " prompt('calabash:true');" +
29
- "}" +
30
- "prompt('calabash:false');" +
31
- "})()");
32
- }
33
- });
16
+ WebView webView = ccc.getWebView();
17
+
18
+ webView.loadUrl("javascript:(function() {" +
19
+ "var element = document.querySelector(\"" + args[0] + "\");" +
20
+ "if (element != null) {" +
21
+ " var oEvent = document.createEvent ('MouseEvent');" +
22
+ " oEvent.initMouseEvent('click', true, true,window, 1, 1, 1, 1, 1, false, false, false, false, 0, element);" +
23
+ " element.dispatchEvent( oEvent );" +
24
+ " prompt('calabash:true');" +
25
+ "}" +
26
+ "prompt('calabash:false');" +
27
+ "})()");
34
28
 
35
29
  String r = ccc.getResult();
36
30
  System.out.println("clickOnSelector: " + r);
@@ -8,6 +8,7 @@ import java.lang.reflect.Field;
8
8
  import java.util.HashMap;
9
9
  import java.util.List;
10
10
  import java.util.Map;
11
+ import java.util.concurrent.atomic.AtomicReference;
11
12
 
12
13
  import sh.calaba.instrumentationbackend.InstrumentationBackend;
13
14
  import sh.calaba.org.codehaus.jackson.map.ObjectMapper;
@@ -15,10 +16,10 @@ import android.webkit.WebView;
15
16
 
16
17
  public class QueryHelper {
17
18
 
18
- public static String executeJavascriptInWebview(String scriptPath, String... args) {
19
+ public static String executeJavascriptInWebview(String scriptPath, String... args) {
19
20
 
20
21
  String script = readJavascriptFromAsset(scriptPath);
21
-
22
+
22
23
  for (String arg : args) {
23
24
  script = script.replaceFirst("%@", arg);
24
25
  }
@@ -27,14 +28,8 @@ public class QueryHelper {
27
28
  List<CalabashChromeClient> webViews = CalabashChromeClient.findAndPrepareWebViews();
28
29
 
29
30
  for (CalabashChromeClient ccc : webViews) {
30
- final WebView webView = ccc.getWebView();
31
- InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(new Runnable() {
32
- @Override
33
- public void run() {
34
- webView.loadUrl("javascript:calabash_result = " + myScript + ";prompt('calabash:' + calabash_result);");
35
- }
36
- });
37
-
31
+ WebView webView = ccc.getWebView();
32
+ webView.loadUrl("javascript:calabash_result = " + myScript + ";prompt('calabash:' + calabash_result);");
38
33
  return ccc.getResult();
39
34
  }
40
35
  throw new RuntimeException("No webviews found");
@@ -56,8 +51,11 @@ public class QueryHelper {
56
51
  CalabashChromeClient calabashChromeClient = CalabashChromeClient.findAndPrepareWebViews().get(0);
57
52
 
58
53
  WebView webView = calabashChromeClient.getWebView();
59
- float scale = calabashChromeClient.getWebView().getScale();
60
-
54
+
55
+
56
+ float scale = webView.getScale();
57
+
58
+
61
59
  System.out.println("scale: " + scale);
62
60
  int[] webviewLocation = new int[2];
63
61
  webView.getLocationOnScreen(webviewLocation);
@@ -60,7 +60,7 @@ public class ScrollTo implements Action {
60
60
  WebView webView = calabashChromeClient.getWebView();
61
61
  int windowTop = webView.getScrollY();
62
62
  int windowBottom = webView.getScrollY() + webView.getHeight();
63
- int centerY = (int) ((Integer)rectangle.get("center_y") * calabashChromeClient.getWebView().getScale());
63
+ int centerY = (int) ((Integer)rectangle.get("center_y") * webView.getScale());
64
64
 
65
65
  return windowTop < centerY && centerY < windowBottom;
66
66
  }
@@ -17,22 +17,14 @@ public class SetPropertyByCssSelector implements Action {
17
17
  String value = args[2];
18
18
 
19
19
  for (CalabashChromeClient ccc : CalabashChromeClient.findAndPrepareWebViews()) {
20
- final WebView webView = ccc.getWebView();
20
+ WebView webView = ccc.getWebView();
21
21
 
22
22
  final String assignment = "document.querySelector(\"" + cssSelector + "\")." + propertyName + " = " + value + ";";
23
23
  System.out.println(assignment);
24
-
25
- InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(new Runnable() {
26
- @Override
27
- public void run() {
28
-
29
- webView.loadUrl("javascript:(function() {" +
30
- assignment +
31
- "prompt('calabash:true');" +
32
- "})()");
33
-
34
- }
35
- });
24
+ webView.loadUrl("javascript:(function() {" +
25
+ assignment +
26
+ "prompt('calabash:true');" +
27
+ "})()");
36
28
  String r = ccc.getResult();
37
29
  System.out.println("setPropertyByCssSelector: " + r);
38
30
  if ("true".equals(r)) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calabash-android
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3.pre3
4
+ version: 0.3.3.pre5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-26 00:00:00.000000000 Z
12
+ date: 2012-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -106,6 +106,7 @@ files:
106
106
  - Rakefile
107
107
  - bin/calabash-android
108
108
  - bin/calabash-android-build.rb
109
+ - bin/calabash-android-console.rb
109
110
  - bin/calabash-android-generate.rb
110
111
  - bin/calabash-android-helpers.rb
111
112
  - bin/calabash-android-run.rb
@@ -113,14 +114,13 @@ files:
113
114
  - calabash-android.gemspec
114
115
  - doc/calabash-android-help.txt
115
116
  - epl-v10.html
116
- - features-skeleton/.irbrc
117
- - features-skeleton/irb_android.sh
118
117
  - features-skeleton/my_first.feature
119
118
  - features-skeleton/step_definitions/calabash_steps.rb
120
119
  - features-skeleton/support/app_installation_hooks.rb
121
120
  - features-skeleton/support/app_life_cycle_hooks.rb
122
121
  - features-skeleton/support/env.rb
123
122
  - features-skeleton/support/hooks.rb
123
+ - irbrc
124
124
  - lib/calabash-android.rb
125
125
  - lib/calabash-android/calabash_steps.rb
126
126
  - lib/calabash-android/canned_steps.md
@@ -199,6 +199,7 @@ files:
199
199
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/l10n/L10nHelper.java
200
200
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/l10n/PressElement.java
201
201
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/l10n/WaitForElement.java
202
+ - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListData.java
202
203
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemProperties.java
203
204
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemText.java
204
205
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/LongPressListItems.java
@@ -1,22 +0,0 @@
1
- #!/bin/bash
2
- TEST_SERVER_PORT=34777
3
- PACKAGE_NAME=$1
4
- MAIN_ACTIVITY=$2
5
- if [ -z "$PACKAGE_NAME" ]; then
6
- echo 'The parameter about your mobile app package is missing: e.g. com.springsource.greenhouse.test'
7
- exit 1
8
- fi
9
-
10
- if [ -z "$MAIN_ACTIVITY" ]; then
11
- echo 'The parameter about your mobile app main activity is missing: e.g. com.springsource.greenhouse.MainActivity'
12
- exit 1
13
- fi
14
-
15
- # use this line for calabash version 0.1
16
- # adb shell am instrument -e class sh.calaba.instrumentationbackend.InstrumentationBackend -w $PACKAGE_NAME/android.test.InstrumentationTestRunner &
17
- # use this for calabash-version 0.2
18
- # adb shell am instrument -e class sh.calaba.instrumentationbackend.InstrumentationBackend -w $PACKAGE_NAME/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner &
19
- #use this for calabash version 0.3
20
- #adb shell am instrument -e target_package $PACKAGE_NAME -e main_activity $MAIN_ACTIVITY -e class sh.calaba.instrumentationbackend.InstrumentationBackend sh.calaba.android.test/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner
21
- #sleep 7
22
- IRBRC=.irbrc TEST_SERVER_PORT=$TEST_SERVER_PORT PACKAGE_NAME=$PACKAGE_NAME MAIN_ACTIVITY=$MAIN_ACTIVITY irb