The technical stuff
There are a bunch of different ways to automate this process, but my favorite is Postman. Postman is a client that allows us to easily make HTTP request to APIs and execute pieces of code before and after each request.
Do you remember when I log all the requests being done during the game play with Google Chrome Developer Tools? It was time to replicate the Yummy Days game requests. For this purpose I created a collection with three requests, called Get Cookies, Fill Form and Play.
The first request, Get Cookies, was a HTTP GET to the URL of the Yummy Dayspage. In Test tab, where you can put a piece of code that will be executed after the request, I set a couple of Postman environment variables with the value of two of the Cookies that come with the response, in a Set-Cookie header, valid for 15 minutes from the request.
In the second request, Fill Form, I wanted to replicate the form submission, that was an HTTP POST to an URL. I created a simple Pre-request Script, a piece of code executed before the request, to set an environment variable with a randomly generated email address.
I also set the JSON body of the POST using this generated email like this:
The first try returned a 500 status code (Internal Server Error), indicating there was something not good with the request. Looking at the logged request in Google Chrome I set the two previously stored Cookies as headers along with any others and the response was a successful 200 status code, great!
Finally, in Play request, I wanted to replicate the behavior of the button that fired the animation to check if you won a prize. That was a simple GET to an URL, using the same headers of the previous request.
I added a test to check if a prize had been won, filtering tries without any prize or duplicated email addresses. If there was a prize in that try, the response to this request would be logged in the Postman Console.
I already had a collection of three request that can be executed in order to play the Yummy Days game with a random email address, so I could execute this requests in an iteration of N executions.
This was time for Postman Collection Runner.
With the Collection Runner, I ran 100 times the game, with no luck, so I tried with a higher number of iterations and I could see the test of one the Playrequest passing, and the following JSON was logged into the console, indicating I had won a prize!
“code”: “******”, //Code has been hidden
“date_to_win”: “2018–06–10 17:36:56”,
“type”: “300”, //300 Yums price
“updated_at”: “2018–06–10 17:36:57”
At this point, I had demonstrated I could automatically win a prize of the Yummy Days promotion, which seems to be time-based and country-based (look at date_to_win and country_id attribute), and seriously affect the results of the promotion (look at updated_at attribute, it is just one second after date_to_win!).