The sample project for the Google Maps defines a number of requests for each of the APIs exposed by Google Maps. The overall structure of the project is as follows:
As you can see the core APIs have been defined as separate REST Services in the project and there is one TestSuite corresponding to each API. The “Master TestSuite” at the end shows how one can have more fine-grained control over the execution of other Tests (see below).
1. Coordinate Assertions
Many of the Assertions in the project are used to validate response content containing coordinates, for example:
As you can see the validation is up to 7 decimals, unfortunately though the last decimals of returned coordinates change rather frequently in which case you will have to either update the “Expected Result” value of the assertion to be in line with the current value, or change the assertion alltogether to either ignore coordinates or handle changes (for example by selecting specific values and truncating them).
Let’s look at each of the APIs and their TestCase(s) in turn.
2. Direction API
The Direction API Rest Service and corresponding TestCase contain requests for basic direction lookups:
The TestCase has the following requests:
- Sample Request : Gets directions from Toronto to Montreal in JSON format and validates the number of steps and bounding coordinates
- Sample Request – no highways: Gets the same directions without highways, validates the number of steps (281!) and bounding coordinates
- Transit with departure time: Looks up a transit from Brooklyn to Queens from the current time and validates the start/end locations and the number of required steps in the XML response.
3. Distance Matrix API
The Distance Matrix API Rest Service and corresponding TestCase contains a sample request for a distance matrix request:
The request retrieves a distance matrix for a number of destination and origin locations and validates the returned destination/origin addresses and the size of the returned matrix.
4. Elevation API
The sample requests for the Elevation API are equally straight forward:
The TestCase performs the following steps:
- Sample Request: specifies coordinates and validates the response to contain the correct elevation
- Sample Request – Multiple Responses: specifies multiple coordinates and validates the response to contain corresponding elevations.
- Path Elevation Sample: specifies a path in coordinates and validates the response to contain the correct elevations.
5. Geocoding API
The GeoCoding API TestCase contains a number of lookup requests:
- Sample Request: validates the geometry coordinates in JSON format of a specified address
- Reverse Lookup Sample: performs a reverse lookup (by specifying coordinates) and verifies the geometry in the result
- Viewport Biasing Sample: performs an address lookup with constraining bounds and validates the returned geometry
- Region Biasing Sample: performs an address lookup with constraining region and validates the returned geometry
- Component Filtering Sample: performs an address lookup with a component filter and validates the returned geometry
- Component Filtering only Sample: performs an lookup with only a component filter and validates the returned geometry
6. Places API
The places API is the only API in this sample that requires an API Key – see below on how that is configured in the project. The Places API Rest Service defines a number of resources with contained GET methods and sample requests. Similarly, the Places API TestSuite contains one TestCase for each of these API resources:
The TestSuite is set up as follows:
- Nearby Search Sample: Performs a nearby search with given coordinates
- Reference Transfer: Transfers the reference of the first hit in the nearby search result to the Details request
- Details: Gets the details of the reference and validates that it has the same coordinates as in the nearbysearch result
- Sample Text Search: performs a text-based query on “restaurants in Sydney”
- Reference Transfer: transfers the reference of the first hit in the search response to the Details request
- Details: gets the details for the first hit in the search response and validates that the lat/lng coordinates are the same in both responses.
- Sample Request: performs an autocomplete search on the string “Amoeba” with type set to “establishment” – validates that the response has 5 entries
- Sample Request in French: performs a similar autocomplete search using the French language – validates that the response has 5 entries
- Sample Request: performs a query-autocomplete search on the string “Pizza near Par” and validates that the response has 5 entries
- Sample Request in French: performs a similar query-autocomplete search using the French language – validates that the response has 5 entries.
7. Places API Authentication
The only API in this project that requires authentication is the Places API; you need to specify an ApiKey that can be obtained via the Google APIs console (https://code.google.com/apis/console). As with similar sample projects, the PlacesApiKey is stored in a project level property and used in corresponding requests via property-expansion:
8. TimeZone API
This is a straightforward API for time zone related queries and conversions. The sample contains just three requests and corresponding TestSteps:
The TestCase is as follows:
- Sample Request: specifies coordinates and validates that the response contains the correct time zone
- Sample Request with DST offset: similar request and response validation with a daylight savings offset
- Sample Request with localized response: same query but now with Spanish locale; validates the entire response.
Download Google Maps Sample Project