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.
- checksums.yaml +4 -4
- data/bin/calabash-android +66 -45
- data/lib/calabash-android/calabash_steps.rb +0 -8
- data/lib/calabash-android/canned_steps.md +2 -30
- data/lib/calabash-android/lib/TestServer.apk +0 -0
- data/lib/calabash-android/operations.rb +199 -23
- data/lib/calabash-android/removed_actions.txt +52 -0
- data/lib/calabash-android/steps/assert_steps.rb +9 -24
- data/lib/calabash-android/steps/check_box_steps.rb +2 -2
- data/lib/calabash-android/steps/context_menu_steps.rb +11 -4
- data/lib/calabash-android/steps/date_picker_steps.rb +2 -2
- data/lib/calabash-android/steps/enter_text_steps.rb +13 -13
- data/lib/calabash-android/steps/l10n_steps.rb +5 -5
- data/lib/calabash-android/steps/map_steps.rb +12 -12
- data/lib/calabash-android/steps/navigation_steps.rb +12 -12
- data/lib/calabash-android/steps/press_button_steps.rb +16 -12
- data/lib/calabash-android/steps/progress_steps.rb +19 -22
- data/lib/calabash-android/steps/search_steps.rb +2 -2
- data/lib/calabash-android/steps/spinner_steps.rb +10 -2
- data/lib/calabash-android/steps/time_picker_steps.rb +2 -2
- data/lib/calabash-android/version.rb +1 -1
- data/lib/calabash-android/wait_helpers.rb +29 -1
- data/test-server/instrumentation-backend/antlr/UIQuery.g +11 -11
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/CalabashInstrumentationTestRunner.java +3 -2
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +9 -4
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/Result.java +16 -12
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/application/Backdoor.java +55 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/gestures/LongPressCoordinate.java +19 -2
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/JavaScriptExecuter.java +105 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/QueryHelper.java +27 -30
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ViewMapper.java +27 -18
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/ComparisonOperator.java +7 -1
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTPredicate.java +16 -4
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryASTWith.java +13 -6
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/query/ast/UIQueryUtils.java +94 -48
- metadata +5 -59
- data/lib/calabash-android/steps/additions_manual_steps.rb +0 -11
- data/lib/calabash-android/steps/app_steps.rb +0 -10
- data/lib/calabash-android/steps/list_steps.rb +0 -41
- data/lib/calabash-android/steps/rotation_steps.rb +0 -7
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressButtonNumber.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressButtonText.java +0 -27
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressImageButtonDescription.java +0 -39
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/PressImageButtonNumber.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/button/WaitForButton.java +0 -47
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/checkbox/ToggleCheckboxNumber.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressText.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressTextAndSelectFromMenuById.java +0 -26
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressTextAndSelectFromMenuByIndex.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/contextmenu/LongPressTextAndSelectFromMenuByText.java +0 -26
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/helpers/InspectCurrentDialog.java +0 -76
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListData.java +0 -85
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemProperties.java +0 -194
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemText.java +0 -136
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/LongPressListItems.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/PressListItems.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/scrolling/ScrollDown.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/scrolling/ScrollUp.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/search/EnterQueryByIndex.java +0 -29
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/softkey/SelectFromMenuByText.java +0 -24
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/spinner/GetSelectedSpinnerItemText.java +0 -36
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/spinner/SelectSpinnerItemByContentDescription.java +0 -43
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/AssertGridViewContainsNoDuplicates.java +0 -72
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/AssertText.java +0 -31
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/AssertTextOfSpecificTextViewByContentDescription.java +0 -32
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClearTextById.java +0 -30
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClearTextByIndex.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClearTextFieldByContentDescription.java +0 -33
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/ClickOnText.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/EnterTextByContentDescription.java +0 -32
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/EnterTextById.java +0 -33
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/EnterTextByIndex.java +0 -22
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/GetTextById.java +0 -42
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/AssertViewProperty.java +0 -141
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/ClickOnViewByDescription.java +0 -46
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/ClickOnViewById.java +0 -56
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/GetViewProperty.java +0 -101
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/HasView.java +0 -31
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/IsEnabled.java +0 -30
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/LongPressOnViewById.java +0 -34
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/Press.java +0 -89
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/SelectTab.java +0 -110
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/Wait.java +0 -24
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForDialogClose.java +0 -21
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForProgress.java +0 -47
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForScreen.java +0 -54
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForTab.java +0 -108
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForText.java +0 -37
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForView.java +0 -43
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForViewById.java +0 -58
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/JavaScriptOperation.java +0 -44
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/PressByCssSelector.java +0 -70
- 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.contextmenu;
|
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 LongPressTextAndSelectFromMenuByIndex implements Action {
|
10
|
-
|
11
|
-
@Override
|
12
|
-
public Result execute(String... args) {
|
13
|
-
InstrumentationBackend.solo.clickLongOnTextAndPress(args[0], Integer.parseInt(args[1]) - 1);
|
14
|
-
return Result.successResult();
|
15
|
-
}
|
16
|
-
|
17
|
-
@Override
|
18
|
-
public String key() {
|
19
|
-
return "press_long_on_text_and_select_with_index";
|
20
|
-
}
|
21
|
-
|
22
|
-
}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
package sh.calaba.instrumentationbackend.actions.contextmenu;
|
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
|
-
|
9
|
-
|
10
|
-
public class LongPressTextAndSelectFromMenuByText implements Action {
|
11
|
-
|
12
|
-
@Override
|
13
|
-
public Result execute(String... args) {
|
14
|
-
|
15
|
-
InstrumentationBackend.solo.clickLongOnText(args[0]);
|
16
|
-
TestHelpers.wait(1);
|
17
|
-
InstrumentationBackend.solo.clickOnText(args[1]);
|
18
|
-
return Result.successResult();
|
19
|
-
}
|
20
|
-
|
21
|
-
@Override
|
22
|
-
public String key() {
|
23
|
-
return "press_long_on_text_and_select_with_text";
|
24
|
-
}
|
25
|
-
|
26
|
-
}
|
@@ -1,76 +0,0 @@
|
|
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
|
-
}
|
@@ -1,85 +0,0 @@
|
|
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.getCurrentViews(ListView.class);
|
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
|
-
}
|
@@ -1,194 +0,0 @@
|
|
1
|
-
package sh.calaba.instrumentationbackend.actions.list;
|
2
|
-
|
3
|
-
import java.lang.reflect.Method;
|
4
|
-
import java.util.ArrayList;
|
5
|
-
|
6
|
-
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
7
|
-
import sh.calaba.instrumentationbackend.Result;
|
8
|
-
import sh.calaba.instrumentationbackend.actions.Action;
|
9
|
-
import android.graphics.drawable.ColorDrawable;
|
10
|
-
import android.graphics.drawable.Drawable;
|
11
|
-
import android.view.View;
|
12
|
-
import android.view.ViewGroup;
|
13
|
-
import android.widget.ListView;
|
14
|
-
import android.widget.TableRow;
|
15
|
-
import android.widget.TextView;
|
16
|
-
|
17
|
-
/**
|
18
|
-
* args:
|
19
|
-
* <ul>
|
20
|
-
* <li>1-based list index (first list is used if not specified)</li>
|
21
|
-
* <li>1-based row index (returns all rows if <=0 or not specified)</li>
|
22
|
-
* </ul>
|
23
|
-
*
|
24
|
-
* eg: (all items of 1st list) <code>performAction( 'get_list_item_properties' )</code>
|
25
|
-
* eg: (all items of 2nd list) <code>performAction( 'get_list_item_properties', '2' )</code>
|
26
|
-
* eg: (1st item of 2nd list) <code>performAction( 'get_list_item_properties', '2' , '1' )</code>
|
27
|
-
*
|
28
|
-
* @return <code>bonusInformation</code> contain an array of Strings, one for each row in the list (or only for the specified row):
|
29
|
-
* eg: {[{"id":"title", "text":"My Title", "compoundDrawables":["left"]}, {"id":"subtitle", "text":"Another text field for the same list item"}]}
|
30
|
-
*
|
31
|
-
*
|
32
|
-
* In ruby, we can then parse the response:
|
33
|
-
* <pre>
|
34
|
-
* response_table = result['bonusInformation']
|
35
|
-
* response_table.each_with_index do | row_data, index |
|
36
|
-
* row_data = JSON.parse( row_data )
|
37
|
-
* response_table[index] = row_data
|
38
|
-
* end
|
39
|
-
* </pre>
|
40
|
-
*
|
41
|
-
* @author Nicholas Albion
|
42
|
-
*/
|
43
|
-
public class GetListItemProperties implements Action {
|
44
|
-
|
45
|
-
@Override
|
46
|
-
public Result execute(String... args) {
|
47
|
-
int listIndex;
|
48
|
-
int rowIndex = -1;
|
49
|
-
|
50
|
-
if( args.length == 0 ) {
|
51
|
-
listIndex = 0;
|
52
|
-
} else {
|
53
|
-
if( args.length > 1 ) {
|
54
|
-
rowIndex = (Integer.parseInt(args[1]) - 1);
|
55
|
-
}
|
56
|
-
listIndex = (Integer.parseInt(args[0]) - 1);
|
57
|
-
}
|
58
|
-
|
59
|
-
|
60
|
-
ArrayList<ListView> listViews = InstrumentationBackend.solo.getCurrentViews(ListView.class);
|
61
|
-
if( listViews == null || listViews.size() <= listIndex ) {
|
62
|
-
return new Result(false, "Could not find list #" + (listIndex + 1));
|
63
|
-
}
|
64
|
-
|
65
|
-
ListView list = listViews.get(listIndex);
|
66
|
-
Result result = new Result(true);
|
67
|
-
|
68
|
-
if( rowIndex < 0 ) {
|
69
|
-
int count = list.getChildCount();
|
70
|
-
for( int i = 0; i < count; i++ ) {
|
71
|
-
result.addBonusInformation( getListItemString( list.getChildAt(i) ) );
|
72
|
-
}
|
73
|
-
} else {
|
74
|
-
result.addBonusInformation( getListItemString( list.getChildAt(rowIndex) ) );
|
75
|
-
}
|
76
|
-
|
77
|
-
return result;
|
78
|
-
}
|
79
|
-
|
80
|
-
/**
|
81
|
-
* @return <code>bonusInformation</code> contain an array of Strings, one for each row in the list (or only for the specified row):
|
82
|
-
* eg: {[{"id":"title", "text":"My Title", "compoundDrawables":{"left":"drawable_id"}}, {"id":"subtitle", "text":"Another text field for the same list item"}]}
|
83
|
-
*/
|
84
|
-
private String getListItemString( View row ) {
|
85
|
-
StringBuilder json = new StringBuilder("{");
|
86
|
-
|
87
|
-
if( row instanceof TextView ) {
|
88
|
-
addViewInfo( json, (TextView)row );
|
89
|
-
} else if( row instanceof ViewGroup ) {
|
90
|
-
addViewInfo( json, (ViewGroup)row );
|
91
|
-
}
|
92
|
-
|
93
|
-
json.append('}');
|
94
|
-
return json.toString();
|
95
|
-
}
|
96
|
-
|
97
|
-
private void addViewInfo( StringBuilder json, TextView view ) {
|
98
|
-
int resId = view.getId();
|
99
|
-
String resIdName = view.getResources().getResourceEntryName(resId);
|
100
|
-
|
101
|
-
json.append("\"id\":\"").append(resIdName).append("\", \"text\":\"").append( ((TextView)view).getText() ).append("\"");
|
102
|
-
|
103
|
-
json.append(", \"color\":").append( view.getCurrentTextColor() );
|
104
|
-
Drawable background = view.getBackground();
|
105
|
-
if( background instanceof ColorDrawable ) {
|
106
|
-
try {
|
107
|
-
// As pointed out by kbielenberg, ColorDrawable.getColor() was only added in level 11/Android 3/Honeycomb
|
108
|
-
Method getColor = ColorDrawable.class.getMethod("getColor");
|
109
|
-
Integer color = (Integer)getColor.invoke(background);
|
110
|
-
json.append(", \"background\":").append( color );
|
111
|
-
} catch (Exception e) {}
|
112
|
-
}
|
113
|
-
|
114
|
-
StringBuilder compoundStr = new StringBuilder();
|
115
|
-
Drawable[] compoundDrawables = view.getCompoundDrawables(); // left, top, right, and bottom
|
116
|
-
if( compoundDrawables[0] != null ) {
|
117
|
-
compoundStr.append("\"left\"");
|
118
|
-
}
|
119
|
-
if( compoundDrawables[1] != null ) {
|
120
|
-
if( compoundStr.length() != 0 ) {
|
121
|
-
compoundStr.append(',');
|
122
|
-
}
|
123
|
-
compoundStr.append("\"top\"");
|
124
|
-
}
|
125
|
-
if( compoundDrawables[2] != null ) {
|
126
|
-
if( compoundStr.length() != 0 ) {
|
127
|
-
compoundStr.append(',');
|
128
|
-
}
|
129
|
-
compoundStr.append("\"right\"");
|
130
|
-
}
|
131
|
-
if( compoundDrawables[3] != null ) {
|
132
|
-
if( compoundStr.length() != 0 ) {
|
133
|
-
compoundStr.append(',');
|
134
|
-
}
|
135
|
-
compoundStr.append("\"bottom\"");
|
136
|
-
}
|
137
|
-
if( compoundStr.length() != 0 ) {
|
138
|
-
json.append(", \"compoundDrawables\":[").append(compoundStr).append(']');
|
139
|
-
}
|
140
|
-
}
|
141
|
-
|
142
|
-
private void addViewInfo( StringBuilder json, TableRow tableRow ) {
|
143
|
-
json.append("\"cells\":[");
|
144
|
-
|
145
|
-
int count = tableRow.getVirtualChildCount();
|
146
|
-
for( int i = 0; i < count; i++ ) {
|
147
|
-
if( i != 0 ) {
|
148
|
-
json.append(", ");
|
149
|
-
}
|
150
|
-
json.append("{\"column\":").append(i).append(", ");
|
151
|
-
|
152
|
-
View view = tableRow.getVirtualChildAt(i);
|
153
|
-
if( view instanceof TextView ) {
|
154
|
-
addViewInfo( json, (TextView)view );
|
155
|
-
} else if( view instanceof ViewGroup ) {
|
156
|
-
addViewInfo( json, (ViewGroup)view );
|
157
|
-
}
|
158
|
-
|
159
|
-
json.append('}');
|
160
|
-
}
|
161
|
-
|
162
|
-
json.append(']');
|
163
|
-
}
|
164
|
-
|
165
|
-
private void addViewInfo( StringBuilder json, ViewGroup viewGroup ) {
|
166
|
-
json.append("\"children\":[");
|
167
|
-
|
168
|
-
int count = viewGroup.getChildCount();
|
169
|
-
for( int i = 0; i < count; i++ ) {
|
170
|
-
if( i != 0 ) {
|
171
|
-
json.append(", ");
|
172
|
-
}
|
173
|
-
json.append('{');
|
174
|
-
|
175
|
-
View view = viewGroup.getChildAt(i);
|
176
|
-
if( view instanceof TextView ) {
|
177
|
-
addViewInfo( json, (TextView)view );
|
178
|
-
} else if( view instanceof TableRow ) {
|
179
|
-
addViewInfo( json, (TableRow)view );
|
180
|
-
} else if( view instanceof ViewGroup ) {
|
181
|
-
addViewInfo( json, (ViewGroup)view );
|
182
|
-
}
|
183
|
-
|
184
|
-
json.append('}');
|
185
|
-
}
|
186
|
-
|
187
|
-
json.append(']');
|
188
|
-
}
|
189
|
-
|
190
|
-
@Override
|
191
|
-
public String key() {
|
192
|
-
return "get_list_item_properties";
|
193
|
-
}
|
194
|
-
}
|
@@ -1,136 +0,0 @@
|
|
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.util.Log;
|
9
|
-
import android.view.View;
|
10
|
-
import android.view.ViewGroup;
|
11
|
-
import android.widget.ListView;
|
12
|
-
import android.widget.TableRow;
|
13
|
-
import android.widget.TextView;
|
14
|
-
|
15
|
-
/**
|
16
|
-
* args:
|
17
|
-
* <ul>
|
18
|
-
* <li>1-based list index (first list is used if not specified)</li>
|
19
|
-
* <li>1-based row index (returns all rows if <=0 or not specified)</li>
|
20
|
-
* </ul>
|
21
|
-
*
|
22
|
-
* eg: (all items of 1st list) <code>performAction( 'get_list_item_text' )</code>
|
23
|
-
* eg: (all items of 2nd list) <code>performAction( 'get_list_item_text', '2' )</code>
|
24
|
-
* eg: (1st item of 2nd list) <code>performAction( 'get_list_item_text', '2' , '1' )</code>
|
25
|
-
*
|
26
|
-
* @return <code>bonusInformation</code> contain an array of Strings, one for each row in the list (or only for the specified row):
|
27
|
-
* eg: {"title":"My Title", "subtitle":"Another text field for the same list item"}
|
28
|
-
*
|
29
|
-
*
|
30
|
-
* In ruby, we can then parse the response:
|
31
|
-
* <pre>
|
32
|
-
* response_table = result['bonusInformation']
|
33
|
-
* response_table.each_with_index do | row_data, index |
|
34
|
-
* row_data = JSON.parse( row_data )
|
35
|
-
* response_table[index] = row_data
|
36
|
-
* end
|
37
|
-
* </pre>
|
38
|
-
*
|
39
|
-
* @author Nicholas Albion
|
40
|
-
*/
|
41
|
-
public class GetListItemText implements Action {
|
42
|
-
|
43
|
-
@Override
|
44
|
-
public Result execute(String... args) {
|
45
|
-
int listIndex;
|
46
|
-
int rowIndex = -1;
|
47
|
-
|
48
|
-
if( args.length == 0 ) {
|
49
|
-
listIndex = 0;
|
50
|
-
} else {
|
51
|
-
if( args.length > 1 ) {
|
52
|
-
rowIndex = (Integer.parseInt(args[1]) - 1);
|
53
|
-
}
|
54
|
-
listIndex = (Integer.parseInt(args[0]) - 1);
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
ArrayList<ListView> listViews = InstrumentationBackend.solo.getCurrentViews(ListView.class);
|
59
|
-
Log.d("GetListItemText", "Found " + listViews.size() + " list views");
|
60
|
-
if( listViews == null || listViews.size() <= listIndex ) {
|
61
|
-
return new Result(false, "Could not find list #" + (listIndex + 1));
|
62
|
-
}
|
63
|
-
|
64
|
-
ListView list = listViews.get(listIndex);
|
65
|
-
Result result = new Result(true);
|
66
|
-
|
67
|
-
if( rowIndex < 0 ) {
|
68
|
-
int count = list.getChildCount();
|
69
|
-
Log.d("GetListItemText", "Found " + count + " list items");
|
70
|
-
for( int i = 0; i < count; i++ ) {
|
71
|
-
result.addBonusInformation( getListItemString( list.getChildAt(i) ) );
|
72
|
-
}
|
73
|
-
} else {
|
74
|
-
result.addBonusInformation( getListItemString( list.getChildAt(rowIndex) ) );
|
75
|
-
}
|
76
|
-
|
77
|
-
return result;
|
78
|
-
}
|
79
|
-
|
80
|
-
/**
|
81
|
-
* @return <code>bonusInformation</code> contain an array of Strings, one for each row in the list (or only for the specified row):
|
82
|
-
* eg: {"title":"My Title", "subtitle":"Another text field for the same list item"}
|
83
|
-
*/
|
84
|
-
private String getListItemString( View row ) {
|
85
|
-
StringBuilder json = new StringBuilder("{");
|
86
|
-
|
87
|
-
if( row instanceof TextView ) {
|
88
|
-
addViewInfo( json, (TextView)row );
|
89
|
-
} else if( row instanceof ViewGroup ) {
|
90
|
-
addViewInfo( json, (ViewGroup)row );
|
91
|
-
}
|
92
|
-
|
93
|
-
json.deleteCharAt( json.length() - 1 ); // remove the last comma
|
94
|
-
json.append('}');
|
95
|
-
return json.toString();
|
96
|
-
}
|
97
|
-
|
98
|
-
private void addViewInfo( StringBuilder json, TextView view ) {
|
99
|
-
int resId = view.getId();
|
100
|
-
String resIdName = view.getResources().getResourceEntryName(resId);
|
101
|
-
|
102
|
-
//json.append("\"id\":\"").append(resIdName).append("\", \"text:\"").append( ((TextView)row).getText() ).append("\"");
|
103
|
-
json.append('"').append(resIdName).append("\":\"").append( ((TextView)view).getText() ).append("\",");
|
104
|
-
}
|
105
|
-
|
106
|
-
private void addViewInfo( StringBuilder json, TableRow tableRow ) {
|
107
|
-
int count = tableRow.getVirtualChildCount();
|
108
|
-
for( int i = 0; i < count; i++ ) {
|
109
|
-
View view = tableRow.getVirtualChildAt(i);
|
110
|
-
if( view instanceof TextView ) {
|
111
|
-
addViewInfo( json, (TextView)view );
|
112
|
-
} else if( view instanceof ViewGroup ) {
|
113
|
-
addViewInfo( json, (ViewGroup)view );
|
114
|
-
}
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
private void addViewInfo( StringBuilder json, ViewGroup viewGroup ) {
|
119
|
-
int count = viewGroup.getChildCount();
|
120
|
-
for( int i = 0; i < count; i++ ) {
|
121
|
-
View view = viewGroup.getChildAt(i);
|
122
|
-
if( view instanceof TextView ) {
|
123
|
-
addViewInfo( json, (TextView)view );
|
124
|
-
} else if( view instanceof TableRow ) {
|
125
|
-
addViewInfo( json, (TableRow)view );
|
126
|
-
} else if( view instanceof ViewGroup ) {
|
127
|
-
addViewInfo( json, (ViewGroup)view );
|
128
|
-
}
|
129
|
-
}
|
130
|
-
}
|
131
|
-
|
132
|
-
@Override
|
133
|
-
public String key() {
|
134
|
-
return "get_list_item_text";
|
135
|
-
}
|
136
|
-
}
|