calabash-android 0.3.2.pre2 → 0.3.2.pre3

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,7 +41,7 @@ def calabash_run(app_path = nil)
41
41
  STDOUT.sync = true
42
42
  arguments = ARGV - ["--google-maps-support", "--no-build"]
43
43
  cmd = "cucumber #{arguments.join(" ")} #{env}"
44
- puts cmd
44
+ log cmd
45
45
  exit_code = system(cmd)
46
46
 
47
47
  sleep(1)
@@ -1,2 +1,13 @@
1
1
  #!/bin/bash
2
- IRBRC=.irbrc irb
2
+ TEST_SERVER_PORT=34777
3
+ MOBILE_APP_PACKAGE=$1
4
+ if [ -z "$MOBILE_APP_PACKAGE" ]; then
5
+ echo 'The parameter about your mobile app package is missing: e.g. com.springsource.greenhouse.test'
6
+ exit 1
7
+ else
8
+ # use this line for calabash version 0.1
9
+ # adb shell am instrument -e class sh.calaba.instrumentationbackend.InstrumentationBackend -w $MOBILE_APP_PACKAGE/android.test.InstrumentationTestRunner &
10
+ adb shell am instrument -e class sh.calaba.instrumentationbackend.InstrumentationBackend -w $MOBILE_APP_PACKAGE/sh.calaba.instrumentationbackend.CalabashInstrumentationTestRunner &
11
+ sleep 7
12
+ IRBRC=.irbrc TEST_SERVER_PORT=$TEST_SERVER_PORT irb
13
+ fi
@@ -3,7 +3,7 @@ require 'calabash-android/operations'
3
3
  include Calabash::Android::Operations
4
4
 
5
5
  AfterConfiguration do |config|
6
- wake_up
6
+ wake_up unless config.dry_run?
7
7
  end
8
8
 
9
9
  Before do |scenario|
@@ -220,6 +220,23 @@ To use a set of concrete GPS cordinates
220
220
  Then /^I am at ([-+]?[0-9]*\.?[0-9]+), ([-+]?[0-9]*\.?[0-9]+)$/ do |latitude, longitude|
221
221
  Then /^I go to ([-+]?[0-9]*\.?[0-9]+), ([-+]?[0-9]*\.?[0-9]+)$/ do |latitude, longitude|
222
222
 
223
+ Internationalization
224
+ --------------------
225
+
226
+ Then /^I press text of translated l10key (\d+)$/
227
+ Simulates that the user pressed the text of the l10nkey.
228
+
229
+ Then /^I press button of translated l10key (\d+)$/
230
+ Simulates that the user pressed the button with the label text of the l10nkey.
231
+
232
+ Then /^I press menu item of translated l10key (\d+)$/
233
+ Simulates that the user pressed the menu item with the label text of the l10nkey.
234
+
235
+ Then /^I press toggle button of translated l10key (\d+)$/
236
+ Simulates that the user pressed the toggle button with the label text of the l10nkey.
237
+
238
+ Then /^I wait for the translated "([^\"]*)" l10nkey to appear$/
239
+ Waits until the text of the translated l10nkey is displayed.
223
240
 
224
241
  Rotation
225
242
  --------
@@ -41,4 +41,6 @@ def is_windows?
41
41
  (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
42
42
  end
43
43
 
44
-
44
+ def log(message, error = false)
45
+ $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (error or ARGV.include? "-v" or ARGV.include? "--verbose")
46
+ end
@@ -30,7 +30,7 @@ module Operations
30
30
  end
31
31
  end
32
32
  def default_device
33
- Device.default_device(self)
33
+ Device.default_device
34
34
  end
35
35
 
36
36
  def performAction(action, *arguments)
@@ -59,7 +59,8 @@ module Operations
59
59
  end
60
60
 
61
61
  def screenshot_embed(options={:prefix => nil, :name => nil, :label => nil})
62
- default_device.screenshot_embed(options)
62
+ path = default_device.screenshot(options)
63
+ embed(path, "image/png", options[:label] || File.basename(path))
63
64
  end
64
65
 
65
66
  def screenshot(options={:prefix => nil, :name => nil})
@@ -121,9 +122,9 @@ module Operations
121
122
  class Device
122
123
  @@default_device = nil
123
124
 
124
- def self.default_device(cucumber_world)
125
+ def self.default_device
125
126
  unless @@default_device
126
- @@default_device = Device.new(cucumber_world, ENV["ADB_DEVICE_ARG"], ENV["TEST_SERVER_PORT"], ENV["APP_PATH"], ENV["TEST_APP_PATH"])
127
+ @@default_device = Device.new(ENV["ADB_DEVICE_ARG"], ENV["TEST_SERVER_PORT"], ENV["APP_PATH"], ENV["TEST_APP_PATH"])
127
128
  end
128
129
  @@default_device
129
130
  end
@@ -132,15 +133,15 @@ module Operations
132
133
  @@default_device = self
133
134
  end
134
135
 
135
- def initialize(cucumber_world, serial, server_port, app_path, test_server_path)
136
- @cucumber_world = cucumber_world
136
+ def initialize(serial, server_port, app_path, test_server_path)
137
137
  @serial = serial
138
138
  @server_port = server_port
139
139
  @app_path = app_path
140
140
  @test_server_path = test_server_path
141
141
 
142
- puts "#{adb_command} forward tcp:b#{server_port} tcp:7102"
143
- log `#{adb_command} forward tcp:#{server_port} tcp:7102`
142
+ forward_cmd = "#{adb_command} forward tcp:#{server_port} tcp:7102"
143
+ log forward_cmd
144
+ log `#{forward_cmd}`
144
145
  end
145
146
 
146
147
  def reinstall_apps()
@@ -230,11 +231,6 @@ module Operations
230
231
  end
231
232
  end
232
233
 
233
- def screenshot_embed(options={:prefix => nil, :name => nil, :label => nil})
234
- path = screenshot(options)
235
- @cucumber_world.embed(path, "image/png", options[:label] || File.basename(path))
236
- end
237
-
238
234
  def screenshot(options={:prefix => nil, :name => nil})
239
235
  prefix = options[:prefix] || ENV['SCREENSHOT_PATH'] || ""
240
236
  name = options[:name]
@@ -311,10 +307,6 @@ module Operations
311
307
  http("/kill")
312
308
  end
313
309
 
314
- def log(message)
315
- $stdout.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} - #{message}" if (ARGV.include? "-v" or ARGV.include? "--verbose")
316
- end
317
-
318
310
  ##location
319
311
  def set_gps_coordinates_from_location(location)
320
312
  require 'geocoder'
@@ -0,0 +1,19 @@
1
+ Then /^I press text of translated l10key (\d+)$/ do |l10key|
2
+ performAction('press_l10n_element', l10key)
3
+ end
4
+
5
+ Then /^I press button of translated l10key (\d+)$/ do |l10key|
6
+ performAction('press_l10n_element', l10key,'button')
7
+ end
8
+
9
+ Then /^I press menu item of translated l10key (\d+)$/ do |l10key|
10
+ performAction('press_l10n_element', l10key,'menu_item')
11
+ end
12
+
13
+ Then /^I press toggle button of translated l10key (\d+)$/ do |l10key|
14
+ performAction('press_l10n_element', l10key,'toggle_button')
15
+ end
16
+
17
+ Then /^I wait for the translated "([^\"]*)" l10nkey to appear$/ do |l10nkey|
18
+ performAction('wait_for_l10n_element', l10nkey)
19
+ end
@@ -1,5 +1,5 @@
1
1
  module Calabash
2
2
  module Android
3
- VERSION = "0.3.2.pre2"
3
+ VERSION = "0.3.2.pre3"
4
4
  end
5
5
  end
@@ -0,0 +1,76 @@
1
+ package sh.calaba.instrumentationbackend.actions.helpers;
2
+
3
+
4
+ import sh.calaba.instrumentationbackend.InstrumentationBackend;
5
+ import sh.calaba.instrumentationbackend.Result;
6
+ import sh.calaba.instrumentationbackend.actions.Action;
7
+ import android.view.View;
8
+ import android.widget.Button;
9
+ import android.widget.EditText;
10
+ import android.widget.FrameLayout;
11
+ import android.widget.LinearLayout;
12
+ import android.widget.RelativeLayout;
13
+ import android.widget.ScrollView;
14
+ import android.widget.Spinner;
15
+ import android.widget.TextView;
16
+
17
+ import com.jayway.android.robotium.solo.Solo;
18
+
19
+ /**
20
+ * Command is inspecting the current dialog and returns a list of details about the current
21
+ * displayed UI items.
22
+ *
23
+ * @author Dominik Dary
24
+ *
25
+ */
26
+ public class InspectCurrentDialog implements Action {
27
+
28
+ @Override
29
+ public Result execute(String... args) {
30
+ Solo solo = InstrumentationBackend.solo;
31
+ StringBuffer viewInfo = new StringBuffer();
32
+ viewInfo.append("<views activity='" + solo.getCurrentActivity().getComponentName() + "'>");
33
+ for (View view : solo.getViews()) {
34
+ if ((view instanceof RelativeLayout) || (view instanceof LinearLayout)
35
+ || (view instanceof ScrollView) || (view instanceof FrameLayout)) {
36
+ // for automation are this ui elements normally not so interesting
37
+ continue;
38
+ }
39
+ viewInfo.append("<view>");
40
+ viewInfo.append("<type>" + view.getClass().getSimpleName() + "</type>");
41
+
42
+ try {
43
+ viewInfo.append("<name>"
44
+ + InstrumentationBackend.solo.getCurrentActivity().getResources()
45
+ .getResourceName(view.getId()) + "</name>");
46
+
47
+ } catch (Exception e) {
48
+ // in case the resource name cannot be identified
49
+ viewInfo.append("<name></name>");
50
+ }
51
+
52
+ if (view instanceof TextView) {
53
+ viewInfo.append("<textViewText>" + ((TextView) view).getText() + "</textViewText>");
54
+ } else if (view instanceof Button) {
55
+ viewInfo.append("<buttonText>" + ((Button) view).getText() + "</buttonText>");
56
+ } else if (view instanceof Spinner) {
57
+ viewInfo.append("<spinnerText>" + ((Spinner) view).getSelectedItem() + "</spinnerText>");
58
+ } else if (view instanceof EditText) {
59
+ viewInfo.append("<editText>" + ((EditText) view).getText() + "</editText>");
60
+ }
61
+
62
+ viewInfo.append("</view>");
63
+ }
64
+
65
+ viewInfo.append("</views>");
66
+ Result result = new Result(true);
67
+ result.addBonusInformation(viewInfo.toString());
68
+ return result;
69
+ }
70
+
71
+ @Override
72
+ public String key() {
73
+ return "inspect_current_dialog";
74
+ }
75
+
76
+ }
@@ -0,0 +1,31 @@
1
+ package sh.calaba.instrumentationbackend.actions.l10n;
2
+
3
+ import sh.calaba.instrumentationbackend.InstrumentationBackend;
4
+
5
+ /**
6
+ * Helper to access Android L10n files.
7
+ *
8
+ * @author Dominik Dary
9
+ *
10
+ */
11
+ public class L10nHelper {
12
+ /**
13
+ * get the translated value based on the current active locale.
14
+ *
15
+ * @param l10nKey The l10n key to use
16
+ * @return The translated value.
17
+ */
18
+ public static String getValue(String l10nKey) {
19
+ int resourceId =
20
+ InstrumentationBackend.solo
21
+ .getCurrentActivity()
22
+ .getResources()
23
+ .getIdentifier(l10nKey, "string",
24
+ InstrumentationBackend.solo.getCurrentActivity().getPackageName());
25
+
26
+ String localizedString =
27
+ InstrumentationBackend.solo.getCurrentActivity().getResources().getString(resourceId);
28
+
29
+ return localizedString;
30
+ }
31
+ }
@@ -0,0 +1,48 @@
1
+
2
+ package sh.calaba.instrumentationbackend.actions.l10n;
3
+
4
+ import sh.calaba.instrumentationbackend.InstrumentationBackend;
5
+ import sh.calaba.instrumentationbackend.Result;
6
+ import sh.calaba.instrumentationbackend.actions.Action;
7
+
8
+ /**
9
+ * Action is getting the translated value of the provided #l10nKey and is
10
+ * searching for the text and then clicking on it.
11
+ *
12
+ * @author Dominik Dary
13
+ * @see L10nHelper
14
+ */
15
+ public class PressElement implements Action {
16
+ public static final String BUTTON = "button";
17
+ public static final String TOGGLE_BUTTON = "toggle_button";
18
+ public static final String MENU_ITEM = "menu_item";
19
+
20
+ @Override
21
+ public Result execute(String... args) {
22
+ String l10nKey = args[0];
23
+ String elementType = args.length > 1 ? args[1] : null;
24
+ String myLocalizedString = L10nHelper.getValue(l10nKey);
25
+ InstrumentationBackend.solo.searchText(myLocalizedString);
26
+ if (elementType == null) {
27
+ InstrumentationBackend.solo.clickOnText(myLocalizedString);
28
+ } else if (BUTTON.equalsIgnoreCase(elementType)) {
29
+ InstrumentationBackend.solo.clickOnButton(myLocalizedString);
30
+ } else if (MENU_ITEM.equalsIgnoreCase(elementType)) {
31
+ InstrumentationBackend.solo.clickOnMenuItem(myLocalizedString);
32
+ } else if (TOGGLE_BUTTON.equalsIgnoreCase(elementType)) {
33
+ InstrumentationBackend.solo.clickOnToggleButton(myLocalizedString);
34
+ } else {
35
+ return Result.fromThrowable(new Throwable(
36
+ "specified element type: '" + elementType
37
+ + " ' is not supported."));
38
+ }
39
+
40
+ return Result.successResult();
41
+ }
42
+
43
+ @Override
44
+ public String key() {
45
+ return "press_l10n_element";
46
+ }
47
+
48
+ }
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright 2012 calabash-driver committers.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
+ * in compliance with the License. You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
10
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
+ * or implied. See the License for the specific language governing permissions and limitations under
12
+ * the License.
13
+ */
14
+ package sh.calaba.instrumentationbackend.actions.l10n;
15
+
16
+ import sh.calaba.instrumentationbackend.InstrumentationBackend;
17
+ import sh.calaba.instrumentationbackend.Result;
18
+ import sh.calaba.instrumentationbackend.actions.Action;
19
+
20
+ /**
21
+ * Action is waiting until the text of the given #l10nKey is displayed.
22
+ *
23
+ * @author Dominik Dary
24
+ * @see L10nHelper
25
+ */
26
+ public class WaitForElement implements Action {
27
+
28
+ @Override
29
+ public Result execute(String... args) {
30
+ String l10nKey = args[0];
31
+
32
+ String myLocalizedString = L10nHelper.getValue(l10nKey);
33
+ boolean timedOut = !InstrumentationBackend.solo.waitForText(
34
+ myLocalizedString, 1, 90000);
35
+ if (timedOut) {
36
+ return new Result(false, "Time out while waiting for text:"
37
+ + args[0]);
38
+ } else {
39
+ return Result.successResult();
40
+ }
41
+ }
42
+
43
+ @Override
44
+ public String key() {
45
+ return "wait_for_l10n_element";
46
+ }
47
+ }
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.2.pre2
4
+ version: 0.3.2.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-10-12 00:00:00.000000000 Z
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -140,6 +140,7 @@ files:
140
140
  - lib/calabash-android/steps/context_menu_steps.rb
141
141
  - lib/calabash-android/steps/date_picker_steps.rb
142
142
  - lib/calabash-android/steps/enter_text_steps.rb
143
+ - lib/calabash-android/steps/l10n_steps.rb
143
144
  - lib/calabash-android/steps/list_steps.rb
144
145
  - lib/calabash-android/steps/location_steps.rb
145
146
  - lib/calabash-android/steps/map_steps.rb
@@ -193,7 +194,11 @@ files:
193
194
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/gestures/ClickOnScreen.java
194
195
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/gestures/Drag.java
195
196
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/gestures/Swipe.java
197
+ - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/helpers/InspectCurrentDialog.java
196
198
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/helpers/ListActions.java
199
+ - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/l10n/L10nHelper.java
200
+ - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/l10n/PressElement.java
201
+ - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/l10n/WaitForElement.java
197
202
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemProperties.java
198
203
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemText.java
199
204
  - test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/LongPressListItems.java