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. The server is able to control the state of input and output of GPIOs using REST API. The project is available on the 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 the response is “NO”, I would encourage 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. apt-get install python-pip pip install -U requests pip install -U robotframework-requests Now we can prepare RPI image. Install

RASPBIAN STRETCH WITH DESKTOP from download link. It is a 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: sudo service gpio-server restart For running server go to Pi-GPIO-Server and type:

5000 port. So we can prepare URL variable. On Variables section type: ${URL} http://192.168.0.46:5000 Let’s run the first test

Get signals. Firstly we should create a session for request control in Robot Framework. To create the session we use the keyword Create session with parameters alias, URL and optional verify. How to create session *** Test Cases ***

alias for all keywords which work on URL. All sessions should be closed using the keyword Delete All Sessions. Next, we need a header, which should be sent with the request. One of the methods for creating header looks like: Create Dictionary Content-Type=application/json Accept=application/json A good trick is assigning headers to the variable. To check the value of GPIO, special GET method is prepared.

Documentation tells: Read a single pin

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: *** Settings *** Library RequestsLibrary Library Collections

patch method. The first step is creating a dictionary with value to send. It is not difficult: ${message}= Create Dictionary value 0

Patch request requires message data to send. Set 0 signals Create Session gpio_server ${URL} verify=True ${headers}= Create Dictionary Content-Type=application/json Accept=application/json ${message}= Create Dictionary value 0 ${pin}= Patch Request gpio_server /api/v1/pin/18 ${message} headers=${headers} Log ${pin.json()} Delete All Sessions 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. The full version of my code:

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 the robot-framework group. I help new users, whenever I can, and also sometimes I’m the one looking for help.