calabash-android 0.4.22.pre4 → 0.5.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/bin/calabash-android +66 -45
  3. data/lib/calabash-android/calabash_steps.rb +0 -8
  4. data/lib/calabash-android/canned_steps.md +2 -30
  5. data/lib/calabash-android/lib/TestServer.apk +0 -0
  6. data/lib/calabash-android/operations.rb +199 -23
  7. data/lib/calabash-android/removed_actions.txt +52 -0
  8. data/lib/calabash-android/steps/assert_steps.rb +9 -24
  9. data/lib/calabash-android/steps/check_box_steps.rb +2 -2
  10. data/lib/calabash-android/steps/context_menu_steps.rb +11 -4
  11. data/lib/calabash-android/steps/date_picker_steps.rb +2 -2
  12. data/lib/calabash-android/steps/enter_text_steps.rb +13 -13
  13. data/lib/calabash-android/steps/l10n_steps.rb +5 -5
  14. data/lib/calabash-android/steps/map_steps.rb +12 -12
  15. data/lib/calabash-android/steps/navigation_steps.rb +12 -12
  16. data/lib/calabash-android/steps/press_button_steps.rb +16 -12
  17. data/lib/calabash-android/steps/progress_steps.rb +19 -22
  18. data/lib/calabash-android/steps/search_steps.rb +2 -2
  19. data/lib/calabash-android/steps/spinner_steps.rb +10 -2
  20. data/lib/calabash-android/steps/time_picker_steps.rb +2 -2
  21. data/lib/calabash-android/version.rb +1 -1
  22. data/lib/calabash-android/wait_helpers.rb +29 -1
  23. data/test-server/instrumentation-backend/antlr/UIQuery.g +11 -11
  24. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/CalabashInstrumentationTestRunner.java +3 -2
  25. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +9 -4
  26. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Result.java +16 -12
  27. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/application/Backdoor.java +55 -0
  28. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/gestures/LongPressCoordinate.java +19 -2
  29. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/JavaScriptExecuter.java +105 -0
  30. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/QueryHelper.java +27 -30
  31. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ViewMapper.java +27 -18
  32. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/ComparisonOperator.java +7 -1
  33. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTPredicate.java +16 -4
  34. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTWith.java +13 -6
  35. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryUtils.java +94 -48
  36. metadata +5 -59
  37. data/lib/calabash-android/steps/additions_manual_steps.rb +0 -11
  38. data/lib/calabash-android/steps/app_steps.rb +0 -10
  39. data/lib/calabash-android/steps/list_steps.rb +0 -41
  40. data/lib/calabash-android/steps/rotation_steps.rb +0 -7
  41. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressButtonNumber.java +0 -22
  42. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressButtonText.java +0 -27
  43. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressImageButtonDescription.java +0 -39
  44. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressImageButtonNumber.java +0 -22
  45. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/WaitForButton.java +0 -47
  46. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/checkbox/ToggleCheckboxNumber.java +0 -22
  47. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressText.java +0 -22
  48. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressTextAndSelectFromMenuById.java +0 -26
  49. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressTextAndSelectFromMenuByIndex.java +0 -22
  50. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressTextAndSelectFromMenuByText.java +0 -26
  51. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/helpers/InspectCurrentDialog.java +0 -76
  52. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListData.java +0 -85
  53. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemProperties.java +0 -194
  54. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemText.java +0 -136
  55. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/LongPressListItems.java +0 -22
  56. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/PressListItems.java +0 -22
  57. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/scrolling/ScrollDown.java +0 -22
  58. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/scrolling/ScrollUp.java +0 -22
  59. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/search/EnterQueryByIndex.java +0 -29
  60. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/softkey/SelectFromMenuByText.java +0 -24
  61. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/spinner/GetSelectedSpinnerItemText.java +0 -36
  62. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/spinner/SelectSpinnerItemByContentDescription.java +0 -43
  63. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/AssertGridViewContainsNoDuplicates.java +0 -72
  64. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/AssertText.java +0 -31
  65. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/AssertTextOfSpecificTextViewByContentDescription.java +0 -32
  66. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClearTextById.java +0 -30
  67. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClearTextByIndex.java +0 -22
  68. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClearTextFieldByContentDescription.java +0 -33
  69. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClickOnText.java +0 -22
  70. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/EnterTextByContentDescription.java +0 -32
  71. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/EnterTextById.java +0 -33
  72. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/EnterTextByIndex.java +0 -22
  73. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/GetTextById.java +0 -42
  74. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/AssertViewProperty.java +0 -141
  75. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/ClickOnViewByDescription.java +0 -46
  76. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/ClickOnViewById.java +0 -56
  77. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/GetViewProperty.java +0 -101
  78. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/HasView.java +0 -31
  79. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/IsEnabled.java +0 -30
  80. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/LongPressOnViewById.java +0 -34
  81. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/Press.java +0 -89
  82. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/SelectTab.java +0 -110
  83. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/Wait.java +0 -24
  84. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForDialogClose.java +0 -21
  85. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForProgress.java +0 -47
  86. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForScreen.java +0 -54
  87. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForTab.java +0 -108
  88. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForText.java +0 -37
  89. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForView.java +0 -43
  90. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForViewById.java +0 -58
  91. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/JavaScriptOperation.java +0 -44
  92. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/PressByCssSelector.java +0 -70
  93. data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/SetText.java +0 -64
@@ -1,22 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.text;
2
-
3
-
4
- import sh.calaba.instrumentationbackend.InstrumentationBackend;
5
- import sh.calaba.instrumentationbackend.Result;
6
- import sh.calaba.instrumentationbackend.actions.Action;
7
-
8
-
9
- public class ClickOnText implements Action {
10
-
11
- @Override
12
- public Result execute(String... args) {
13
- InstrumentationBackend.solo.clickOnText(args[0]);
14
- return Result.successResult();
15
- }
16
-
17
- @Override
18
- public String key() {
19
- return "click_on_text";
20
- }
21
-
22
- }
@@ -1,32 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.text;
2
-
3
-
4
- import sh.calaba.instrumentationbackend.InstrumentationBackend;
5
- import sh.calaba.instrumentationbackend.Result;
6
- import sh.calaba.instrumentationbackend.TestHelpers;
7
- import sh.calaba.instrumentationbackend.actions.Action;
8
- import android.view.View;
9
- import android.widget.EditText;
10
-
11
-
12
- public class EnterTextByContentDescription implements Action {
13
-
14
- @Override
15
- public Result execute(String... args) {
16
- View view = TestHelpers.getTextViewByDescription(args[1]);
17
- if(view == null) {
18
- return new Result(false, "No view found with content description: '" + args[1] + "'");
19
- } else if (!(view instanceof EditText)) {
20
- return new Result(false, "Expected EditText found: '" + view.getClass() + "'");
21
- } else {
22
- InstrumentationBackend.solo.enterText((EditText)view, args[0]);
23
- return Result.successResult();
24
- }
25
- }
26
-
27
- @Override
28
- public String key() {
29
- return "enter_text_into_named_field";
30
- }
31
-
32
- }
@@ -1,33 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.text;
2
-
3
- import android.view.View;
4
- import android.widget.EditText;
5
- import sh.calaba.instrumentationbackend.InstrumentationBackend;
6
- import sh.calaba.instrumentationbackend.Result;
7
- import sh.calaba.instrumentationbackend.TestHelpers;
8
- import sh.calaba.instrumentationbackend.actions.Action;
9
-
10
- public class EnterTextById implements Action {
11
-
12
- @Override
13
- public Result execute(String... args) {
14
- if(args[1] == null) {
15
- return Result.failedResult("Input text cannot be null");
16
- }
17
- View view = TestHelpers.getViewById(args[1]);
18
- if(view == null) {
19
- return new Result(false, "No view found with id: '" + args[1] + "'");
20
- } else if (!(view instanceof EditText)) {
21
- return new Result(false, "Expected EditText found: '" + view.getClass() + "'");
22
- } else {
23
- InstrumentationBackend.solo.enterText((EditText)view, args[0]);
24
- return Result.successResult();
25
- }
26
- }
27
-
28
- @Override
29
- public String key() {
30
- return "enter_text_into_id_field";
31
- }
32
-
33
- }
@@ -1,22 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.text;
2
-
3
-
4
- import sh.calaba.instrumentationbackend.InstrumentationBackend;
5
- import sh.calaba.instrumentationbackend.Result;
6
- import sh.calaba.instrumentationbackend.actions.Action;
7
-
8
-
9
- public class EnterTextByIndex implements Action {
10
-
11
- @Override
12
- public Result execute(String... args) {
13
- InstrumentationBackend.solo.enterText(Integer.parseInt(args[1]) - 1, args[0]);
14
- return Result.successResult();
15
- }
16
-
17
- @Override
18
- public String key() {
19
- return "enter_text_into_numbered_field";
20
- }
21
-
22
- }
@@ -1,42 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.text;
2
-
3
- import sh.calaba.instrumentationbackend.Result;
4
- import sh.calaba.instrumentationbackend.TestHelpers;
5
- import sh.calaba.instrumentationbackend.actions.Action;
6
- import android.view.View;
7
- import android.widget.TextView;
8
-
9
- public class GetTextById implements Action {
10
-
11
- @Override
12
- public Result execute(String... args) {
13
- String idArgument = args[0];
14
- final View theView = TestHelpers.getViewById(idArgument);
15
-
16
- if (null == theView) {
17
- return notFoundResult(idArgument);
18
- } else if (!(theView instanceof TextView)) {
19
- return foundButNotATextViewResult(idArgument, theView);
20
- }
21
-
22
- return new Result(true, textOf(theView));
23
- }
24
-
25
- @Override
26
- public String key() {
27
- return "get_text_by_id";
28
- }
29
-
30
- private String textOf(final View theView) {
31
- return ((TextView)theView).getText().toString();
32
- }
33
-
34
- private Result foundButNotATextViewResult(String idArgument, final View theView) {
35
- return Result.failedResult(String.format("Found View with id %s but it is a %s not a %s", idArgument, theView.getClass().getName(), TextView.class.getName()));
36
- }
37
-
38
- private Result notFoundResult(String idArgument) {
39
- return Result.failedResult(String.format("View with id %s was not found.", idArgument));
40
- }
41
-
42
- }
@@ -1,141 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.view;
2
-
3
- import java.lang.reflect.InvocationTargetException;
4
- import java.lang.reflect.Method;
5
-
6
- import android.graphics.Bitmap;
7
- import android.graphics.drawable.BitmapDrawable;
8
- import android.graphics.drawable.Drawable;
9
- import android.graphics.drawable.DrawableContainer;
10
- import android.util.Log;
11
- import android.view.View;
12
- import android.widget.TextView;
13
- import sh.calaba.instrumentationbackend.Result;
14
- import sh.calaba.instrumentationbackend.TestHelpers;
15
- import sh.calaba.instrumentationbackend.actions.Action;
16
-
17
-
18
- /**
19
- * eg: performAction( 'assert_view_property', 'my_view', 'visibility', 'visible' ) // or invisible/gone
20
- * eg: performAction( 'assert_view_property', 'my_view', 'drawable', 'expected_id' )
21
- * eg: performAction( 'assert_view_property', 'my_view', 'compoundDrawables', 'left', 'expected_id' )
22
- *
23
- * @author Nicholas Albion
24
- */
25
- public class AssertViewProperty extends GetViewProperty implements Action {
26
- private static final String TAG = "assert_view_property";
27
-
28
- @Override
29
- protected Result getPropertyValue( String propertyName, View view, String[] args ) throws NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
30
- if( "compoundDrawables".equals(propertyName) ) {
31
- if( view instanceof TextView ) {
32
- // performAction( 'get_view_property', 'my_view', 'compoundDrawables', 'left', 'expected_id'
33
- String expected_id = args[3];
34
- int pos;
35
- if( "top".equals(args[2]) ) {
36
- pos = 1;
37
- } else if( "right".equals(args[2]) ) {
38
- pos = 2;
39
- } else if( "bottom".equals(args[2]) ) {
40
- pos = 3;
41
- } else {
42
- pos = 0;
43
- }
44
- Drawable[] drawables = ((TextView)view).getCompoundDrawables(); // [left, top, right, bottom]
45
- Drawable actualDrawable = drawables[pos];
46
- Drawable expectedDrawable = TestHelpers.getDrawableById(expected_id);
47
- return assertSameDrawables( propertyName + ", " + args[2], expectedDrawable, actualDrawable );
48
- } else {
49
- throw new IllegalArgumentException("compoundDrawables is only supported for subclasses of TextView, not " + view.getClass().getName());
50
- }
51
- } else {
52
- return super.getPropertyValue(propertyName, view, args);
53
- }
54
- }
55
-
56
- /**
57
- * @param propertyName
58
- * @param propertyValue
59
- * @param args
60
- * @return successResult if <code>propertyValue</code> is equal to <code>args[2]</code>
61
- * otherwise provides a descriptive message and the expected and actual values in the <code>bonusInformation</code>
62
- */
63
- @Override
64
- protected Result processProperty( String propertyName, Object propertyValue, String[] args ) {
65
- String expected = args[2];
66
- String value;
67
- if( propertyValue == null ) {
68
- if( expected == null || "null".equals(expected) ) {
69
- return Result.successResult();
70
- }
71
- value = "null";
72
- } else if( "drawable".equals(propertyName) ) {
73
- Drawable actualDrawable = (Drawable)propertyValue; // ((ImageButton)view).getDrawable();
74
- if( actualDrawable instanceof DrawableContainer ) {
75
- actualDrawable = ((DrawableContainer)actualDrawable).getCurrent();
76
- }
77
- Drawable expectedDrawable = TestHelpers.getDrawableById(expected);
78
- return assertSameDrawables( propertyName, expectedDrawable, actualDrawable );
79
- } else {
80
- value = propertyValue.toString();
81
- if( value.equals(expected) ) {
82
- return Result.successResult();
83
- }
84
- }
85
- Result result = new Result(false, "For " + propertyName + " expected " + expected + " but was actually " + value);
86
- result.addBonusInformation( expected );
87
- result.addBonusInformation( value );
88
- return result;
89
- }
90
-
91
- private Result assertSameDrawables( String propertyName, Drawable expectedDrawable, Drawable actualDrawable ) {
92
- if( sameDrawables( expectedDrawable, actualDrawable) ) {
93
- return Result.successResult();
94
- } else {
95
- Result result = new Result(false, "For " + propertyName + " expected " + expectedDrawable + " but was actually " + actualDrawable);
96
- result.addBonusInformation( expectedDrawable == null ? "null" : expectedDrawable.toString() );
97
- result.addBonusInformation( actualDrawable == null ? "null" : actualDrawable.toString() );
98
- return result;
99
- }
100
- }
101
-
102
- private boolean sameDrawables( Drawable expected, Drawable actual ) {
103
- if( expected.equals(actual) ) {
104
- return true;
105
- }
106
- if( expected instanceof DrawableContainer ) {
107
- expected = ((DrawableContainer)expected).getCurrent();
108
- }
109
- if( actual instanceof DrawableContainer ) {
110
- actual = ((DrawableContainer)actual).getCurrent();
111
- }
112
- if( (expected instanceof BitmapDrawable) && (actual instanceof BitmapDrawable) ) {
113
- Bitmap expectedBitmap = ((BitmapDrawable)expected).getBitmap();
114
- Bitmap actualBitmap = ((BitmapDrawable)actual).getBitmap();
115
- try {
116
- // As pointed out by kbielenberg, Bitmap.sameAs() was only added in level 12/Android 3.1/Honeycomb MR1
117
- Method sameAs = Bitmap.class.getMethod("sameAs", Bitmap.class);
118
- return (Boolean)sameAs.invoke( expectedBitmap, actualBitmap );
119
- } catch (Exception e) {
120
- if( expectedBitmap.getWidth() != actualBitmap.getWidth() ) { return false; }
121
- if( expectedBitmap.getHeight() != actualBitmap.getHeight() ) { return false; }
122
- if( expectedBitmap.getConfig() != actualBitmap.getConfig() ) { return false; }
123
- boolean bitmapsEqual = expectedBitmap.equals(actualBitmap);
124
- if( !bitmapsEqual ) {
125
- Log.i(TAG, "Bitmaps are not equal");
126
- }
127
- boolean drawablesEqual = expected.equals(actual);
128
- if( !drawablesEqual ) {
129
- Log.i(TAG, "Drawables are not equal");
130
- }
131
- return bitmapsEqual && drawablesEqual;
132
- }
133
- }
134
- return false;
135
- }
136
-
137
- @Override
138
- public String key() {
139
- return "assert_view_property";
140
- }
141
- }
@@ -1,46 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.view;
2
-
3
-
4
- import sh.calaba.instrumentationbackend.InstrumentationBackend;
5
- import sh.calaba.instrumentationbackend.Result;
6
- import sh.calaba.instrumentationbackend.TestHelpers;
7
- import sh.calaba.instrumentationbackend.actions.Action;
8
- import android.view.View;
9
-
10
- /*
11
- * Warning: Unlike most other actions this action will allow you to click on views that are not visible.
12
- */
13
- public class ClickOnViewByDescription implements Action {
14
-
15
- @Override
16
- public Result execute(String... args) {
17
- final View view = TestHelpers.getViewByDescription(args[0]);
18
-
19
- if(view == null) {
20
- return new Result(false, "Could not find view with description: '" + args[0] + "'");
21
- }
22
- try {
23
- System.out.println("Clicking on view: " + view.getClass());
24
- InstrumentationBackend.solo.clickOnView(view);
25
- return Result.successResult();
26
- } catch(junit.framework.AssertionFailedError e) {
27
- System.out.println("solo.clickOnView failed - using fallback");
28
- if (view.isClickable()) {
29
- InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(new Runnable() {
30
- public void run() {
31
- view.performClick();
32
- }
33
- });
34
- }
35
- }
36
- return Result.successResult();
37
- }
38
-
39
- @Override
40
- public String key() {
41
- return "click_on_view_by_description";
42
- }
43
-
44
-
45
-
46
- }
@@ -1,56 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.view;
2
-
3
-
4
- import sh.calaba.instrumentationbackend.InstrumentationBackend;
5
- import sh.calaba.instrumentationbackend.Result;
6
- import sh.calaba.instrumentationbackend.TestHelpers;
7
- import sh.calaba.instrumentationbackend.actions.Action;
8
- import android.view.View;
9
-
10
-
11
- /*
12
- * Warning: Unlike most other actions this action will allow you to click on views that are not visible.
13
- */
14
- public class ClickOnViewById implements Action {
15
-
16
- @Override
17
- public Result execute(String... args) {
18
- final View view = TestHelpers.getViewById(args[0]);
19
-
20
- if(view == null) {
21
- return new Result(false, "Could not find view with id: '" + args[0] + "'");
22
- }
23
- try {
24
- System.out.println("Clicking on view: " + view.getClass());
25
- System.out.println(view.getLeft());
26
- System.out.println(view.getTop());
27
- System.out.println(view.getWidth());
28
- System.out.println(view.getHeight());
29
- int[] xy = new int[2];
30
-
31
- view.getLocationOnScreen(xy);
32
- System.out.println(xy[0]);
33
- System.out.println(xy[1]);
34
-
35
- InstrumentationBackend.solo.clickOnView(view);
36
- } catch(junit.framework.AssertionFailedError e) {
37
- System.out.println("solo.clickOnView failed - using fallback");
38
- if (view.isClickable()) {
39
- InstrumentationBackend.solo.getCurrentActivity().runOnUiThread(new Runnable() {
40
- public void run() {
41
- view.performClick();
42
- }
43
- });
44
- }
45
- }
46
- return Result.successResult();
47
- }
48
-
49
- @Override
50
- public String key() {
51
- return "click_on_view_by_id";
52
- }
53
-
54
-
55
-
56
- }
@@ -1,101 +0,0 @@
1
- package sh.calaba.instrumentationbackend.actions.view;
2
-
3
- import java.lang.reflect.InvocationTargetException;
4
- import java.lang.reflect.Method;
5
-
6
- import sh.calaba.instrumentationbackend.Result;
7
- import sh.calaba.instrumentationbackend.actions.Action;
8
- import sh.calaba.instrumentationbackend.actions.wait.WaitForViewById;
9
- import android.view.View;
10
-
11
- /**
12
- * eg: performAction( 'get_view_property', 'my_view', 'visibility') => visible, invisible or gone
13
- *
14
- * @see AssertViewProperty
15
- * @author Nicholas Albion
16
- */
17
- public class GetViewProperty extends WaitForViewById implements Action {
18
-
19
- @Override
20
- public Result execute(String... args) {
21
- String viewId = args[0];
22
-
23
- try {
24
- View view = getViewById(viewId, 60000);
25
- if( view != null ) {
26
- String propertyName = args[1];
27
- return getPropertyValue(propertyName, view, args);
28
- } else {
29
- return new Result(false, "Timed out while waiting for view with id:'" + viewId + "'");
30
- }
31
- } catch( Exception e ) {
32
- return Result.fromThrowable(e);
33
- }
34
- }
35
-
36
- /**
37
- * @param propertyName
38
- * @param view
39
- * @param args - used by {@link AssertViewProperty#getPropertyValue}
40
- * @return
41
- * @throws NoSuchMethodException
42
- * @throws IllegalArgumentException
43
- * @throws IllegalAccessException
44
- * @throws InvocationTargetException
45
- */
46
- protected Result getPropertyValue( String propertyName, View view, String[] args ) throws NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
47
- if( "visibility".equals(propertyName) ) {
48
- String value;
49
-
50
- switch( view.getVisibility() ) {
51
- case View.VISIBLE:
52
- value = "visible";
53
- break;
54
- case View.INVISIBLE:
55
- value = "invisible";
56
- break;
57
- case View.GONE:
58
- value = "gone";
59
- break;
60
- default:
61
- value = Integer.toString(view.getVisibility());
62
- }
63
-
64
- return new Result( true, value );
65
- } else {
66
- // resort to reflection
67
- Class<? extends View> clazz = view.getClass();
68
- Method method = null;
69
- try {
70
- String methodName = propertyName;
71
- method = clazz.getMethod( methodName );
72
- } catch( NoSuchMethodException e ) {
73
- try {
74
- String methodName = "get" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
75
- method = clazz.getMethod( methodName );
76
- } catch( NoSuchMethodException e2 ) {
77
- String methodName = "is" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
78
- method = clazz.getMethod( methodName );
79
- }
80
- }
81
- Object valueObj = method.invoke(view);
82
- return processProperty( propertyName, valueObj, args );
83
- }
84
- }
85
-
86
- /**
87
- * @param propertyName
88
- * @param propertyValue
89
- * @param args - used by {@link AssertViewProperty#getPropertyValue}
90
- * @return a successful result with the requested property as the <code>message</code> field
91
- */
92
- protected Result processProperty( String propertyName, Object propertyValue, String[] args ) {
93
- String message = (propertyValue == null) ? "null" : propertyValue.toString();
94
- return new Result( true, message );
95
- }
96
-
97
- @Override
98
- public String key() {
99
- return "get_view_property";
100
- }
101
- }