1

I am currently carrying out test automation using a Selenium based Automation framework. I am currently sending in HTTP requests in order to create an API suite.

However the next URL I need to post in is part of a text/event-stream. The data I require to extract is within the eventStream itself.

a["{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"VirgoSessionToken\":\"8C7A0FAA-EA27-473A-BCC3-E568ABDBD403\",\"Localization\":{\"LocaleString\":\"en_UK\",\"LanguageTag\":\"en-UK\",\"DecimalSeparator\":\".\",\"ZeroDigit\":\"0\",\"ThousandsSeparator\":\",\",\"CurrencySymbolLocation\":\"PREFIX\"},\"Balance\":{\"Timestamp\":1493730819967,\"Banks\":{\"CREDIT\":{\"Amount\":83872,\"CurrencyCode\":\"GBP\",\"MinorCurrencyUnits\":2,\"CurrencySymbol\":\"GBP\"},\"WINNINGS\":{\"Amount\":0,\"CurrencyCode\":\"GBP\",\"MinorCurrencyUnits\":2,\"CurrencySymbol\":\"GBP\"}}},\"Preferences\":{\"Global\":{},\"Game\":{}},\"State\":{\"value\":\"{\\\"serverState\\\":{\\\"player\\\":{\\\"uniqueVirgoId\\\":\\\"f85551d0-2f36-11e7-9136-314c3f96f318\\\",\\\"playerBindingState\\\":{\\\"20\\\":0,\\\"40\\\":0,\\\"60\\\":0,\\\"80\\\":0,\\\"100\\\":0,\\\"200\\\":0,\\\"400\\\":0,\\\"600\\\":0,\\\"800\\\":0,\\\"1000\\\":0,\\\"2000\\\":0,\\\"4000\\\":0,\\\"6000\\\":0,\\\"8000\\\":0,\\\"10000\\\":0},\\\"populated\\\":true},\\\"game\\\":{\\\"currencyCode\\\":\\\"\\\"}},\\\"jackpotState\\\":{}}\"},\"ApiPhase\":\"Idle\"}}"]   

I need to extract the Amount value using Java. Apologies if the code formatting isn't great.

Is there a best way to extract Data from EventStreams?

As an example of what my framework does:

String webSocketUrl = insHostedUrl + responseTitle + "/xc_yx4r_" + "/eventsource";
assertTrue(httpCreateRequest("post", webSocketUrl);
assertTrue(httpSendRequest());
response = httpGetResponse();

This posts in the URL that is visible in the requests. However this does not get me to the eventStream data.

mvoase
  • 544
  • 1
  • 6
  • 20
  • Where is the code? – freedev May 02 '17 at 15:34
  • The actual data code is listed in the question. The code itself for the project isn't posted as its an internal Automation framework. I was just posting to see if there was any generic Java methods that would be able to extract this, as the framework doesn't go that far. – mvoase May 02 '17 at 15:36
  • What I see is just a big Json string (with a nested Json string inside). – freedev May 02 '17 at 15:39
  • This is the data from the eventStream of the HTTP request. I have added some of the code which is used to send in a request. – mvoase May 02 '17 at 15:41
  • Did you manage to solve this issue? – Guillermo Nov 20 '17 at 18:20
  • Turns out, because this is on the server side its not possible to access. – mvoase Nov 21 '17 at 11:14

1 Answers1

0

You can probably use the google json library and run some code like this.

JsonObject jsonObject = new 
JsonParser().parse({\"Amount\":0}").getAsJsonObject();
System.out.println(jsonObject.get("Amount").getAsString());

Here is another article with more information How to parse JSON in Java

Community
  • 1
  • 1
quinny1187
  • 66
  • 2
  • Thanks for the response.. its the actual getting to the Data itself thats the issue. Thanks for adding this as it will help once I get there, however the JSON isn't given in the response body of the request itself. Only in the eventStream which is Server side. – mvoase May 02 '17 at 15:44