How to use RobotFramework with the Selenium Library

  • Sharebar

RobotFramework logo

At Wallix we use RobotFramework to test our products AdminBastion and LogBox in a black box way mainly for exercising the web interface. In this blog post we’ll explain one way of using RobotFramework to test web interfaces either for web site testing or for web application testing.

What is RobotFramework ?

Robot Framework is a generic test automation framework for acceptance testing. It has an easy-to-use tabular test data syntax and utilizes a keyword-driven testing approach. Its testing capabilities can be extended by test libraries implemented either with Python or Java, and users can create new keywords from existing ones using the same syntax that is used for creating test cases.

 Robot Framework is an open source software released under the Apache License 2.0. It’s developed and owned by Nokia Siemens Networks.

For more information in order to install and setup RobotFramework, you should read the RobotFramework Wiki and the Setup and installation page.

What is the Selenium Library ?

The Selenium Library is a RobotFramework test library that uses the popular Selenium web testing tool internally. It provides a powerful combination of a simple test data syntax and support for different browsers.

Objective of this Tutorial

The objective of this tutorial is to explain how to use RobotFramework with Selenium and to detail some functionalities of RobotFramework by the way.

Pre-conditions

  • Install RobotFramework on your machine: ( python setup.py install ), for Windows environment you have to install python 2.7.
  • Then, you have to get the Java Runtime Environment (JRE) for running the Selenium Server.
  • Make sure you have Firefox in your path.
  • Install the Selenium Library using: python setup.py install

For Windows environment you can use the windows installer.

Getting started

First, you have to launch the Selenium server. In a terminal go to your directory where selenium-server.jar file are present and launch the server by typing :

[mbu@mbu2 poc]$ cd <my selenium server directory>
[mbu@mbu2 poc]$ java -jar selenium-server.jar

Your Selenium server should start …You can specify more options, like port, firefox profile etc…

Now you can write your first test. This test will open a browser to www.google.fr web site and type selenium in the search area.

Before writing your first test make sure that the command pybot –help works well.

There are different ways to write a test with RobotFramework. You can write your test in an html file using a table, in a standard text file or in a rst file. In this tutorial, we will use a standard text file.

So, now you can make a directory for your first test:

[mbu@mbu2 poc]$ mkdir tuto

And then you can create a txt file called myFirstTest.txt. It’s the main file that RobotFramework will execute for running the test. In this file, functions described by « Keywords » will be called by the robot.

The main test file: myFirstTest.txt

A test file contains different sections, like settings, variables, testcase or keywords. Section are defined with three wild cards.

First you have to fill the Settings section:

*** Settings ***
Documentation  This is your first test

In the Settings section, the word « Documentation » is a keyword. It means that this word is interpreted by RobotFramework and executed. The keyword « Documentation » will print in your terminal and in the log file the text : « this is your first test ».

Then, you have to set your resources files. Resource files are optional. You can write all your variables and your own keywords in the same file but it’s better for your test suite to put your variables and global informations in different files to reuse them in all your tests. To demonstrate their usage in this tutorial, you will use two resources files :

  • one for global variables and library: common.txt
  • another one for specific keywords: google-search.txt

Add the following lines to your file to declare these resources:

Resource  common.txt
Resource  google-search.txt

Then, you have to specify your tests cases. In this example, you’ll create TestsCases and call keywords which are contained in google-search.txt resource file (we’ll create those keywords in the second part of this tutorial).

*** Test Cases ***

Go To Google Page [Documentation] Go to google page and search something
    Open Browser to Google Page
    Input Search  selenium
    Submit Search

Open Selenium Page [Documentation] TestCase for open Selenium page
    Click Selenium Link
    Selenium Blog Should Open

    [Teardown]  Close Browser

Here, you have two TestsCases which contains your own keywords.

Resource File : google-search.txt

In this file, you’ll specify all keywords for running RobotFramework with the Selenium Library.

This file is also made of section like your first file:

*** Settings ***
Documentation  this ressource file contain specific keywords for running
...            Robotframework and Selenium Lib

*** Variables ***
${google_url}  http://www.google.fr/

You can create variables with this syntax ${myVar}. By default the type of variables is string. You can create other variables like list or dictionary. We’ll see this in another tutorial…

*** Keywords ***

Open Browser To Google Page
    Open Browser  ${google_url}  ${browser}
    Maximize Browser Window
    Set Selenium Speed  ${sel_speed}
    Title Should Be  Google

Input Search  [Arguments]  ${search}
    Input Text  lst-ib  ${search}

Submit Search
    Click Button  btnG  don't wait

Click Selenium Link
    Click Link  http://seleniumhq.org/

Selenium Blog Should Open
    Title Should Be  Selenium - Web Browser Automation

So, in this second part, you have created all of your keywords needed for your test. Now you have to create the second resource file containing global and common variables.

Resource File : common.txt

Like in the other files you specify a Settings section:

*** Settings ***
Documentation  This resource file contains common and global variables
Library  SeleniumLibrary  5  localhost

*** Variables ***
# Choose Firefox Chrome Browser :
# You can change here your web browser.
${browser}  *chrome
${sel_speed}  1

Here, you import the Selenium library. You have to specify some parameters like the host, port and time out.

Then, you create two variables, one for the browser to use, another one for Selenium speed.

Important : In the RobotFramwork syntax, you can comment some words with the character # . You have to respect the indentation : keywords, data or variables must be separated by TWO spaces minimum.

Here, you could find all of Selenium Library keywords : http://robotframework-seleniumlibrary.googlecode.com/hg/doc/SeleniumLibrary.html?r=2.7

And here you can find all the standards libs included in RobotFramework and external libs: http://code.google.com/p/robotframework/wiki/TestLibraries

With these other libs you can automate ssh connection for example or telnet or use RobotFramework on a remote machine.

Launch your test

To launch your test you have to type in a terminal:

[mbu@mbu2 poc]$ pybot myFirstTest.txt
==============================================================================
myFirstTest :: This is your first test
==============================================================================
...Google Page [Documentation] Go to google page and search something | PASS |
------------------------------------------------------------------------------
Open Selenium Page [Documentation] TestCase for open Selenium page | PASS |
------------------------------------------------------------------------------
myFirstTest :: This is your first test | PASS |
2 critical tests, 2 passed, 0 failed
2 tests total, 2 passed, 0 failed
==============================================================================
Output: /home/mbu/Projet/qa/poc/tuto/output.xml
Report: /home/mbu/Projet/qa/poc/tuto/report.html
Log: /home/mbu/Projet/qa/poc/tuto/log.html

Results and reports

After the execution, RobotFramework create three output files :

  • log.html : the result step by step of your test.
  • Report.html : A little report of your test suite
  • output.xml : another output in xml format.

Here are some screenshots of those output files:

Log file

Log file 2

Report file

Output file

Screenshots

RobotFramework takes screenshots during the execution and when TestsCases fail:

Screenshot

More

You can use RobotFramework IDE called RIDE to write your tests.

In a next tutorial, we’ll explain more about RobotFramework: how to manipulate strings, conditions (if else), loops, recursive functions, and more.

Stay tuned !

Article contributed by Mathieu Bultel, QA engineer at Wallix.

Incoming search terms:

  • robot framework tutorial
  • robot framework selenium
  • robot framework selenium tutorial
  • robot framework example
  • robot framework
  • robotframework
  • selenium robot framework tutorial
  • selenium robot framework
  • selenium robot
  • robotframework tutorial
This entry was posted in test and tagged , , , , . Bookmark the permalink.

40 comments on “How to use RobotFramework with the Selenium Library

  1. Pingback: A Smattering of Selenium #56 « Official Selenium Blog

  2. prabakaran on said:

    Thanks a lot , For this Tutorial looking Forward to know about the Loop and conditions . Please Publish it as soon as possible

  3. Pingback: Using RobotFramework with the Selenium Library

  4. Vladimir Belorusets on said:

    Thank you, guys.
    Very clear and easy to follow tutorial.
    It will help me to evaluate test automation frameworks that can be used with Selenium.

  5. Kavitha on said:

    It very clear and was very helpful to start with robot frame work..

    Thanks a Ton..

    Expecting more

  6. ralph on said:

    Why so complicated?
    Install RIDE for robot Framework.

  7. Mayur on said:

    Gr8 Tutorial

    Thanks a lot.

    Regards
    Mayur

  8. When I hit run, 2 windows open: Selenium Remote Control chrome://src/content/RemoteRunner.html?sessionId=72d13ab9f702465e8a825a65b07bc41a&multiWindow=true&baseUrl=http%3A%2F%2Fwww.google.fr%2F&debugMode=false&driverUrl=http://localhost:4444/selenium-server/driver/

    and then another one where it tries to connect to: http://localhost:4444/selenium-server/core/Blank.html?start=true and fails
    What am I doing wrong here?

    • mbu on said:

      Hi Alex,

      It’s hard to answer and to find a solution to your problem.

      Can you tell me more about your config of selenium server and your parameters ?

  9. Laloo Thadhani on said:

    Hi all

    I am getting the following error while executing the Test Cases on Robot IDE
    C:\_Dev_\_Experiments_\RobotFramework\RFPythonVariables\MyRunner.py –argumentfile c:\docume~1\a0868050\locals~1\temp\RIDE3yoxja.d\argfile.txt –listener C:\Python26\lib\site-packages\robotide\contrib\testrunner\SocketListener.py:5010 C:\_Dev_\_Experiments_\RobotFramework\RFPythonVariables
    MyRunner: Called by RIDE
    MyRunner.main: argv=['--argumentfile', 'c:\\docume~1\\a0868050\\locals~1\\temp\\RIDE3yoxja.d\\argfile.txt', '--listener', 'C:\\Python26\\lib\\site-packages\\robotide\\contrib\\testrunner\\SocketListener.py:5010', 'C:\\_Dev_\\_Experiments_\\RobotFramework\\RFPythonVariables']

    can somebody help

  10. Ankur on said:

    Great tutorial…but i little bit confused regarding global variables and library: common.txt
    Is we have to make new text file for it?

  11. Bharath Kumar on said:

    Hi, I followed the same steps as mentioned in the tutorial but my test cases failed as below

    C:\RobotFramework\tuto>pybot myfirsttest.txt
    ==============================================================================
    Myfirsttest :: this is my first robot test
    ==============================================================================
    Go To Google Page [Documentation] Go to google page and searcg som… | FAIL |
    No keyword with name ‘Open Browser to Google Page’ found.
    ——————————————————————————
    Open Selenium Page [Documentation] TestCase for open selenium page | FAIL |
    No keyword with name ‘Click Link http://selenium.org‘ found.
    ——————————————————————————
    Myfirsttest :: this is my first robot test | FAIL |
    2 critical tests, 0 passed, 2 failed
    2 tests total, 0 passed, 2 failed
    ==============================================================================
    Output: C:\RobotFramework\tuto\output.xml
    Log: C:\RobotFramework\tuto\log.html
    Report: C:\RobotFramework\tuto\report.html

    C:\RobotFramework\tuto>

    Any help please

    Bharath

    • Teresa on said:

      You need to create the file google-search.txt with the contents:

      *** Settings ***
      Documentation this ressource file contain specific keywords for running
      … Robotframework and Selenium Lib

      *** Variables ***
      ${google_url} http://www.google.fr/

      *** Keywords ***

      Open Browser To Google Page
      Open Browser ${google_url} ${browser}
      Maximize Browser Window
      Set Selenium Speed ${sel_speed}
      Title Should Be Google

      Input Search [Arguments] ${search}
      Input Text gbqfq ${search}

      Submit Search
      Click Button btnG don’t wait

      Click Selenium Link
      Click Link http://seleniumhq.org/

      Selenium Blog Should Open
      Title Should Be Selenium – Web Browser Automation

      • Manav Kataria on said:

        Make sure you have atleast a double space between a keyword, data and arguments. Read the ‘IMPORTANT’ note in the article.

  12. Monika on said:

    Hi, I tried to run your tutorial but each time I get the error: “ERROR: Element lst-ib not found”. I tried changing “lst_ib” to “id=lst_id” but it does not help. I use Firefox. Do you have any idea what is causing it or what should I change? Thanks in advance

  13. Monika on said:

    There should be “id=lst_ib” instead of “id=lst_id”, misspeling, sorry.

  14. mallik on said:

    Hi All
    I am using rbframewrk 2.7 with selenium . I am using for functional testing of a product. i need to get a value from a drop downlist so how can i select that value from the drop down list. can anyone help me on this.If Any smaple example is there it will be more helpful
    Thanks in advance.

  15. Pingback: 48.228 Elite Proxies Pack

  16. This does not work if you use the Jython based version of Robot Framework. Run a command like this:

    java -jar robotframework-2.7.3.jar myfirsttest.txt

    And you’ll be told:

    [ ERROR ] Parsing ‘c:\Projects\myfirsttest.txt’ failed: File has no test case table.

    The contents of myfirsttest.txt, as per your example, are:

    *** Settings ***
    Documentation This is your first test

    Resource common.txt
    Resource google-search.txt

    I do have a google-search.txt file in the same location as the myfirsttest.txt file. So it looks like the Jython installer may not be reading the resources correctly?

    Barring this issue, which may just be my own mistake, getting Robot Framework up and running seems much more cumbersome than just using something like Cucumber. I opted for the Jar package because then I didn’t have to worry about all the other set up stuff. Nice article, though. I appreciate the detail you went into.

  17. Actually, in regards to my last comment, I get the same error with pybot (with a direct Python installation) as well. So never mind. I don’t think Robot is going to work for me regardless! :)

  18. thanks a lot for your short tutorial.
    i understand paragraphs more than words in a cage (i.e. robot’s users guide).
    can you give more insights on curl automation using selenium/robot fw?
    i’m doubting whether i can make use of the whole framework for curl and output matching.
    i have to do HTTP POST/SET, then GET to verify the output.
    anyway.. great stuff! keep it coming..

  19. North Wales Web Design on said:

    Hmm is anyone else encountering problems with the pictures on this blog loading?
    I’m trying to figure out if its a problem on my end or if it’s the blog.
    Any suggestions would be greatly appreciated.

  20. google first page on said:

    This paragraph offers clear idea in favor of the new users of blogging, that in
    fact how to do running a blog.

  21. Freda on said:

    Fantastic beat ! I would like to apprentice at the same time as you amend your site,
    how can i subscribe for a weblog website? The account helped
    me a acceptable deal. I have been tiny bit familiar of this your
    broadcast offered vibrant transparent concept

  22. Rahul Dave on said:

    Hello friends I have tried above example with given instruction but I am getting below error please suggest solution. Thanks in advance…..!

    [ ERROR ] Error in file ‘C:\Robot Examples\TestRobo\myFirstTest.txt’ in table ‘Settings’: UnicodeDecodeError: ‘utf8′ codec can’t decode byte 0×85 in position 0: invalid start byte
    ==============================================================================
    myFirstTest :: this is your first Test
    ==============================================================================
    Go To Google Page [Documentation] Go to google page and search som… | FAIL |
    No keyword with name ‘Open Browser to Google Page’ found.
    ——————————————————————————
    Open Selenium Page [Documentation] TestCase for open Selenium page | FAIL |
    No keyword with name ‘Click Selenium Link’ found.
    ——————————————————————————
    myFirstTest :: this is your first Test | FAIL |
    2 critical tests, 0 passed, 2 failed
    2 tests total, 0 passed, 2 failed
    ==============================================================================
    Output: C:\Robot Examples\TestRobo\output.xml
    Log: C:\Robot Examples\TestRobo\log.html
    Report: C:\Robot Examples\TestRobo\report.html

  23. Karri on said:

    Excellent post. I was checking constantly this blog and I’m impressed! Extremely useful info particularly the last part :) I care for such information much. I was seeking this particular information for a long time. Thank you and good luck.

  24. Tarnnum on said:

    Hi All,

    I am executing test script using robot framework. Browser has been launched but url is not passed. I got following error. Please suggest

    command: pybot.bat –argumentfile c:\users\tarnnu~1.ban\appdata\local\temp\RIDEufqggb.d\argfile.txt –listener C:\Python27\Lib\site-packages\robotide\contrib\testrunner\SocketListener.py:61876 C:\Python27\Scripts\tuto
    unable to open socket to “localhost:61876″ error: [Errno 10061] No connection could be made because the target machine actively refused it
    ======================================================================================================================================================================
    Tuto
    ======================================================================================================================================================================
    Tuto.myFirstTest :: This is your first test
    ======================================================================================================================================================================
    process 5560 killed

  25. Savino on said:

    Hi,
    I found your tutorial really great. But I have a question about a TC that I’m doing.
    I have a TC and after clicking an url link I wanna have the following step

    Title Should Be Blablabla….
    Location Should Be http://www.url.com/${random number}

    how can I said to RF/Selenium that have to accept an url like that with a number instead of ${random number}

    Thanks,
    Savino

  26. Edmundo on said:

    That is really attention-grabbing, You are an excessively skilled blogger.
    I’ve joined your feed and sit up for searching for extra of your fantastic post. Additionally, I’ve shared your website in my social networks!

  27. great ad on said:

    Hellο і am kaνin, its my first οccaѕion to commentіng аnуwheгe, when
    i rеаԁ this pοst i thought і cоuld also creatе
    cοmment due to this brilliant parаgгaph.

  28. fresno website design on said:

    I wanted to thank you for this good read!! I definitely loved every little bit
    of it. I’ve got you book marked to look at new stuff you post…

  29. It’s hard to find well-informed people in this particular topic, however, you sound like you know what you’re talking about!

    Thanks

  30. Free Proxy site on said:

    Nice post. I learn something totally new and challenging on sites I stumbleupon on
    a daily basis. It’s always helpful to read content from other authors and use something from their websites.

  31. olly on said:

    is there a method of working out what version of selenium library you are using via the command line? I have an issue where some of the Keywords are not recognised and are making my tests fail. thanks

    http://robotframework-seleniumlibrary.googlecode.com/hg/doc/SeleniumLibrary.html?r=2.7#Capture%20Screenshot

  32. Helaine on said:

    Hmm it looks like your blog ate my first comment (it was extremely long) so
    I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog.

    I as well am an aspiring blog writer but I’m still new to everything. Do you have any points for inexperienced blog writers? I’d certainly appreciate it.

  33. ucas personal statement on said:

    I’ve learn some good stuff here. Certainly value bookmarking for revisiting. I surprise how so much effort you place to make the sort of great informative site.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>