Getting Started With Robot Framework in Java

Automation Testing Published on:

I recently interviewed the creator of the Robot Framework, Pekka Klark, on my Testalks podcast. So I thought it would be a good time to create a quick tutorial on how to actually get started with Robot Framework in Java.

The Robot Framework is an open-source test automation framework that is based on Python and uses a keyword-driven approach to test automation. Robot Framework also supports Jython(Java) and IronPython(.NET).

Just a heads up, I’m not an expert in the Robot Framework – yet. I’m just getting started, and this post is me actually learning as I go in real-time. I honestly couldn’t find any clear setup instructions to get started with the Robot Framework in Java.
But based on what I found in the getting started instructions and various StackOverflow conversations this is what I did. Some of these steps might not be 100% necessary but they worked on getting my example to run.

I will be posting more Robot Framework tutorials as I learn new things to share with others who also might be starting off.

In this post, you’ll learn

  • The basics of Robot Framework
  • How to install the Robot Framework
  • The plugins needed for Robot Framework

INDEX
How to Install Robot Framework
Install Robot Framework Selenium2 Library in Java
Create a simple project
Add entries to the Pom file
Create your first Robot Framework Java test
Create a Maven Run Command Goal and Run the Test
Install Robotide Eclipse IDE plugin

Get Automation Testing Tips

How to Install Robot Framework


For this example, I will be using Java with Maven and will be using Selenium2Library. Besides Selenium, the Robot Framework has external libraries with existing keywords for lots of other technologies like

  • Appium
  • Android
  • Swing
  • FTP
  • HTTP
  • Database
  • AutoIt

Install Robot Framework Selenium2 Library in Java

All we need to do for this example is import a few libraries into our project Maven pom file. Let's take a look at creating a simple project that includes the Robot Framework maven dependencies.

Create a simple project

In Eclipse, select File>New>Other, and in the New dialog, select the Maven folder

  • Select Maven Project
  • Click on the Use default Workspace location, and click Next
  • On the next screen, select the default maven-archetype-quickstart option

 

newMavenRobotframework

  • Click Next
  • Enter the following:
  • Group Id = com.testtalks.robot
  • Artificat Id = javarobot
  • Version = 0.0.1-SNAPSHOT
  • Click Finish

NewMavenProjectSettings2

Add entries to the Pom file


You should now have a project called javabot. Expand it and double-click the pom.xml
Open your pom.xml file and add the following dependencies:

      
     
        
            org.robotframework
            robotframework
            2.8.7
                  
       
         com.github.markusbernhardt
        robotframework-selenium2library-java
        1.4.0.8
       
     
        

Also, add the following plugin:

        
     

        
        org.robotframework
        robotframework-maven-plugin
        1.4.7
        
          
            
              run
            
          
                
             

Get FREE Automation Testing Courses

Create your first Robot Framework Java test

 

You don’t actually write your Robot Framework test in java. Robot Framework is a generic keyword-driven framework that uses text files with keywords that it understands to run your tests. 

So in Java, all you are doing right now is creating a text file with Selenium2 keywords.

Because the Robot Framework comes with many ready-made built-in keywords for things like Selenium, it is easy to get started with a simple test and not have to write any code.

So let’s create our Java Robot project and test case.

  • Under the src/test/java directory add a New Folder named robotframework/acceptance

RobotFrameworkTests3

  • Click on Finish
  • Right-click on acceptance and select New>File
  • Name the file txt


Open the Test_Case_1 text file and enter the following. Be careful spaces matter! There are two spaces between everything

*** Settings ***
Documentation  A resource file containing the application specific keywords
Library		Selenium2Library

*** Test Cases ***
Check out joe colantonio dot com
	Open Browser  https://testguild.com  ff
	Close Browser


To find out what each keyword used in this simple example and what other keywords are available to you go to the keyword documentation:

https://repo1.maven.org/maven2/com/github/markusbernhardt/robotframework-selenium2library-java/1.4.0.8/robotframework-selenium2library-java-1.4.0.8-libdoc.html

In our example, you can see that for the Open Browser keyword it opens a new browser instance given URL.

LISTEN TO AUTOMATION TESTING PODCASTS

Create a Maven Run Command Goal and Run the Test

  • Right-click on the java robot directory and select Run As>Run Configurations..
  • In the Run Configuration dialog dbl click on the Maven Build
  • Click on the Browser Workspace button and select the java robot project as the base directory
  • Under Goals enter robotframework:run
  • Click on the Resolve Workspace artifacts and the Update Snapshots
  • Click Apply
  • Click Run


If all goes well the browser should start and navigate to joecolantonio.com without any errors.


I kept getting the error Failed to execute goal org.robotframework:robotframework-maven-plugin:1.4.6:run at first when I tried this example.

It turned out to be due to me not having two spaces between my URL and the browser type I wanted to run. The Robot Framework cares about proper formatting, like spaces!

RobotFrameworkResults5

robotframeworkrun4

Install Robotide Eclipse IDE plugin


To avoid any issues with spaces, let’s also install the robotide Eclipse IDE plugin for RobotFramework:

  • Close eclipse
  • Navigate to : https://sourceforge.net/projects/robotide/files/stable/features/
  • Click on the Download content.jar
  • Once the content.jar is downloaded copy it to your eclipse’s plugins and features directories
  • Restart Eclipse now in your .robot file if you don’t have the correct amount of spaces between your parameters

RobotframeworkEclipseIDE6

Final Thoughts

That’s it for our introduction to Robot Framework in Java! We hope you found this tutorial helpful. If you want to learn more or get started using Robot Framework for your own projects, be sure to check out Test Guild. Our website is packed with information on automation tools and techniques, as well as tutorials like this one.

And if you have any questions about Robot Framework or anything else related to automated testing, don’t hesitate to reach out – we love helping people learn new things and grow their skill sets. Thanks for reading, and happy testing!

Work With Me

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Must See TestResults.io Product Review

Posted on 11/21/2022

In this post, we'll look at TestResults.io for a product review. When creating ...

Unlocking end-to-end testing for all with mabl

Posted on 09/27/2022

A recent *study showed that 75% of organizations use a combination of manual ...

AI Powered API Testing (Meet Loadmill)

Posted on 09/21/2022

I just learned of a great tool (Loadmill) to help automated API test ...