Test Harness
The Test Harness allows you to send API requests into the GameSparks platform in their raw form to see the responses that the server returns for any given request:
- Mimics Connected Devices. Because the browser uses WebSockets for communication, the Test Harness can mimic a connected device by receiving asynchronous messages when they are generated by the platform.
- Invaluable Test Tool. The Test Harness is an invaluable tool for testing your game configuration. We recommend that you always try out any game configuration changes that you make in the Test Harness before writing the game client code that uses it.
The Test Harness comes with two key tools for refining and developing your Cloud Code:
- Debugger - You can use the Debugger to thoroughly debug your Cloud Code.
- Profiler - You can use the Profiler to inspect performance metrics for your Cloud Code, which will help you to identify and address any performance issues.
FAQs? You can review Frequently Asked Questions about the Test Harness.
Getting to Know the Test Harness
You can open the Test Harness directly from the main left-hand navigation menu in the Portal:
There are several sections in the Test Harness page:
- Connection
- Shows details of the current connection - you can hover your cursor on these fields and click to Copy:
- Service URL
- Auth Token (authentication token)
- Player ID
- Credential - Use the drop-down menu to select the Credential you want to use when connecting. In the above example, the Test Harness is connected using the debug system Credential.
- Connect/Disconnect - Use the Connect/Disconnect button to connect and disconnect:
- Your connection status is shown:
or
- Your connection status is shown:
- Shows details of the current connection - you can hover your cursor on these fields and click to Copy:
- Debug
- Debug Options - Use the checkboxes to select which Cloud Code you want to debug in the current session - the Cloud Code attached to Requests, Responses, or Messages.
- You can also enable/disable Break On Error.
- For details of how to work with the Debugger, click here to go to the GameSparks Debugger page.
- Profile - Use this checkbox to enable Cloud Code Profiling. When you enable for Cloud Code Profiling, Debug is disabled.
- For details of how to work with the Cloud Code Profiler, click here to go to the Profile page
- Requests
- Lists all the available GameSparks API requests grouped according to functional area. Each submenu item allows you to quickly select a request and then populate the JSON entry field with a correctly formatted request.
- JSON - enter your JSON request text here. You can click:
- Inspector
- Keep track of the requests, responses, and asynchronous messages in your Test Harness session:
- Requests sent - Shown in green.
- Responses received - Shown in blue.
- Asynchronous messages received - Shown in yellow.
- To clear out the Inspector at any time, click the clear
icon.
- Keep track of the requests, responses, and asynchronous messages in your Test Harness session:
Stage
You can use the switch at the top of the page to use the Test Harness for the Preview or Live stage of your game:
- Preview:
- Live:
Seeing Debugger! The Debugger is not always in view. If you have selected an Event which has Cloud Code attached to it, the Debugger will automatically appear but only when you run the Event and only if you haven't enabled for Cloud Code Profiling.
Starting a Test Harness Session
When you first access the Test Harness page within the Developer Portal, it will establish a session with the GameSparks platform. At this point the Test Harness is connected to GameSparks but no player is currently authenticated within this session. The initial connection handshaking methods are shown in the Inspector section.
When you have issued one of the available authentication requests (for example, AuthenticationRequest, DeviceAuthenticationRequest, and so on) with valid player details, you will see an Auth Token (authentication token) in the Connection section.
Issuing a Request
To issue a request from the Test Harness, simply enter the JSON for the request into the JSON section and click Send Request:
The Inspector will show the request (in green), and the response (in blue).
Re-Issuing a Request
To re-issue a request, click the rotated arrow in the Inspector window. The request JSON is copied into the JSON section so that you can re-send the request:
Working with Requests
The Requests section contains a selection of buttons which will populate the JSON section with the correctly formatted text for a given request. The requests are grouped by functional area. Click on a functional area to display a submenu of buttons for each request it contains:
- Authentication - Requests relating to authentication and registration.
- Admin - Requests relating to administration jobs.
- Analytics - Requests relating to Analytics.
- Leaderboards - Requests relating to Leaderboards.
- Misc - Requests that don't belong anywhere else!
- Multiplayer - Requests relating to multiplayer contexts.
- Player - Requests relating to the Player.
- Store - Requests relating to 3rd-party app stores such as Google play.
- Teams - Requests relating to Teams.
- Log Event - Contains a LogEventRequest for each of the Events that you have defined in the Configurator.
- Log Challenge Event - Contains a LogChallengeEventRequest for each of the Events that you have defined in the Configurator.
- Upload - Requests relating to uploading.
- Scenarios - Requests that you have saved for later use.
Debugger! If you are using LogEventRequest with Cloud Code scripts, then at execution the Debugger may appear.
Example Requests
Example 1
1. Click the Player functional area to display the player-related requests.
2. Click ChangeUserDetailsRequest button and populate the JSON section with the specific request details:
Make any changes to the request that you require, such as removing optional fields or changing the default data values and then click to Send Request.
Example 2
You can also issue several requests at once simply by creating a JSON array of requests in the JSON section. For example, to authenticate a player and then query their details include the two requests in a JSON array such as this.
Note: You'll need outer square brackets and comma separator between each request to build a well-formed JSON array.
Saving Requests as a Scenario
1. To save an individual request as a scenario, first click on the icon in the JSON section.
2. Give your scenario a meaningful name and click the Save button.
The scenario is saved to Scenarios area of the Requests section and can be recalled to the JSON section in the future:
Scenario Limit! A limit of 4000 characters is imposed on the JSON you save under a Scenario.
Recording Multi-Request Scenarios
You can also record a sequence of requests with the Test Harness and then save this multi-request sequence as a scenario.
1. Enter the first request in the JSON section.
2. Click the microphone icon, which will switch to be highlighted to indicate that the Test Harness is now recording subsequent requests.
3. Click to Send Request as normal.
4. Select the next request, in the JSON section enter the request details, and then Send Request:
Record Mode. The microphone
icon remains highlighted to show that record-scenario mode is enabled.
5. Repeat these steps for each of the requests you want to include in your scenario.
6. When you've entered and sent all the requests you want in your multi-request scenario, click the highlighted microphone icon a second time to stop recording. The JSON section will be populated with an array of all the requests that you sent whilst recording.
This multi-request scenario can now be saved as described in the previous section.
Scenario Limit! A limit of 4000 characters is imposed on the JSON you save under a Scenario.