Getting Started With Robot Framework in Java

What is Robot Framework?

Robot Framework is an open-source, keyword-driven test automation framework that enables easy-to-use and maintainable acceptance testing and acceptance test-driven development (ATDD). It provides a flexible and extensible architecture that allows users to create powerful and robust automation solutions.

As Pekka Klärck, the creator of Robot Framework, explained in an interview on my automation podcast:

“Robot framework is an open source automation framework, primarily keyword driven. The thing I love about it is that the Selenium library is just one of many libraries that come out of the box with robot frameworks that are built in. I can do web testing using the Selenium library. I can do operating system-level operations, and I can do terminal-based operations all within the same automation framework using the same keyword-driven syntax.”

The keyword-driven approach, a hallmark of Robot Framework and its extensive ecosystem of libraries, makes it a user-friendly tool that caters to users with varying levels of programming experience.

Robot Framework, with its support for different types of testing and integration with various tools and technologies, is a comprehensive solution. Its excellent built-in reporting capabilities and seamless integration into CI/CD pipelines make it a top choice. Moreover, the active community and abundance of learning resources make it a user-friendly tool for test automation needs.

Because of its flexibility in handling multiple technologies and testing techniques,

I like to think of it as the Swiss army knife of automation frameworks.

Sound good?

Read on to learn more about:

INDEX

What are some best practices recommended for using Robot Framework effectively?

Here are ten best practices often mentioned on my podcast and online events from Robot Framework experts:

  1. Organize keywords in a reusable and maintainable manner: Create granular, low-level keywords and mid-tier keywords that combine multiple low-level keywords. This approach improves reusability and maintainability of the framework.
  2. Follow a page object-like pattern: While not strictly object-oriented, organizing keywords and elements in a page object-like manner can enhance the structure and readability of the framework.
  3. Leverage built-in and external libraries: Robot Framework comes with a wide range of built-in libraries, such as Selenium, operating system, and string libraries. Utilize these libraries and explore the extensive ecosystem of external libraries to extend the framework’s capabilities.
  4. Create an abstraction layer for built-in keywords: Wrap built-in Robot Framework keywords with custom keywords to create an abstraction layer. This approach makes it easier to maintain and modify the framework in the future, as it reduces the impact of potential changes to the underlying libraries.
  5. Implement proper logging and reporting: Robot Framework offers excellent built-in reporting capabilities. Leverage these features by adding meaningful log messages at different levels (e.g., trace, debug, info) to facilitate debugging and troubleshooting. Use the built-in screenshot capture functionality to document failures automatically.
  6. Design keywords for clarity and readability: When creating custom keywords, ensure that they are named and designed in a way that clearly conveys their purpose. This makes the test cases more readable and easier to understand, even for non-technical stakeholders.
  7. Adopt a scalable and modular architecture: Design your Robot Framework implementation in a scalable and modular manner, using a layered approach. This allows for easier maintenance, reusability, and adaptability as the framework grows.
  8. Integrate with CI/CD pipelines: Incorporate Robot Framework into your CI/CD pipelines using tools like Jenkins. Take advantage of plugins and post-build actions to automatically publish test results and integrate with test management systems.
  9. Encourage collaboration and knowledge sharing: Foster a collaborative environment where team members can contribute to the framework’s development. Establish coding guidelines and best practices to ensure consistency and maintainability. Promote knowledge sharing through regular meetings, documentation, and mentoring.
  10. Continuously learn and leverage the community: Stay updated with the latest developments in Robot Framework and its ecosystem. Engage with the active community through forums, slack channels, and events to learn from others’ experiences and get support when needed.

What are the challenges associated with using Robot Framework?

The experts also mentioned a few challenges and potential gotchas associated with using Robot Framework:

What are the differences between Robot Framework and Selenium?

Many newbies get confused with understanding how Selenium works with Robot Framework. Here are some difference to be aware of:

How to Get Started

Just a heads up, I’m not an expert in the Robot Framework – yet. I’m just starting, and this post is me learning as I go in real time. I honestly couldn’t find any clear setup instructions to start 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.

 

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

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

newMavenRobotframework
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:

    
  <dependency>
  <groupId>org.robotframework</groupId>
  <artifactId>robotframework</artifactId>
  <version>2.8.7</version>
  </dependency>
  
  <dependency>
  <groupId>org.robotframework</groupId>
  <artifactId>robotframework-maven-plugin</artifactId>
  <version>2.1.0</version>
  <type>maven-plugin</type>
</dependency>
    
  
  
Also, add the following plugin:
   <plugin>
        <groupId>org.robotframework</groupId>
        <artifactId>robotframework-maven-plugin</artifactId>
        <version>2.1.0</version>
        <executions>
          <execution>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
                           
             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.

RobotFrameworkTests3


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

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:

RobotframeworkEclipseIDE6

now that you have everything installed you might be asking what can I test with this framework?

What are the different types of testing supported by Robot Framework?

Once again due to it’s flexibility and numerous libraries here is a small sample of the types of testing that is supported.

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 projects, check out Test Guild. Our website is packed with information on automation tools and techniques and tutorials like this one.

And if you have questions about Robot Framework or anything 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