Robot framework selenium Library: Open Browser example

In this article we will see how to setup Browser automation using Robot framework selenium Library. This article is more of an intro to handle browser automation, more examples of browser automation can be found here

Step 1: Install RIDE and Robot framework

We need to install Robot framework and its IDE (RIDE) on the machine which we are working on . For this article im using a windows 10 machine where I have already installed the RIDE and RF. You can refer article  "Robot framework IDE aka RIDE installation on Windows 10 in 6 steps"

Step 2: Install Selenium Library

Robot framework offers multiple libraries for various use cases, one of those library is the selenium library which is used for web testing.
Official documentation can be found on official webpage and github

Install selenium library using the below command

pip install --upgrade robotframework-seleniumlibrary

Verify the library installation using below command in the snippet

C:\Users\****t>pip3 show robotframework-seleniumlibrary
Name: robotframework-seleniumlibrary
Version: 6.0.0
Summary: Web testing library for Robot Framework
Home-page: https://github.com/robotframework/SeleniumLibrary
Author: Tatu Aalto
Author-email: [email protected]
License: Apache License 2.0
Location: c:\users\****t\appdata\local\programs\python\python37\lib\site-packages
Requires: selenium, robotframework, robotframework-pythonlibcore

Step 3: Install Browser drivers

After installing Selenium library we still need to install browser drivers. For this article we will see how to use Google chrome

Install Google Chrome Driver

  • We need to install driver for chrome. You can visit the official website for more details.
  • For the scope of this article, by the time im writing this article, version 103.0.5060.53  is the latest stable release available
  • Chrome Driver 103.0.5060.53 can be downloaded from the repo  .

 

Chrome drivers

  • Download the version for windows, since we are using windows and extract the zip content and copy it to the python  Scripts folder

Copy pdriver to python path

Install other browser drivers (optional)

Step 4: Import Selenium library

  • Open RIDE and create a new project, for this article I'm naming it as Browser tests
  • Click on the project and click on the Library option from the right side of the screen

Create Test suite

  • Clicking Library opens another window , where you can enter the Library name "SeleniumLibrary"

import selenium library

  • Verify the imported Library in the settings of the test suite. It should the Library SeleniumLibrary  in black color, if it is seen in red color then there is typo error or the library is not imported

import library verification

Step 5: Test case for opening website

  • Openbrowser keyword can be used for opening browser and expects web url and browser name as argument
    • For this article im using chrome, if you are using anyother browser drivers, same need to be as the argument
  • Closebrowser keyword can be used for closing browser
  • Below test case will open linux data hub website using chrome browser
    • Open browser and open website
    • Sleep for 5sec
    • Close browser

Testcase run

Test case execution observation

  • It can be seen that the google browser got opened
  • The website was loaded in the browser tab
  • After 5 sec, the browser was closed

passed console                browser output

 

 

Search on LinuxDataHub

2 thoughts on “Robot framework selenium Library: Open Browser example”

  1. While executing the testcase with open browser key word my testcase fails with error code 444. Its launching the browser and closes it immediately.

    Reply
    • Can you pls paste the code snippet and error, browser opening and closing may be expected if the code is failing. Pls check whether the python and ride version is mutually compatable

      Reply

Leave a Comment