Robot Framework vs Selenium

Robot framework or Selenium Webdriver? A question frequently asked in professional forums, the answer is pretty simple- “This question is irrelevant”,  there is no sense in comparing the two.

Selenium is a library (some call it a webdriver) and Robot is a test automation framework that uses libraries. With Robot, you can run a variety of automated tests; Both UI element based and API tests, you can run a test with the help of the a math library and a test that validates if the element exists on the page, with the assistance of Selenium Webdriver.

With selenium, you can create UI based functional test cases, but in order to execute them, you’ll need a test automation runner or alternatively, an automation wrapper. There are several popular test runners available out there, for instance: MSTestTestNGNunitJunit etc.

You can see here that I have this script .robot file at the top, and it is capable of interacting with any of these libraries shown below.

Robot Framework vs. Selenium

So if you decide your script wants to do Selenium testing, you simply load up that Selenium2library that's highlighted in yellow, and start writing simple keywords to create your script. So let's see a specific example of this. ,

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

public class ChromeBrowserLaunchDemo {

    public static void main(String[] args) {
        
        //Creating a driver object referencing WebDriver interface
        WebDriver driver;
        
        //Setting the webdriver.chrome.driver property to its executable's location
        System.setProperty("webdriver.chrome.driver", "/lib/chromeDriver/chromedriver.exe");
	
        //Instantiating driver object
        driver = new ChromeDriver();
        
        //Using get() method to open a webpage
        driver.get("https://www.expounddigital.com");
        
        //using Maximize() method to maximize the window
        driver.Manage().Window.Maximize();
        
        //Closing the browser
        driver.close();
 
    }
 
}

This is a typical Selenium test, and you can see up there at the top we've added a bunch of using statements that bring features into the file that we're trying to work with.Then we've got a class, and then we have a main function, and then a bunch of java code here where we're newing up variables and using java syntax to spin up a new Chrome web driver and we're going to navigate it to expound digital. And maximize the window. And then we're going to close the window. Now what's interesting about this is that in order to use different browsers, you'd have to bring in a different using statement for a different web driver, and then the test you'd have to specify somehow which web driver you'd want to use in some kind of a selection statement here. So you can see for a QA person who doesn't have any existing programming skills, this is a pretty steep learning curve. By contrast, this is what a Robot Framework web test looks like. ,

*** Settings ***
Library     Selenium2Library

*** Variables ***
${URL}          https://www.expounddigital.com/
${BROWSER}      Chrome
${wait_time}    2s

*** Keywords ***
Open Home Page
    Open browser    ${URL}   ${BROWSER}
    Maximize Browser Window

Close Browsers
    Close All Browsers

Click On Blog
     Click Element   xpath://a[text()='Blog']

Open Robot Framework Blog
    Click Element    xpath://a[text()='Robot Framework Introduction']
    Sleep    ${wait_time}
*** Settings ***
Suite Setup     Open Home Page
Suite Teardown  Close Browsers
Resource open_robot_blog_keywords.robot 

*** Test Cases *** 
The user can open Robot framework Blogs 
    Click On Blog 
    Open Robot Framework Blog

You can see at the top here I have one line that says I want to bring in the Selenium2 library. Then I define some variables. And then my keywords. In another file I create the name of my test case. There's no classes or anything like that. Just the name of my test case. And then the beginning of each of these lines is a Selenium2 keyword or user defined keyword. So I can say open the browser and I can pass in two different pieces of information to that.And I could say click a button, I pass in the locator to click that button. And sleep here. I just have that in there to keep the window open so we can see it. And then finally close browser. So at its simplest, you can see that Robot Framework is a very easy keyword driven language to use. So hopefully you can see here that by using Robot Framework you can produce very easy to read test cases very easily and you can test a wide variety of things instead of just web like Selenium does.

1 thought on “Robot Framework vs Selenium”

Leave a Reply

Your email address will not be published. Required fields are marked *