Requests library is one of the most popular libraries implemented for Robot Framework. It is very important for testing distributed applications, so this is the first library I got to know in the Robot Framework.

To test Request library we can install Pi-GPIO-Server on Raspberry Pi. Server is able to control state of input and output of GPIOs using REST API.

Project is availiable on link: Project weekend – GPIO Server

In the REST Api we used following methods: – Delete – Get – Options – Post – Put – Patch

To control GPIOs on the RPI we need only Get and Patch methods, other methods are used in the same way – Options is used for exceptions.

I assume you have already installed Robot Framework. If response is “NO”, I would like to invite you to read the Installation paragraph It is official documentation for Robot Framework. Next we can install requests libraries. Collections library is a standard built-in library. Use below commands to install libs:

Now we can prepare RPI image. Install RASPBIAN STRETCH WITH DESKTOP from download link. It is very good solution, because we can control also GPIOs using buttons.

I hope that instruction of installation process is sufficient, so I will not duplicate the description. Take a few minutes to prepare the pin configuration and restart gpio server:

For running server go to Pi-GPIO-Server and type:

Now, we can start writing code for GPIO control using REST API and Robot Framework.

Run RPi and check for its IP address. We will use IP for connection with API server. My RPI has IP: Documentation says that server runs on 5000 port. So we can prepare URL variable. On Variables section type:

Let’s run the first test Get signals. Firstly we should create session for request control in Robot Framework. To create a session we use keyword Create session with parameters alias, URL and optional verify. How to create session

We will use alias for all keywords which work on URL. All sessions should be closed using keyword Delete All Sessions. Next we need a header, which should be sent with request. One of the methods for creating header looks like:

Good trick is assigning headers to variable. To check the value of GPIO, special GET method is prepared. Documentation tells:

Let’s implement it in another way:

As I said, alias is very important because it defines on which session we send requests. For observing results Robot Framework has special keyword. Its name is Log.

Whole test look like this:

To get all signals you can only type hiperlink without pin number. Example:

That was easier part of our script.

To set high or low state for GPIOs you should use patch method. First step is creating dictionary with value to send. It is not difficult:

Patch request requires message data to send.

We can use the same test to set the high state on GPIO. As an indicator I used LED diodes and resistors in series connection.

Full version of my code:

This code is not in perfect form, but it’s not the subject of this article. So polishing is left to the reader. RF generates very readable reports after all tests are done.

Reports look like this:

You can see that Robot Framework is very easy to use environment for testing REST API. All methods (e.g. POST and Patch) are the same in use. If you need help with implementing tests you can ask me or chat with users on Slack –requests channel on robot-framework group. I help new users, whenever I can, and also sometime I’m the one looking for help.