Automation testers Stop using Java and switch to Robot!

Vedashree Paranjape
4 min readSep 10, 2023

--

Considering that the majority of automation testing community uses Java with Selenium and I have been using Robot Framework since the start of my career and I never found any limitation of Robot whatsoever. So I went through some tutorials and sample codes of Java to see what exactly is Java offering which cannot be done with Robot, but I didn’t find anything! I actually didn’t find any advantage of using Java for automation. This might raise a few eyebrows but when I say this I am talking in comparison to Robot Framework. Read till the end to see for yourself.

Before anything else lets just have an apples to apples comparison of code which opens www.selenium.dev website on Chrome browser, searches for a text and clicks on first search result.

Let the battle begin!!

Java vs Robot Framework

First one is a Java+Selenium code which I found online for a login functionality and I modified it for the above scenario, second one is the Robot+Selenium code which I have written. Both the codes do exactly the same thing! (except Robot one does a few additional things too 😉) :

Java:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class SeleniumAutomation {
@Test
public void Selenium() {
System.setProperty("webdriver.chrome.driver", "path of driver");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.selenium.dev/");
WebElement searchicon=driver.findElement(By.id("docsearch"));
searchicon.click();
WebElement searchinputbox=driver.findElement(By.xpath("//input[@type="search"]"));
searchinputbox.sendKeys("Timeouts");
WebElement searchresult1=driver.findElement(By.id("docsearch-item-0"));
searchresult1.click();
String actualUrl=driver.getCurrentUrl();
String expectedUrl= "https://www.selenium.dev/documentation/webdriver/drivers/options/#timeouts";
Assert.assertEquals(expectedUrl,actualUrl);
}
}

Robot:

*** Settings ***
Library SeleniumLibrary implicit_wait=10 run_on_failure=Capture Page Screenshot
*** Test Cases ***
TC1: Selenium
Open Browser https://www.selenium.dev/ Chrome
Maximize Browser Window
Click Element id=docsearch
Input Text //input[@type="search"] Timeouts
Click Element id=docsearch-item-0
Location Should Be https://www.selenium.dev/documentation/webdriver/drivers/options/#timeouts

Now if you are new to Robot Framework or haven’t heard about it still by looking at the code you can tell how simple it is compared to Java. If you have any doubts about it you can actually try it yourself in just few steps and see the magic. The setup is extremely easy:

  1. Install Python
  2. In command prompt run commands:
    pip install robotframework
    pip install robotframework-seleniumlibrary
  3. Download chromedriver for the version of chrome browser you are using and save it in PATH.

Done!

Save the above code with a .robot extension (sample.robot) open command prompt where the file is located and run command: robot sample.robot and the script will get executed.

Advantages of using Robot instead of Java:

  1. Lines of code reduced to less than 50% (as per above code)
  2. Ease of coding and maintenance (No need to worry about complex syntax, all the semi-colons, parenthesis, dots and quotes!)
  3. Increased readability
  4. No separate reporting plugin/tool needed, automatically a beautiful log and report file gets generated
    (if you execute above robot code a log and report file will get generated at the location where the robot file is located)
  5. If the script fails, the log will have screenshot of the page where it failed
  6. Customisable

Some other features of Robot Framework

  1. Open Source
  2. Supports Mac, Windows, Linux OS
  3. Just like Selenium, Robot can be used with Appium to automate iOS, Android mobile, Android TVs, Apple TV and any other platform which Appium supports
  4. We can write our own python function and import it in Robot for any custom requirements
  5. We can separate the tests from the locators using variables to ease maintenance
  6. We can write reusable keywords which can be used in multiple tests
  7. Supports integration with JIRA+Xray so automation results can be directly imported in JIRA
  8. Integration with Azure/Jenkins any CI/CD tool
  9. Supports parallel execution
  10. Supports execution with selenium grid
  11. API automation also supported with Requests library
  12. Supports automation of Native Windows and Mac apps like Calculator
  13. Many other libraries available for different requirements and we can create our own library too

And many more…

The code above is just a sample and by using proper framework structure we can create a very efficient and easy to use code with minimum maintenance and coding efforts. If you are interested in learning more about Robot Framework and its features let me know in comments and I would be happy to share more!

All that being said about Robot Framework, If you know of any limitation of RF or any advantage which Java offers I am open to learn more about it so do share your views in the comments. Also any feedback is most welcome!

Happy Learning! 🙌

Official Robot Framework site: https://robotframework.org/

--

--