Closed nalbion closed 12 years ago
Hi Nicholas,
Great work.
If you want to start using the functionality in Calabash before Renas slips it into Robotium we can add it to the test-server.
Do you have a sample app I can use to verify the implementation?
On Tuesday, July 3, 2012 at 09:32 , nalbion wrote:
I've submitted a MapViewUtils class to robotium: http://code.google.com/p/robotium/issues/detail?id=291
Once released, the following should be supported:
When /^I centre the map at (-?\d+\.\d+), (-?\d+\.\d+)$/ do | lat, lon | performAction('set_map_center', lat, lon) end When /^(?:I )?set the zoom level to (\d+)$/ do | zoom | performAction('set_map_zoom', zoom) end When /^(?:I )?zoom (in|out) on the map$/ do | zoom | performAction('set_map_zoom', zoom) end Then /^I should see the following markers:$/ do | marker_table | verify_markers( marker_table ) end Then /^I should see the following (\d+) markers:$/ do | number_of_markers, marker_table | verify_n_markers( number_of_markers, marker_table ) end
require 'json' def verify_markers( expected_marker_table ) result = performAction('get_map_markers') actual_table = result['bonusInformation'] actual_table.each_with_index do | marker_info, index | # eg: {"latitude":-12.345678, "longitude":123.456789, "title":"Test Marker"} marker_info = JSON.parse( marker_info ) actual_table[index] = marker_info end expected_marker_table.diff!(actual_table) end def verify_n_markers( number_of_markers, expected_marker_table ) result = performAction('get_map_markers', number_of_markers) actual_table = result['bonusInformation'] actual_table.each_with_index do | marker_info, index | marker_info = JSON.parse( marker_info ) actual_table[index] = marker_info end expected_marker_table.diff!(actual_table) end
package sh.calaba.instrumentationbackend.actions.map; import java.util.List; import sh.calaba.instrumentationbackend.InstrumentationBackend; import sh.calaba.instrumentationbackend.Result; import sh.calaba.instrumentationbackend.actions.Action; import com.google.android.maps.ItemizedOverlay; /** * Allows the test script to retreive a list of markers on {@link ItemizedOverlay}s. * The optional arg can be used to require a specific number of markers * * @author Nicholas Albion */ public class GetMapMarkers implements Action { @Override public Result execute(String... args) { List<String> markers = InstrumentationBackend.solo.getMapMarkerItems(); Result result; if( args.length != 0 ) { int expectedNumberOfStops = Integer.parseInt(args[0]); if( expectedNumberOfStops != markers.size() ) { result = new Result(false, "Expected " + expectedNumberOfStops + " markers, but found " + markers.size()); } else { result = Result.successResult(); } } else { result = Result.successResult(); } for (String markerJson : markers) { // Log.i("get_map_markers", markerJson); result.addBonusInformation(markerJson); } return result; } @Override public String key() { return "get_map_markers"; } }
package sh.calaba.instrumentationbackend.actions.map; import sh.calaba.instrumentationbackend.InstrumentationBackend; import sh.calaba.instrumentationbackend.Result; import sh.calaba.instrumentationbackend.actions.Action; /** * Center on lat, lon */ public class SetMapCenter implements Action { @Override public Result execute(String... args) { InstrumentationBackend.solo.setMapCenter( Double.parseDouble(args[0]), Double.parseDouble(args[1]) ); return Result.successResult(); } @Override public String key() { return "set_map_center"; } }
package sh.calaba.instrumentationbackend.actions.map; import sh.calaba.instrumentationbackend.InstrumentationBackend; import sh.calaba.instrumentationbackend.Result; import sh.calaba.instrumentationbackend.actions.Action; public class SetMapZoom implements Action { @Override public Result execute(String... args) { if( "in".equals(args[0]) ) { return new Result( InstrumentationBackend.solo.zoomInOnMap() ); } else if( "out".equals(args[0]) ) { return new Result( InstrumentationBackend.solo.zoomOutOnMap() ); } int zoomLevel = Integer.parseInt(args[0]); int newZoom = InstrumentationBackend.solo.setMapZoom( zoomLevel ); if( newZoom == zoomLevel ) { return Result.successResult(); } else { return new Result(false, "Requested zoom level: " + zoomLevel + " but current zoom level is " + newZoom); } } @Override public String key() { return "set_map_zoom"; } }
Reply to this email directly or view it on GitHub: https://github.com/calabash/calabash-android/issues/59
Hi Jonas,
I've compiled the test server and tested it locally. I'll probably add more to it over the next week or so - like clickOnMarker()
Here's one of my test scripts:
Given my app is running When I centre the map at -12.345678, 123.456789 And set the zoom level to 17 Then I should see the following markers:
| latitude | longitude | title | | -12.345678 | 123.456789 | Test Marker |
From: Jonas Maturana Larsen reply@reply.github.com To: nalbion nalbion@yahoo.com Sent: Tuesday, 3 July 2012 6:48 PM Subject: Re: [calabash-android] Support for MapView (#59)
Hi Nicholas,
Great work.
If you want to start using the functionality in Calabash before Renas slips it into Robotium we can add it to the test-server.
Do you have a sample app I can use to verify the implementation?
On Tuesday, July 3, 2012 at 09:32 , nalbion wrote:
I've submitted a MapViewUtils class to robotium: http://code.google.com/p/robotium/issues/detail?id=291
Once released, the following should be supported:
When /^I centre the map at (-?\d+\.\d+), (-?\d+\.\d+)$/ do | lat, lon | performAction('set_map_center', lat, lon) end When /^(?:I )?set the zoom level to (\d+)$/ do | zoom | performAction('set_map_zoom', zoom) end When /^(?:I )?zoom (in|out) on the map$/ do | zoom | performAction('set_map_zoom', zoom) end Then /^I should see the following markers:$/ do | marker_table | verify_markers( marker_table ) end Then /^I should see the following (\d+) markers:$/ do | number_of_markers, marker_table | verify_n_markers( number_of_markers, marker_table ) end
require 'json' def verify_markers( expected_marker_table ) result = performAction('get_map_markers') actual_table = result['bonusInformation'] actual_table.each_with_index do | marker_info, index | # eg: {"latitude":-12.345678, "longitude":123.456789, "title":"Test Marker"} marker_info = JSON.parse( marker_info ) actual_table[index] = marker_info end expected_marker_table.diff!(actual_table) end def verify_n_markers( number_of_markers, expected_marker_table ) result = performAction('get_map_markers', number_of_markers) actual_table = result['bonusInformation'] actual_table.each_with_index do | marker_info, index | marker_info = JSON.parse( marker_info ) actual_table[index] = marker_info end expected_marker_table.diff!(actual_table) end
package sh.calaba.instrumentationbackend.actions.map; import java.util.List; import sh.calaba.instrumentationbackend.InstrumentationBackend; import sh.calaba.instrumentationbackend.Result; import sh.calaba.instrumentationbackend.actions.Action; import com.google.android.maps.ItemizedOverlay; /** * Allows the test script to retreive a list of markers on {@link ItemizedOverlay}s. * The optional arg can be used to require a specific number of markers * * @author Nicholas Albion */ public class GetMapMarkers implements Action { @Override public Result execute(String... args) { List<String> markers = InstrumentationBackend.solo.getMapMarkerItems(); Result result; if( args.length != 0 ) { int expectedNumberOfStops = Integer.parseInt(args[0]); if( expectedNumberOfStops != markers.size() ) { result = new Result(false, "Expected " + expectedNumberOfStops + " markers, but found " + markers.size()); } else { result = Result.successResult(); } } else { result = Result.successResult(); } for (String markerJson : markers) { // Log.i("get_map_markers", markerJson); result.addBonusInformation(markerJson); } return result; } @Override public String key() { return "get_map_markers"; } }
package sh.calaba.instrumentationbackend.actions.map; import sh.calaba.instrumentationbackend.InstrumentationBackend; import sh.calaba.instrumentationbackend.Result; import sh.calaba.instrumentationbackend.actions.Action; /** * Center on lat, lon */ public class SetMapCenter implements Action { @Override public Result execute(String... args) { InstrumentationBackend.solo.setMapCenter( Double.parseDouble(args[0]), Double.parseDouble(args[1]) ); return Result.successResult(); } @Override public String key() { return "set_map_center"; } }
package sh.calaba.instrumentationbackend.actions.map; import sh.calaba.instrumentationbackend.InstrumentationBackend; import sh.calaba.instrumentationbackend.Result; import sh.calaba.instrumentationbackend.actions.Action; public class SetMapZoom implements Action { @Override public Result execute(String... args) { if( "in".equals(args[0]) ) { return new Result( InstrumentationBackend.solo.zoomInOnMap() ); } else if( "out".equals(args[0]) ) { return new Result( InstrumentationBackend.solo.zoomOutOnMap() ); } int zoomLevel = Integer.parseInt(args[0]); int newZoom = InstrumentationBackend.solo.setMapZoom( zoomLevel ); if( newZoom == zoomLevel ) { return Result.successResult(); } else { return new Result(false, "Requested zoom level: " + zoomLevel + " but current zoom level is " + newZoom); } } @Override public String key() { return "set_map_zoom"; } }
Reply to this email directly or view it on GitHub: https://github.com/calabash/calabash-android/issues/59
Reply to this email directly or view it on GitHub: https://github.com/calabash/calabash-android/issues/59#issuecomment-6729098
Map support was introduced with @nalbion's pull request (gh-90)
I've submitted a MapViewUtils class to robotium: http://code.google.com/p/robotium/issues/detail?id=291
Once released, the following should be supported: