Working With Browsers Using Selenium Library


Advertisements

In this chapter, we will learn how to work with browsers using Robot Framework and Selenium Library in ride.

  • Project setup in Ride
  • Import Selenium Library
  • Test case using Chrome Browser
  • Test case using Firefox Browser

Project Setup In Ride

We will first create a project in Ride to work with browsers. Open ride using ride.py from the command line.

Project Setup In Ride

Click on New Project and give name to your project.

give name your project

The name given is BrowserTestCases. Click OK to save the project. Right-click on the name of the project created and click on New Test Case

Browser Test Cases

Browser Test Cases Ex

Give name to the test case and click OK.

Give name

We are done with the project setup. Now, we will write test cases for the browser.

Import Selenium Library

To work with browsers, we need selenium library to be imported in robot. We can do that as follows −

Go to https://robotframework.org/

Import Selenium Library

On the left side, select the LIBRARIES option.

LIBRARIES option

Select External option from above and it will list you all the libraries available to be used.

External option

Click SeleniumLibrary.

You will be redirected to the github repo as shown below −

github repo

For Installation of seleniumlibrary, we can use the command from the github and install it using pip.

Command

pip install --upgrade robotframework-seleniumlibrary
selenium library

Selenium library gets installed inside the lib folder in python as follows −

library gets installed

Once the installation is done, we have to import the library in Ride as shown in the below steps.

Click on your project on the left side and use Library from Add Import −

Add Import

Upon clicking Library, a screen will appear wherein you need to enter the library name −

clicking Library

Click OK and the library will get displayed in the settings.

displayed settings

The name given has to match with the name of the folder installed in site-packages. In case the names do not match, the library name will be in red as shown below −

site packages

Library import in red is as good as the library does not exist inside python. Now, we have completed selenium library import.

Test Case Using Chrome Browser

To work with Chrome browser in Robot, we need to first install the drivers for chrome to work with Selenium. The drives are available on Selenium site − https://www.seleniumhq.org/.

Chrome Browser

Click Download Selenium as in the above screenshot.

In download section, go to Third Party Browser Drivers NOT DEVELOPED by seleniumhq and select Google Chrome driver as shown in highlighted section below

download section

Here we have a list of the various drivers available for browsers. For Chrome, click Google Chrome Driver and download the latest driver as per you operating system.

Chrome Driver

Click on the latest release. It will display the downloads as per the operating system – windows, linux and mac.

operating system

Download the version as per your operating system from the above list. It downloads the zip file. Once the file downloads, unzip it and copy the .exe driver file to python folder.

We are copying the file to C:\Python27\Scripts.

zip file

Now we are done installing the driver for chrome. We can get started with writing test case that will open browser and close browser.

Go back to ride and enter the keywords for opening the browser.

Ride helps you with keywords to be used with its built-in tool. Enter the command and press ctrl+spacebar. You will get all the details of the command as shown below

ctrl spacebar

It gives the details of the command and also examples on how to use it. In the test case, we will open the site https://www.howcodex.com/ in chrome and the test case details will be as follows −

ctrl spacebar Ex

Let us now run this test case to see the output −

run test case

run test case Ex

The test case has passed; we can see the site is opened in chrome browser.

We will add more test cases as follows −

test case passed
  • Open Browser − URL − https://www.howcodex.com/ in Chrome browser

  • Capture Page Screenshot − name of the image is page.png

  • Close browser

Here are the details of the report and log for above test cases executed.

Report

test cases executed

Log

test cases executed Log

Details of test cases from log

test cases log

test cases log Ex

test cases log Exs

Test Case Using Firefox Browser

Install the driver for Firefox and save it in python scripts folder.

Test case for Firefox

for Firefox

for Firefox Ex

Conclusion

We have seen how to install Selenium library and the browser drivers to work with browsers in Robot framework. Using the selenium library keywords, we can open any given link in the browsers and interact with it. The details of the test-case execution are available in the form of reports and logs, which give the time taken for execution.

Advertisements