Automation Testing

Getting Started With Robot Framework in Java

By Test Guild
  • Share:
Join the Guild for FREE

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:

  • The basics of Robot Framework and best practices
  • What to avoid
  • How to install the Robot Framework
  • The plugins needed for Robot Framework

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:

  • Double space delimiters: One of the most common gotchas in Robot Framework is the use of double spaces as delimiters. Users often encounter issues when they miss a space or only use a single space between arguments. As Dave Martin mentions, “the biggest gotcha with robot is everything is delimited by a double space. And more often than not, when somebody comes to me and says, hey, this isn't working, I look at, I'm like, you're missing. You've only got one space between these two arguments. You need two.”
  • Potential library conflicts: While the expert didn't encounter any library conflicts himself, he acknowledges the possibility of such issues arising, especially when using external libraries. Managing dependencies and keeping track of library versions using a requirements.txt file can help mitigate this risk.
  • Learning curve for beginners: Although Robot Framework is designed to be accessible and readable, there is still a learning curve for those new to the framework. Users need to familiarize themselves with the keyword-driven approach, understand the structure and syntax, and learn how to effectively use the available libraries and tools.
  • Maintenance and scalability: As the framework grows and more contributors get involved, maintaining consistency, and ensuring the framework remains scalable can be challenging. Establishing clear guidelines, best practices, and code review processes becomes crucial to prevent the framework from becoming unwieldy or difficult to maintain over time.

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:

  • Selenium as a library: Robot Framework uses Selenium as one of its built-in libraries, which means that Selenium's functionality is incorporated into Robot Framework. As Pekka Klärck states, “Selenium library actually said tool library nowadays is probably the most used external test library.”
  • Keyword-driven approach: Robot Framework offers a keyword-driven approach that abstracts the underlying Selenium code, making it easier to write and read tests. This allows users to create tests using predefined keywords without necessarily needing to know the intricacies of Selenium or programming.
  • Ecosystem and multiple libraries: Robot Framework provides a wide range of libraries beyond Selenium, enabling users to perform various types of testing, such as web, mobile, API, and desktop testing, all within the same framework. Selenium, on the other hand, is primarily focused on web browser automation.
  • Robot Framework's support for multiple programming languages (Python, Java, and C#) through different language bindings, while Selenium has bindings for a wide range of languages.
  • The learning curve and ease of use for beginners, considering Robot Framework's keyword-driven approach and Selenium's direct interaction with web elements.
  • A more detailed comparison of the features offered by each tool, such as built-in reporting, test result visualization, and integration with other tools and frameworks.

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

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

    
  <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.

  • 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

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.

  • Web testing: Robot Framework's built-in Selenium library allows users to perform web testing and browser automation. As mentioned by Pekka Klärck, “I can do web testing using the selenium library.”
  • API testing: The framework can be used for API testing, as stated by Dave Martin, “I even automated our API testing with robots.”
  • Desktop application testing: Robot Framework supports desktop application testing using libraries like the Auto It library, which enables interaction with Windows GUI components. Dave Martin mentions, “And there's also a library that we used to support that supports auto it.”
  • Mobile testing: Although not explicitly mentioned in the attached PDF, Robot Framework does support mobile testing through libraries like the Appium library, which allows for automation of mobile web, native, and hybrid applications.
  • Operating system and shell operations: The framework can perform operating system-level tasks and shell operations, as indicated by Pekka Klärck, “I can do operating system level operations, I can do terminal based operations all within the same automation framework using the same keyword driven syntax.”
  • Database testing: Robot Framework can interact with databases using libraries like the Database Library, allowing users to perform database-related operations and validations.
  • Acceptance testing and ATDD: The keyword-driven approach and plain-language syntax make Robot Framework well-suited for acceptance testing and Acceptance Test-Driven Development (ATDD), enabling collaboration between technical and non-technical stakeholders.
  • Performance testing: While Robot Framework is not primarily designed for performance testing, it can be used to generate load by running tests in parallel across multiple machines, as mentioned by Dave Martin, “I can do an operation a whole bunch of times across a whole bunch of different machines, using a robot script to generate load.”

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

  1. Getting this error. INFO] ————————————————————————
    [ERROR] Failed to execute goal org.robotframework:robotframework-maven-plugin:1.4.6:run (default-cli) on project CoreRobot: Execution default-cli of goal org.robotframework:robotframework-maven-plugin:1.4.6:run failed: An API incompatibility was encountered while executing org.robotframework:robotframework-maven-plugin:1.4.6:run: java.lang.UnsupportedClassVersionError: org/robotframework/RobotFramework : Unsupported major.minor version 51.0
    [ERROR] —————————————————–
    [ERROR] realm = plugin>org.robotframework:robotframework-maven-plugin:1.4.6
    [ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy

  2. Getting this error:

    [ERROR] Failed to execute goal org.robotframework:robotframework-maven-plugin:1.4.6:run (default-cli) on project RobotFramwork: Execution default-cli of goal org.robotframework:robotframework-maven-plugin:1.4.6:run failed. PyException: Cannot create PyString with non-byte value -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
    Exception in thread “Jython-Netty-Client-6” java.lang.NoClassDefFoundError: org/python/netty/util/concurrent/DefaultFutureListeners
    at org.python.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:577)
    at org.python.netty.util.concurrent.DefaultPromise.setSuccess(DefaultPromise.java:397)
    at org.python.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:155)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.ClassNotFoundException: org.python.netty.util.concurrent.DefaultFutureListeners
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
    … 4 more

    Can you help me?

  3. Hi Joe,
    Thanks for a such nice article. Very helpful indeed.
    I am new to Robot Framework. I followed the steps listed in the article however keep getting following error while running the test.
    Is there any pointer you can provide for resolution?

    —————————————————————————————
    Failed to execute goal org.robotframework:robotframework-maven-plugin:1.4.6:run (default-cli) on project JavaRobot: Execution default-cli of goal org.robotframework:robotframework-maven-plugin:1.4.6:run failed: Plugin org.robotframework:robotframework-maven-plugin:1.4.6 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:6 at specified path C:\Program Files\Java\jre1.8.0_101/../lib/tools.jar -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

  4. I got an issue like as :

    org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/Applications/Firefox.app/Contents/MacOS/firefox-bin) on port 7055; process output follows:
    Locale”:{“name”:”Default”,”description”:”The default theme.”,”creator”:”Mozilla”,”homepageURL”:null,”contributors”:[“Mozilla Contributors”]},”visible”:true,”active”:true,”userDisabled”:false,”appDisabled”:false,”descriptor”:”/Applications/Firefox.app/Contents/Resources/browser/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi”,”installDate”:1486024522000,”updateDate”:1486024522000,”applyBackgroundUpdates”:1,”skinnable”:true,”size”:6352,”sourceURI”:null,”releaseNotesURI”:null,”softDisabled”:false,”foreignInstall”:false,”hasBinaryComponents”:false,”strictCompatibility”:true,”locales”:[],”targetApplications”:[{“id”:”{ec8030f7-c20a-464f-9b0e-13a3a9e97384}”,”minVersion”:”51.0.1″,”maxVersion”:”51.0.1″}],”targetPlatforms”:[],”seen”:true,”dependencies”:[],”hasEmbeddedWebExtension”:false}

    –> seem like the robot couldn’t input the URL. Could you help me to solve it ? Thanks so muck

  5. Thanks for the article.

    When I am running the same test, I am getting below exception:-

    As I need to run this using Java then why this is throwing exception regarding python.

    Exception in thread “Jython-Netty-Client-1” java.lang.NoClassDefFoundError: org/python/netty/util/concurrent/DefaultFutureListeners
    at org.python.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:577)
    at org.python.netty.util.concurrent.DefaultPromise.setSuccess(DefaultPromise.java:397)
    at org.python.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:155)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.ClassNotFoundException: org.python.netty.util.concurrent.DefaultFutureListeners
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
    … 4 more
    Exception in thread “Jython-Netty-Client-8” java.lang.NoClassDefFoundError: org/python/netty/util/concurrent/DefaultFutureListeners
    at org.python.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:577)
    at org.python.netty.util.concurrent.DefaultPromise.setSuccess(DefaultPromise.java:397)
    at org.python.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:155)
    at java.lang.Thread.run(Thread.java:745)

  6. Thank you for sharing nice article.
    I followed the steps, but I got prefix error
    [INFO] ————————————————————————
    [ERROR] No plugin found for prefix ‘robotframework’ in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\mishra.rakesh\.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    can you please help me to resolve this

  7. Hi Joe,

    I am getting the below error on running.

    Failed to execute goal org.robotframework:robotframework-maven-plugin:1.4.6:run (default-cli) on project AntsRobot: Execution default-cli of goal org.robotframework:robotframework-maven-plugin:1.4.6:run failed: Plugin org.robotframework:robotframework-maven-plugin:1.4.6 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:6 at specified path C:\Users\AB76137\Desktop\eclipse\jre/../lib/tools.jar -> [Help 1]

    Please help

  8. Getting Error –
    [ ERROR ] Error in file ‘D:\RobotFramework\Workplace\javarobot\src\test\robotframework\acceptance\Test_Case_1.txt’: Importing test library ‘Selenium2Library’ failed: ImportError: No module named Selenium2Library
    Traceback (most recent call last):
    None
    PYTHONPATH:
    C:\maven\repo\org\robotframework\robotframework\3.0.2\Lib
    Acceptance.Test Case 1 :: A resource file containing the application specif…

  9. Hi All,
    Thanks Joe for this great article.
    In case anyone needs the pom.xml at one place:

    4.0.0

    RFTEST
    RFTEST2
    0.0.1-SNAPSHOT
    jar

    RFTEST2
    http://maven.apache.org

    UTF-8

    org.robotframework
    robotframework-maven-plugin
    1.7.1

    run

    com.github.hi-fi
    robotframework-seleniumlibrary
    3.141.59.26535
    test

    org.python
    jython-slim
    2.7.2

    junit
    junit
    3.8.1
    test

    Note:
    I was facing an error like below and found a workaround for the same:

    Failed to execute goal org.robotframework:robotframework-maven-plugin:1.4.6:run (default-cli) on project JavaRobot: Execution default-cli of goal org.robotframework:robotframework-maven-plugin:1.4.6:run failed: Plugin org.robotframework:robotframework-maven-plugin:1.4.6 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:6 at specified path C:\Program Files\Java\jre1.8.0_101/../lib/tools.jar -> [Help 1]

    Workaround 1(which worked for me):
    Goto your Eclipse folder >>Eclipse configuration settings file and add the following before vmargs:

    -vm
    C:\Program Files\Java\jdk1.8.0_66\bin\javaw.exe

    Workaround 2(I found on the internet):
    Add an exclusion tag to your selenium library dependency as below:

    com.github.markusbernhardt
    robotframework-selenium2library-java
    1.4.0.7
    test

    tools
    com.sun

  10. I only receive the msg that tools.jar was not found when I tried to run the goal. How can I fix it?

Comments are closed.

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

Leveraging AI and Playwright for Test Case Generation

Posted on 11/22/2024

Two BIG trends the past few years in the software testing space been ...

Symbolic AI vs. Gen AI: The Dynamic Duo in Test Automation

Posted on 09/23/2024

You've probably been having conversations lately about whether to use AI for testing. ...

8 Special Ops Principles for Automation Testing

Posted on 08/01/2024

I recently had a conversation, with Alex “ZAP” Chernyak about his journey to ...

Register for AutomationGuild 2025 Online Event (Before Early Price Increase) - Join Now! >>