Introduction to API’s

You might have Continuous Integration for your deployment where you automate everything. You could add visual testing as one of the steps. In this article we go through basics of using API’s to automate testing.

First of all you will need to start with registering account at https://diffy.website and creating your project. Lets assume you have staging and production environments and every time you do deployment you would like to compare them.

Let’s start using API’s.

Authentication

For authentication you would need to pass login/password of your account to https://diffy.website/api/login_check.

curl -X POST -H “Content-Type: application/x-www-form-urlencoded” -d “_username=urlencodedusername%40gmail.com&_password=yourpassword” https://diffy.website/api/login_check

Then in response you will get token that you will need to use in all your next calls.

{“token”:”eyJhb-LONG-LONG-KEY-3g0"}

Please pay attention that login/password should be URL-encoded. You can do that fast online using service like https://www.url-encode-decode.com/.

Parsing token

I am sure if you are building script in some modern language you can decode received json.

Lets demo how to do it in bash.

curl -X POST -H “Content-Type: application/x-www-form-urlencoded” -d “_username=urlencodedusername%40gmail.com&_password=yourpassword” https://diffy.website/api/login_check | grep -o “token\”:.*\”}” | sed “s/token\”:\”//g” | sed “s/\”}//g”

Additionally we would like to make sure we actually have received the token. So lets it can be a good idea to add a check afterwards.

Compare call

Final step after receiving token is to run compare operation. As we will be comparing production with staging there is shortcut API call to https://diffy.website/api/projects/PROJECTID/compare.

You can find your project’s id in the URL when viewing it.

So here is the final script we can run:

Running Compare operation from bash

If everything is successful you will get response like:

“diff: DIFFID”

Getting results

By default you will receive an email notification when job is done. Meanwhile, if you would like to check the results of the diff you could call https://diffy.website/api/diffs/ID to get information about it.

Documentation

For more information about all our API’s please visit https://diffy.website/rest. It is a Swagger UI so you can try them out right there.

--

--