calabash-android 0.3.0.pre2 → 0.3.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/calabash-android CHANGED
@@ -45,11 +45,10 @@ elsif cmd == 'build'
45
45
  elsif cmd == 'run'
46
46
  raise_if_android_home_not_set
47
47
  if ARGV.empty? or not is_apk_file?(ARGV.first)
48
- calabash_run()
48
+ exit calabash_run()
49
49
  else
50
- calabash_run(relative_to_full_path(ARGV.shift))
50
+ exit calabash_run(relative_to_full_path(ARGV.shift))
51
51
  end
52
- exit 0
53
52
  elsif cmd == 'gen'
54
53
  calabash_scaffold
55
54
  exit 0
@@ -9,7 +9,7 @@ def calabash_run(app_path = nil)
9
9
  puts "Please do the following to update your project:"
10
10
  puts "1) Open #{f} in a text editor"
11
11
  puts "2) Replace #{old_runner} with #{new_rummer}"
12
- exit
12
+ exit 1
13
13
  end
14
14
 
15
15
  if app_path
@@ -26,7 +26,6 @@ def calabash_run(app_path = nil)
26
26
  end
27
27
  env = "PACKAGE_NAME=#{package_name(app_path)} "\
28
28
  "MAIN_ACTIVITY=#{main_activity(app_path)} "\
29
- "TEST_PACKAGE_NAME=#{package_name(test_server_path)} "\
30
29
  "APP_PATH=\"#{app_path}\" "\
31
30
  "TEST_APP_PATH=\"#{test_server_path}\" "\
32
31
  "TEST_SERVER_PORT=#{test_server_port}"
@@ -36,11 +35,10 @@ def calabash_run(app_path = nil)
36
35
 
37
36
  STDOUT.sync = true
38
37
  arguments = ARGV - ["--google-maps-support"]
39
- cmd = "cucumber #{arguments.join(" ")} #{env} #{"-c" unless is_windows?}"
38
+ cmd = "cucumber #{arguments.join(" ")} #{env}"
40
39
  puts cmd
41
- IO.popen(cmd) do |io|
42
- io.each { |s| print s }
43
- end
40
+ exit_code = system(cmd)
44
41
 
45
42
  sleep(1)
43
+ exit_code
46
44
  end
@@ -18,5 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency( "cucumber" )
19
19
  s.add_dependency( "json" )
20
20
  s.add_dependency( "retriable" )
21
+ s.add_dependency( "slowhandcuke" )
21
22
 
22
23
  end
@@ -46,7 +46,7 @@ module Operations
46
46
  end
47
47
 
48
48
  def uninstall_apps
49
- default_device.uninstall_app(ENV["TEST_PACKAGE_NAME"])
49
+ default_device.uninstall_app("sh.calaba.android.test")
50
50
  default_device.uninstall_app(ENV["PACKAGE_NAME"])
51
51
  end
52
52
 
@@ -1,5 +1,5 @@
1
1
  module Calabash
2
2
  module Android
3
- VERSION = "0.3.0.pre2"
3
+ VERSION = "0.3.0.pre3"
4
4
  end
5
5
  end
@@ -17,23 +17,22 @@ import android.webkit.WebView;
17
17
  public class CalabashChromeClient extends WebChromeClient {
18
18
  private final ConditionVariable eventHandled = new ConditionVariable();
19
19
  private final Result result = new Result();
20
-
21
-
22
-
23
20
  private WebChromeClient mWebChromeClient;
24
21
  private final WebView webView;
25
22
 
26
23
  public CalabashChromeClient(WebView webView) {
27
24
  this.webView = webView;
28
- try {
29
- Method methodGetConfiguration = webView.getClass().getMethod("getWebChromeClient");
30
- mWebChromeClient = (WebChromeClient)methodGetConfiguration.invoke(webView);
31
- webView.setWebChromeClient(this);
32
- } catch(Exception e) {
33
- throw new RuntimeException(e);
25
+ if (Build.VERSION.SDK_INT < 16) { // jelly bean
26
+ try {
27
+ Method methodGetConfiguration = webView.getClass().getMethod("getWebChromeClient");
28
+ mWebChromeClient = (WebChromeClient)methodGetConfiguration.invoke(webView);
29
+ } catch(Exception e) {
30
+ throw new RuntimeException(e);
31
+ }
34
32
  }
33
+ webView.setWebChromeClient(this);
35
34
  }
36
-
35
+
37
36
  @Override
38
37
  public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult r) {
39
38
  if (message != null && message.startsWith("calabash:")) {
@@ -41,7 +40,7 @@ public class CalabashChromeClient extends WebChromeClient {
41
40
  System.out.println("onJsPrompt: " + message);
42
41
  result.message = message.replaceFirst("calabash:", "");
43
42
  eventHandled.open();
44
-
43
+
45
44
  return true;
46
45
  } else {
47
46
  if (mWebChromeClient == null) {
@@ -52,21 +51,22 @@ public class CalabashChromeClient extends WebChromeClient {
52
51
  }
53
52
  }
54
53
  }
55
-
56
-
57
-
54
+
58
55
  public float getScale() {
56
+ if (Build.VERSION.SDK_INT >= 16) { // jelly bean
57
+ return webView.getScale();
58
+ }
59
59
  try {
60
60
  Field mActualScaleField = null;
61
61
  Object targetObject = webView;
62
-
62
+
63
63
  if (Build.VERSION.SDK_INT < 14) { //before Ice cream sandwich
64
64
  mActualScaleField = WebView.class.getDeclaredField("mActualScale");
65
65
  } else {
66
66
  Field zoomManagerField = WebView.class.getDeclaredField("mZoomManager");
67
67
  zoomManagerField.setAccessible(true);
68
68
  targetObject = zoomManagerField.get(webView);
69
-
69
+
70
70
  mActualScaleField = Class.forName("android.webkit.ZoomManager").getDeclaredField("mActualScale");
71
71
  }
72
72
  mActualScaleField.setAccessible(true);
@@ -75,11 +75,11 @@ public class CalabashChromeClient extends WebChromeClient {
75
75
  throw new RuntimeException(e);
76
76
  }
77
77
  }
78
-
78
+
79
79
  public WebView getWebView() {
80
80
  return webView;
81
81
  }
82
-
82
+
83
83
  public String getResult() {
84
84
  eventHandled.block(30000);
85
85
  if (result.message == null) {
@@ -87,11 +87,11 @@ public class CalabashChromeClient extends WebChromeClient {
87
87
  }
88
88
  return result.message;
89
89
  }
90
-
90
+
91
91
  private class Result {
92
92
  String message;
93
93
  }
94
-
94
+
95
95
  public static List<CalabashChromeClient> findAndPrepareWebViews() {
96
96
  List<CalabashChromeClient> webViews = new ArrayList<CalabashChromeClient>();
97
97
  ArrayList<View> views = InstrumentationBackend.solo.getCurrentViews();
@@ -0,0 +1,61 @@
1
+ package sh.calaba.instrumentationbackend.actions.webview;
2
+
3
+ import java.util.List;
4
+
5
+ import sh.calaba.instrumentationbackend.InstrumentationBackend;
6
+ import sh.calaba.instrumentationbackend.Result;
7
+ import sh.calaba.instrumentationbackend.actions.Action;
8
+ import android.webkit.WebView;
9
+
10
+ public class ExecuteAsyncJavascript implements Action {
11
+
12
+ @Override
13
+ public Result execute(String... args) {
14
+
15
+ List<CalabashChromeClient> list = CalabashChromeClient.findAndPrepareWebViews();
16
+ if (list.isEmpty()) {
17
+ return new Result(false, "No WebView component found");
18
+ }
19
+
20
+ CalabashChromeClient ccc = list.get(0);
21
+ final WebView webView = ccc.getWebView();
22
+ final String script = "javascript:(function() {"
23
+ + " function cb(ret) {"
24
+ + " prompt('calabash:'+ret);"
25
+ + " }"
26
+ + " try {"
27
+ + " (function(returnValue) {"
28
+ + args[0] + ";"
29
+ + " }(cb));"
30
+ + " } catch (e) {"
31
+ + " prompt('calabash:Exception: ' + e);"
32
+ + " }"
33
+ + "}())";
34
+
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
+ });
44
+
45
+ String r = ccc.getResult();
46
+ System.out.println("javascript result: " + r);
47
+
48
+ boolean success = true;
49
+ if (r.startsWith("Exception:")) {
50
+ success = false;
51
+ }
52
+
53
+ return new Result(success, r);
54
+ }
55
+
56
+ @Override
57
+ public String key() {
58
+ return "execute_async_javascript";
59
+ }
60
+
61
+ }
@@ -1,5 +1,7 @@
1
1
  package sh.calaba.instrumentationbackend.actions.webview;
2
2
 
3
+ import java.util.List;
4
+
3
5
  import sh.calaba.instrumentationbackend.InstrumentationBackend;
4
6
  import sh.calaba.instrumentationbackend.Result;
5
7
  import sh.calaba.instrumentationbackend.actions.Action;
@@ -10,7 +12,12 @@ public class ExecuteJavascript implements Action {
10
12
  @Override
11
13
  public Result execute(String... args) {
12
14
 
13
- CalabashChromeClient ccc = CalabashChromeClient.findAndPrepareWebViews().get(0);
15
+ List<CalabashChromeClient> list = CalabashChromeClient.findAndPrepareWebViews();
16
+ if (list.isEmpty()) {
17
+ return new Result(false, "No WebView component found");
18
+ }
19
+
20
+ CalabashChromeClient ccc = list.get(0);
14
21
  final WebView webView = ccc.getWebView();
15
22
  final String script = "javascript:(function() {"
16
23
  + " var 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.0.pre2
4
+ version: 0.3.0.pre3
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-09-21 00:00:00.000000000 Z
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: slowhandcuke
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  description: ! 'calabash-android drives tests for native and hybrid Android apps. '
63
79
  email:
64
80
  - jonas@lesspainful.com
@@ -234,6 +250,7 @@ files:
234
250
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/DumpBodyHtml.java
235
251
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/DumpHtml.java
236
252
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/EnterTextByCssSelector.java
253
+ - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteAsyncJavascript.java
237
254
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/ExecuteJavascript.java
238
255
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/GetLoadProgress.java
239
256
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/GetUrl.java