Robot framework

Introduction to and examples of Robot Framework

Robot framework

Introduction

Robot Framework is an open-source test automation framework designed to simplify and streamline the process of software testing. It is a generic keyword-driven automation framework that supports both acceptance testing and acceptance test-driven development (ATDD). Developed using Python, Robot Framework allows testers to write high-level test cases in a simple format, making it accessible to both technical and non-technical users.

Key features of Robot Framework include its extensibility, as it supports the integration of external libraries (e.g. Selenium, SSH and MQTT), enabling users to extend its functionality as per their specific requirements. 

Robot Framework promotes a keyword-driven approach, where test cases are expressed using keywords in a readable and understandable syntax. This helps in creating test cases that are both human-readable and easily maintainable. 

With its versatility, ease of use, and robust capabilities, Robot Framework has gained popularity in the software testing community as a reliable tool for test automation, contributing to efficient and effective testing processes in various domains.

In the sections below I have provided a few exmaples of the Robot Framework libraries which I have personally found most useful. These Libraries include: Selenium libarary (Testing user interface through browser), SSH libarary (Opening a shell to any node and execute commands), and finally MQTT libarary (Capable of sending a receiving MQTT messeage to a broker).

Selenium Library Example

1. Install Robot Framework:
				
					pip install robotframework

				
			
2. Install Selenium Library:
				
					pip install robotframework-seleniumlibrary

				
			
3. Create test script
				
					*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Open Browser and Visit Google
    Open Browser    https://www.google.com    chrome
    Input Text    name=q    Robot Framework
    Click Button    name=btnK
    Sleep    2s
    Capture Page Screenshot
    Close Browser

				
			

This script does the following:

  • Opens the Google homepage in the Chrome browser.
  • Types “Robot Framework” into the search bar.
  • Clicks the “Google Search” button.
  • Pauses for 2 seconds.
  • Takes a screenshot of the page.
  • Closes the browser.
4. Run test
				
					robot example_test.robot

				
			

This example demonstrates a basic scenario using the SeleniumLibrary with Robot Framework for web automation. You can customize and expand upon this script based on your specific testing requirements.

SSH Library Example

1. Install SSH Library:
				
					pip install robotframework-sshlibrary
				
			
2. Create test script
				
					*** Settings ***
Library    SSHLibrary

*** Variables ***
${HOST}    localhost
${USERNAME}    your_username
${PASSWORD}    your_password

*** Test Cases ***
Connect to SSH Server
    Open Connection    ${HOST}
    Login    ${USERNAME}    ${PASSWORD}
    ${result}    Execute Command    echo "Hello, SSH!"
    Should Contain    ${result}    Hello, SSH!
    Close All Connections

				
			

Replace ${HOST}, ${USERNAME}, and ${PASSWORD} with your SSH server details.

This example connects to an SSH server, executes a simple command (echo "Hello, SSH!"), and verifies the output.

MQTT Library Example

1. Install SSH Library:
				
					pip install robotframework-mqttlibrary
				
			
2. Create test script
				
					*** Settings ***
Library    MQTTLibrary

*** Variables ***
${BROKER}    mqtt.eclipse.org
${PORT}      1883
${TOPIC}     /robotframework/mqtt
${QOS}       0

*** Test Cases ***
Connect to MQTT Broker
    Connect To MQTT    ${BROKER}    ${PORT}
    Subscribe    ${TOPIC}    ${QOS}
    Publish    ${TOPIC}    Hello, MQTT!    ${QOS}
    ${message}    Wait For Message    ${TOPIC}    timeout=5s
    Should Be Equal As Numbers    ${QOS}    ${message.qos}
    Should Be Equal    Hello, MQTT!    ${message.payload}
    Disconnect From MQTT

				
			

In this example, replace ${BROKER}, ${PORT}, ${TOPIC}, and ${QOS} with your MQTT broker details.

The script connects to an MQTT broker, subscribes to a topic, publishes a message, waits for the message, and then disconnects.

Recommended Reading

Articles

About

Hi, I'm the Author

My name is Daniel H. Jacobsen and I’m a dedicated and highly motivated software developer with a masters engineering degree within the field of ICT. 

I have through many years of constantly learning and adapting to new challenges, gained a well-rounded understanding of what it takes to stay up to date with new technologies, tools and utilities. 

The purpose of this blog is to share both my learnings and knowledge with other likeminded developers as well as illustrating how these topics can be taught in a different and alternative manner.

If you like the idea of that, I would encourage you to sign up for the newsletter.

Cheers! 🍺

Didn't Find What You Were Looking For?

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Scroll to Top
INTEGU - Cookie-consent

INTEGU uses cookies to personalize your experience and provide traceability for affiliate links. By using the website, you agree to these terms and conditions. To learn more see the privacy policy page.