Sign In Register

How can we help you today?

Start a new topic

parameterized multi-request scenarios in test harness

It would be nice to use values from a request response as parameters for subsequent requests in a multi-request scenario.

For example:

 

a "static" multi-request scenario

[

 {

  "@class": ".AuthenticationRequest",

  "password": "blahblah",

  "userName": "jchaplin@somewhere.com"

 },

 {

  "@class": ".LogEventRequest",

  "eventKey": "getLives",

 },

 {

  "@class": ".LogEventRequest",

  "eventKey": "updateAccount",

  "name": "James Chaplin",

  "lives": "13",

 }

]

The first request return this response

{

 "@class": ".AuthenticationResponse",

 "authToken": "111111-22222-33333-4444",

 "displayName": "James Chaplin",

 "newPlayer": false,

 "userId": "123213aasdasd123123"

}

The second request return this response

{

 "@class": ".LogEventResponse",

 "scriptData": {

  "result": {

   "lives": 17

  }

 }

}

a "parameterized" multi-request scenario, would look like that

[

 {

  "@class": ".AuthenticationRequest",

  "password": "blahblah",

  "userName": "jchaplin@somewhere.com"

 },

 {

  "@class": ".LogEventRequest",

  "eventKey": "getLives",

 },

 {

  "@class": ".LogEventRequest",

  "eventKey": "updateAccount",

  "name": "@response[0].displayName",

  "lives": "@response[1].scriptData.result.lives",

 }

]


Hi Christian, 


Currently it's not possible to do this with scenarios. You could however set up a test script and use SparkRequests to send a series of requests and use the responses from them to populate the the next SparkRequest. Basic example below.

 

//send our first request
var request = new SparkRequests.AccountDetailsRequest();
var response = request.Send();

//get the country from the response
var playerCountry = response.location.country

//send our second request using data from the first
var request2 = new SparkRequests.LogEventRequest();
request2.eventKey = "postScore";
request2.score = 50;
request2.country = playerCountry //use our retrieved country from the first request in the second request, in this example the country is used to partition a leaderboard
var response2 = request2.Send

Spark.setScriptData("Response", response2)

  

You could also use request.SendAs(playerId) to send the request as a given player, or you could use request.ExecuteAs(playerId), this will execute any Cloud Code attached to the request as the given player. Try that out and let me know if it suits your needs.


Thanks,

Liam

HI Liam,


Thanks for your response and yes I knew that I could dot it in a script but my request was for just to have a quick and convenient way to build a more advance scenarios.  But I understand that it's not a a high priority request ;).


Thanks again,

Christian

Login to post a comment