Automation Challenges and Solutions – Robot Framework
Technical Feed
Royalyn Gifty April 5, 2018

Automation Challenges and Solutions - 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 a keyword-driven approach, is built on Python and supports Java (Jython) as well as .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.

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 that is sent or received in the emails.

Robot framework provides us an easy way of executing this; all we need is the IMAPLibrary. IMAPLibrary accesses emails from the mailbox, read 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

Documentation:https://rickypc.github.io/robotframework-imaplibrary/doc/ImapLibrary.html

Prerequisite: Enable IMAP in corresponding google account

Email Assertions

Email Assertions

Note: This doesn’t involve sending emails through the 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 asserted it after specific actions. For some web elements, the style attribute and background color are visible in the tag level while for a few others, the background color is not available at the tag level. Let us check how can we handle both the situations in the 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:  http://robotframework.org/robotframework/latest/libraries/OperatingSystem.html

Set Home Environment

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 the 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 the 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 it 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 pure content, we wrote a library and used it in our script.

Create Your Own Library

Creating Libraries

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

Creating Own Libraries

We can write a library and use it

Library  mailcontent.py   #mailcontent.py is nothing but the file name Mailcontent.py

Mailcontent.py

Automation technologies are developing at a breathtaking pace, and business leaders are faced with prioritizing test automation services for the fast and easy deployment of their software or products. By implementing unique software testing technique strategies, ThinkPalm helps in increasing the workflow and also satisfying the requirements of the client by providing them with the best services.

 


Get A Free Consultation On Our Test Automation Services



Get A Free Consultation On Our Test Automation Services