Table of Contents
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.
Below are some common challenges faced during automation for which we found simple solutions using robot framework:
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:
Installation: Pip install robotframework-imaplibrary
Documentation:https://rickypc.github.io/robotframework-imaplibrary/doc/ImapLibrary.html
Prerequisite: Enable IMAP in corresponding google account
Note: This doesn’t involve sending emails through the script, for which we will need to use SMTP Library.
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:
Tag Details:
<span_ngcontent-c41=””style=”background-color:rgb(183, 2, 0);”> Critical </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.
Background color 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.
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.
Set Home Environment
MyComputer -> Right Click select Properties -> Select Advance System Settings -> Select Enviroment Variables -> Add home environment.
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
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.
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.
After processing the mail body through clean HTML function, below is the result:
We can write a library and use it
Library mailcontent.py #mailcontent.py is nothing but the file name 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.