Author : Royalyn Gifty

Published on: April 5, 2018

Category : Technical Feed

Automation Testing – Robot Framework

Automation has gained significant importance in present times with the rise in demand for agile and DevOps. For continuous integration and delivery, we require tests that run quickly and reliably. On the other hand, this demand is making test automation complicated and challenging.

Robot Framework is an open source and platform independent framework, used for test automation and Acceptance Test Driven Development(ATDD). It uses keyword driven approach, is built on Python and supports Java (Jython) and .NET (Iron Python). The framework consists of standard test libraries and a wide range of external libraries. CI tool support for Maven, Jenkins, Ant etc. are also available.

Automation Challenges and Solutions - Robot Framework

In this article we will check out some common challenges faced in automation testing and how we can sort them out using robot framework.

Challenges and Solutions

Below are some common challenges faced during automation, for which we found simple solutions using robot framework:

  1. Email Assertions
  2. Asserting with background colors
  3. File handling
  4. Using our own libraries
 1. Email Assertions

At times, depending on the requirement, we might need to automate the test cases where we need to validate the email content sent/received in the emails.

Robot framework provides an easy way of executing this; all we need is the IMAPLibrary. IMAPLibrary accesses emails from the mail box, reads emails, fetches the links or contents of the email and asserts it. There are three steps involved:

  1. Install IMAP library
  2. Allow IMAP access from the email account
  3. Write script for reading emails

Installation:  Pip install robotframework-imaplibrary


Prerequisite: Enable IMAP in corresponding google account

Email Assertions

Email Assertions

Note: This doesn’t involve sending emails through script, for which we will need to use SMTP Library.

2. Asserting Background Colors

At times, as a part of GUI testing, we need to visually check if the color has changed and assert it after specific actions. For some web elements, the style attribute and background color are visible in tag level while for few others, the background color is not available in the tag level. Let us check how can we handle both the situations in robot framework.

Background color available in Tag:

Asserting Background Colors - Bg color available in tag

Tag Details:

<span_ngcontent-c41=””style=”background-color:rgb(183, 2, 0);”>&nbsp;Critical&nbsp;&nbsp;&nbsp;</span>

In the above code, we can see that the color details are available in tag level. Hence, we need to extract the attribute value and assert the same.

Asserting Background Colour - bg colour available in tag

Background color not available in Tag:

Asserting Background Colours - Bg colour not available in tag

Tag Details:

<div class=”slider round”></div>

In the above case, the tag doesn’t contain much information about style or background color since style details are defined under class “slider round” using CSS.

Let us check out how to obtain the color value and assert using robot framework.

Asserting Backgroung Colour - bg colour not available in tag

3. File Handling

As our application under test involves features such as upload and download files, it becomes necessary to use file handling. Also, the data driven scripts need to read values from external files.

Robot framework provides a set of keywords for file handling in the operating system library. Let us learn how to handle upload and download of files and assert the same.

It is a two step process. Since operating system is a built-in library, we need not perform a pip install.

  1. Set the home environment in the machine on which you are executing the script
  2. Write script for file handlingDocumentation:

Set Home Enviromment

MyComputer -> Right Click select Properties -> Select Advance System Settings -> Select Enviroment Variables -> Add home environment.

File Handling

We can also use the absolute path, but our scripts will look good if we can have the same as system variable. Also, it will be easier to execute the same scripts in Linux/Windows/Mac environments.

Sample Code:

Download and Assert

Give Name And Export
Input Text    ${EXPORT_NAME}    AutomationExportTesting
Click Element    ${EXPORT_FILE}

Assert Alert Count – Import and Assert

Assert Alert Count - Import and Assert

In operating system library, we have a good collection of keywords for file handling which can be used in automating our specific scenarios or test cases.

4. Creating your own library

Apart from the available libraries and keywords, you can create your own library and use in your scripts.  For this, you need to know Python, especially to write functions and return the results.

During an email validation, I used the keyword Get Mail Body which returned the mail body contents as html tags. To get the pure content, we wrote a library and used it in our script.

Create Your Own Library

Creating Libraries

After processing the mail body through cleanhtml function, below is the result:

Creating Own Libraries

We can write a library and use it

Library is nothing but the file name

Hope the above will help you in solving automation challenges, will come up with more stuff in future.