calabash-android 0.2.11 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.txt +6 -0
- data/features-skeleton/support/app_installation_hooks.rb +11 -3
- data/features-skeleton/support/app_life_cycle_hooks.rb +9 -0
- data/features-skeleton/support/hooks.rb +18 -2
- data/lib/calabash-android/operations.rb +1 -1
- data/lib/calabash-android/steps/assert_steps.rb +12 -0
- data/lib/calabash-android/steps/list_steps.rb +40 -0
- data/lib/calabash-android/steps/map_steps.rb +61 -0
- data/lib/calabash-android/steps/navigation_steps.rb +10 -1
- data/lib/calabash-android/steps/progress_steps.rb +5 -0
- data/lib/calabash-android/version.rb +2 -2
- data/test-server/AndroidManifest.xml +5 -5
- data/test-server/build.xml +4 -0
- data/test-server/instrumentation-backend/.gitignore +1 -0
- data/test-server/instrumentation-backend/AndroidManifest.xml +4 -3
- data/test-server/instrumentation-backend/project.properties +1 -1
- data/test-server/instrumentation-backend/src/com/jayway/android/robotium/solo/MapViewUtils.java +328 -0
- data/test-server/instrumentation-backend/src/com/jayway/android/robotium/solo/SoloEnhanced.java +97 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/InstrumentationBackend.java +3 -3
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/TestHelpers.java +51 -1
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemProperties.java +195 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/list/GetListItemText.java +136 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/map/GetMapBounds.java +27 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/map/GetMapCenter.java +27 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/map/GetMapMarker.java +31 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/map/GetMapMarkers.java +48 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/map/GetMapZoom.java +19 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/map/PanMapTo.java +23 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/map/SetMapCenter.java +23 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/map/SetMapZoom.java +34 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/map/TapAwayFromMarkers.java +28 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/map/TapMapMarker.java +29 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/spinner/GetSelectedSpinnerItemText.java +36 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/AssertGridViewContainsNoDuplicates.java +72 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/text/GetTextById.java +42 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/AssertViewProperty.java +141 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/ClickOnViewById.java +1 -8
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/GetActivityName.java +32 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/GetViewProperty.java +107 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/HasView.java +31 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/Press.java +1 -1
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/view/SelectTab.java +110 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForScreen.java +10 -6
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/wait/WaitForTab.java +108 -0
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/{view → wait}/WaitForView.java +1 -1
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/{view → wait}/WaitForViewById.java +21 -11
- data/test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/webview/QueryHelper.java +3 -3
- metadata +102 -88
@@ -0,0 +1,27 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.map;
|
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
|
+
|
9
|
+
/**
|
10
|
+
* A succesful response includes bonusInformation: [top, right, bottom, left] in decimal degrees
|
11
|
+
* @author Nicholas Albion
|
12
|
+
*/
|
13
|
+
public class GetMapBounds implements Action {
|
14
|
+
|
15
|
+
@Override
|
16
|
+
public Result execute(String... args) {
|
17
|
+
List<String> bounds = InstrumentationBackend.solo.getMapBounds();
|
18
|
+
Result result = new Result(true);
|
19
|
+
result.setExtras( bounds );
|
20
|
+
return result;
|
21
|
+
}
|
22
|
+
|
23
|
+
@Override
|
24
|
+
public String key() {
|
25
|
+
return "get_map_bounds";
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.map;
|
2
|
+
|
3
|
+
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
4
|
+
import sh.calaba.instrumentationbackend.Result;
|
5
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Returns latitude, longitude (in decimal degrees) in the "bonusInformation"
|
9
|
+
*
|
10
|
+
* @author Nicholas Albion
|
11
|
+
*/
|
12
|
+
public class GetMapCenter implements Action {
|
13
|
+
|
14
|
+
@Override
|
15
|
+
public Result execute(String... args) {
|
16
|
+
double[] center = InstrumentationBackend.solo.getMapCenter();
|
17
|
+
Result result = new Result(true);
|
18
|
+
result.addBonusInformation( Double.toString(center[0]) );
|
19
|
+
result.addBonusInformation( Double.toString(center[1]) );
|
20
|
+
return result;
|
21
|
+
}
|
22
|
+
|
23
|
+
@Override
|
24
|
+
public String key() {
|
25
|
+
return "get_map_center";
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.map;
|
2
|
+
|
3
|
+
|
4
|
+
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
5
|
+
import sh.calaba.instrumentationbackend.Result;
|
6
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Allows the test script to retreive a specific marker by title
|
10
|
+
*
|
11
|
+
* @author Nicholas Albion
|
12
|
+
*/
|
13
|
+
public class GetMapMarker implements Action {
|
14
|
+
|
15
|
+
@Override
|
16
|
+
public Result execute(String... args) {
|
17
|
+
String title = args[0];
|
18
|
+
String marker = InstrumentationBackend.solo.getMapMarkerItem(title);
|
19
|
+
|
20
|
+
if( marker == null ) {
|
21
|
+
return new Result(false, "Could not find marker " + title);
|
22
|
+
} else {
|
23
|
+
return new Result(true, marker);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
@Override
|
28
|
+
public String key() {
|
29
|
+
return "get_map_marker";
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.map;
|
2
|
+
|
3
|
+
|
4
|
+
import java.util.List;
|
5
|
+
|
6
|
+
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
7
|
+
import sh.calaba.instrumentationbackend.Result;
|
8
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
9
|
+
|
10
|
+
import com.google.android.maps.ItemizedOverlay;
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Allows the test script to retreive a list of markers on {@link ItemizedOverlay}s.
|
14
|
+
* The optional arg can be used to require a specific number of markers
|
15
|
+
*
|
16
|
+
* @author Nicholas Albion
|
17
|
+
*/
|
18
|
+
public class GetMapMarkers implements Action {
|
19
|
+
|
20
|
+
@Override
|
21
|
+
public Result execute(String... args) {
|
22
|
+
List<String> markers = InstrumentationBackend.solo.getMapMarkerItems();
|
23
|
+
|
24
|
+
Result result;
|
25
|
+
if( args.length != 0 ) {
|
26
|
+
int expectedNumberOfStops = Integer.parseInt(args[0]);
|
27
|
+
|
28
|
+
if( expectedNumberOfStops != markers.size() ) {
|
29
|
+
result = new Result(false, "Expected " + expectedNumberOfStops + " markers, but found " + markers.size());
|
30
|
+
} else {
|
31
|
+
result = new Result(true);
|
32
|
+
}
|
33
|
+
} else {
|
34
|
+
result = new Result(true);
|
35
|
+
}
|
36
|
+
|
37
|
+
for (String markerJson : markers) {
|
38
|
+
// Log.i("get_map_markers", markerJson);
|
39
|
+
result.addBonusInformation(markerJson);
|
40
|
+
}
|
41
|
+
return result;
|
42
|
+
}
|
43
|
+
|
44
|
+
@Override
|
45
|
+
public String key() {
|
46
|
+
return "get_map_markers";
|
47
|
+
}
|
48
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.map;
|
2
|
+
|
3
|
+
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
4
|
+
import sh.calaba.instrumentationbackend.Result;
|
5
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
6
|
+
|
7
|
+
public class GetMapZoom implements Action {
|
8
|
+
|
9
|
+
@Override
|
10
|
+
public Result execute(String... args) {
|
11
|
+
int zoomLevel = InstrumentationBackend.solo.getMapZoom();
|
12
|
+
return new Result(true, Integer.toString(zoomLevel));
|
13
|
+
}
|
14
|
+
|
15
|
+
@Override
|
16
|
+
public String key() {
|
17
|
+
return "get_map_zoom";
|
18
|
+
}
|
19
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.map;
|
2
|
+
|
3
|
+
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
4
|
+
import sh.calaba.instrumentationbackend.Result;
|
5
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Center on lat, lon
|
9
|
+
* @author Nicholas Albion
|
10
|
+
*/
|
11
|
+
public class PanMapTo implements Action {
|
12
|
+
|
13
|
+
@Override
|
14
|
+
public Result execute(String... args) {
|
15
|
+
InstrumentationBackend.solo.panMapTo( Double.parseDouble(args[0]), Double.parseDouble(args[1]) );
|
16
|
+
return Result.successResult();
|
17
|
+
}
|
18
|
+
|
19
|
+
@Override
|
20
|
+
public String key() {
|
21
|
+
return "pan_map_to";
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.map;
|
2
|
+
|
3
|
+
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
4
|
+
import sh.calaba.instrumentationbackend.Result;
|
5
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Center on lat, lon
|
9
|
+
* @author Nicholas Albion
|
10
|
+
*/
|
11
|
+
public class SetMapCenter implements Action {
|
12
|
+
|
13
|
+
@Override
|
14
|
+
public Result execute(String... args) {
|
15
|
+
InstrumentationBackend.solo.setMapCenter( Double.parseDouble(args[0]), Double.parseDouble(args[1]) );
|
16
|
+
return Result.successResult();
|
17
|
+
}
|
18
|
+
|
19
|
+
@Override
|
20
|
+
public String key() {
|
21
|
+
return "set_map_center";
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.map;
|
2
|
+
|
3
|
+
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
4
|
+
import sh.calaba.instrumentationbackend.Result;
|
5
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @author Nicholas Albion
|
9
|
+
*/
|
10
|
+
public class SetMapZoom implements Action {
|
11
|
+
|
12
|
+
@Override
|
13
|
+
public Result execute(String... args) {
|
14
|
+
if( "in".equals(args[0]) ) {
|
15
|
+
return new Result( InstrumentationBackend.solo.zoomInOnMap() );
|
16
|
+
} else if( "out".equals(args[0]) ) {
|
17
|
+
return new Result( InstrumentationBackend.solo.zoomOutOnMap() );
|
18
|
+
}
|
19
|
+
|
20
|
+
int zoomLevel = Integer.parseInt(args[0]);
|
21
|
+
int newZoom = InstrumentationBackend.solo.setMapZoom( zoomLevel );
|
22
|
+
|
23
|
+
if( newZoom == zoomLevel ) {
|
24
|
+
return Result.successResult();
|
25
|
+
} else {
|
26
|
+
return new Result(false, "Requested zoom level: " + zoomLevel + " but current zoom level is " + newZoom);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public String key() {
|
32
|
+
return "set_map_zoom";
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.map;
|
2
|
+
|
3
|
+
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
4
|
+
import sh.calaba.instrumentationbackend.Result;
|
5
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* An optional "step" parameter lets the test script specify the number of pixels to increment down/across when
|
9
|
+
* searching for a marker - defaults to 5
|
10
|
+
*
|
11
|
+
* @author Nicholas Albion
|
12
|
+
*/
|
13
|
+
public class TapAwayFromMarkers implements Action {
|
14
|
+
|
15
|
+
@Override
|
16
|
+
public Result execute(String... args) {
|
17
|
+
int step = (args.length == 0) ? 5 : Integer.parseInt(args[0]);
|
18
|
+
if( InstrumentationBackend.solo.tapMapAwayFromMarkers(step) ) {
|
19
|
+
return Result.successResult();
|
20
|
+
}
|
21
|
+
return new Result(false, "Could not find any where to tap away from markers");
|
22
|
+
}
|
23
|
+
|
24
|
+
@Override
|
25
|
+
public String key() {
|
26
|
+
return "tap_map_away_from_markers";
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.map;
|
2
|
+
|
3
|
+
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
4
|
+
import sh.calaba.instrumentationbackend.Result;
|
5
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* eg: tap_map_marker_by_title, "my marker"
|
9
|
+
* eg: tap_map_marker_by_title, "my marker", "10000" (keep trying for 10 seconds)
|
10
|
+
*
|
11
|
+
* @author Nicholas Albion
|
12
|
+
*/
|
13
|
+
public class TapMapMarker implements Action {
|
14
|
+
|
15
|
+
@Override
|
16
|
+
public Result execute(String... args) {
|
17
|
+
String title = args[0];
|
18
|
+
long timeout = (args.length > 1) ? Long.parseLong(args[1]) : 10000;
|
19
|
+
if( InstrumentationBackend.solo.tapMapMarkerItem(title, timeout) ) {
|
20
|
+
return Result.successResult();
|
21
|
+
}
|
22
|
+
return new Result(false, "Could not find marker '" + title + "' to tap after waiting " + timeout + " ms");
|
23
|
+
}
|
24
|
+
|
25
|
+
@Override
|
26
|
+
public String key() {
|
27
|
+
return "tap_map_marker_by_title";
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.spinner;
|
2
|
+
|
3
|
+
import sh.calaba.instrumentationbackend.Result;
|
4
|
+
import sh.calaba.instrumentationbackend.TestHelpers;
|
5
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
6
|
+
import android.widget.Spinner;
|
7
|
+
|
8
|
+
public class GetSelectedSpinnerItemText implements Action {
|
9
|
+
|
10
|
+
@Override
|
11
|
+
public Result execute(String... args) {
|
12
|
+
final String idArgument = args[0];
|
13
|
+
final Spinner foundView = TestHelpers.getViewById(idArgument, Spinner.class);
|
14
|
+
|
15
|
+
if( null == foundView ) {
|
16
|
+
return notFoundResult(idArgument);
|
17
|
+
}
|
18
|
+
|
19
|
+
return new Result(true, getSelectedSpinnerText(foundView));
|
20
|
+
}
|
21
|
+
|
22
|
+
private String getSelectedSpinnerText(final Spinner foundView) {
|
23
|
+
Object selectedItem = foundView.getSelectedItem();
|
24
|
+
return (null != selectedItem) ? selectedItem.toString() : "";
|
25
|
+
}
|
26
|
+
|
27
|
+
private Result notFoundResult(final String idArgument) {
|
28
|
+
return Result.failedResult(String.format("Could not find %s with id %s.", Spinner.class.getName(), idArgument));
|
29
|
+
}
|
30
|
+
|
31
|
+
@Override
|
32
|
+
public String key() {
|
33
|
+
return "get_selected_spinner_item_text";
|
34
|
+
}
|
35
|
+
|
36
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
package sh.calaba.instrumentationbackend.actions.text;
|
2
|
+
|
3
|
+
import java.util.ArrayList;
|
4
|
+
import java.util.LinkedList;
|
5
|
+
|
6
|
+
import android.widget.GridView;
|
7
|
+
import android.widget.TextView;
|
8
|
+
import sh.calaba.instrumentationbackend.InstrumentationBackend;
|
9
|
+
import sh.calaba.instrumentationbackend.Result;
|
10
|
+
import sh.calaba.instrumentationbackend.actions.Action;
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Optional arg is 1-based index - eg: assert_no_duplicates_in_grid, "1" examines the first grid
|
14
|
+
* @author Nicholas Albion
|
15
|
+
*/
|
16
|
+
public class AssertGridViewContainsNoDuplicates implements Action {
|
17
|
+
|
18
|
+
@Override
|
19
|
+
public Result execute(String... args) {
|
20
|
+
ArrayList<GridView> gridViews = InstrumentationBackend.solo.getCurrentGridViews();
|
21
|
+
|
22
|
+
if( gridViews.size() == 0 ) {
|
23
|
+
return new Result(false, "Could not find any grid views");
|
24
|
+
}
|
25
|
+
|
26
|
+
int index;
|
27
|
+
LinkedList<String> duplicates;
|
28
|
+
if( args.length == 1 ) {
|
29
|
+
index = Integer.parseInt(args[0]) - 1;
|
30
|
+
duplicates = assertNoDuplicatesInGrid( gridViews.get(index) );
|
31
|
+
} else {
|
32
|
+
index = gridViews.size() - 1;
|
33
|
+
do {
|
34
|
+
GridView gridView = gridViews.get(index);
|
35
|
+
duplicates = assertNoDuplicatesInGrid(gridView);
|
36
|
+
if( duplicates.size() != 0 ) {
|
37
|
+
break;
|
38
|
+
}
|
39
|
+
} while( index-- != 0 );
|
40
|
+
}
|
41
|
+
|
42
|
+
if( duplicates.size() == 0 ) {
|
43
|
+
return Result.successResult();
|
44
|
+
} else {
|
45
|
+
Result result = new Result(false, "Duplicates were found in GridView #" + (index + 1) + ": " + duplicates);
|
46
|
+
result.setExtras( duplicates );
|
47
|
+
return result;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
private LinkedList<String> assertNoDuplicatesInGrid( GridView gridView ) {
|
52
|
+
//InstrumentationBackend.solo.getViews( gridView );
|
53
|
+
ArrayList<TextView> textViews = InstrumentationBackend.solo.getCurrentTextViews( gridView );
|
54
|
+
LinkedList<String> textValues = new LinkedList<String>();
|
55
|
+
LinkedList<String> duplicates = new LinkedList<String>();
|
56
|
+
|
57
|
+
for (TextView textView : textViews) {
|
58
|
+
String text = textView.getText().toString();
|
59
|
+
if( textValues.contains(text) ) {
|
60
|
+
duplicates.add(text);
|
61
|
+
} else {
|
62
|
+
textValues.add(text);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
return duplicates;
|
66
|
+
}
|
67
|
+
|
68
|
+
@Override
|
69
|
+
public String key() {
|
70
|
+
return "assert_no_duplicates_in_grid";
|
71
|
+
}
|
72
|
+
}
|
@@ -0,0 +1,42 @@
|
|
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
|
+
}
|