- June 23, 2020
- Posted by: Bhanu Pratap Singh
- Category: Blogs
What Exactly is a Test Automation Framework?
Below are the characters and components of a good automation framework:
- The first thing to consider is a language like Python, Java, etc. that we can use to write our tests. It gives us the ability to create scripts.
- The reusable page or entity objects.
- Supporting libraries that give us the ability to test web or API or database or mobile applications.
- An abstraction layer that gives us the ability to write test cases in a natural language so that it can also be understood by business analysts.
- A test runner that has selective test running capabilities like the ability to tag our test cases and run them by tags.
- Test suites or test setup and teardown mechanism which gives us the ability to clean up and also not repeat setup and teardown script.
- A very important part of it is well-structured reports that have results summary with aggregation, timestamps, the ability to drill down into the test case to see what was executed, the ability to search our results and automatically embedded screenshots if there is a failure.
- The ability to schedule our tests daily or weekly or monthly.
- The ability to integrate with a continuous integration system so that the tests can be run automatically after the build and deployment on a server.
- The support for parallel execution so we can run tests on different computers at the same time to save time.
- Finally, we want to have some sense of convention to bring consistency to the Team.
Why Robot Framework
The simple answer to the ‘Why’ is that Robot Framework does all of these things right out of the box so that we do not require to build test automation frameworks from scratch. What’s even better is that it’s open-source and free. Also, it can be installed, up and running and ready to use all these features in no time and with minimal effort. And it’s the fastest and easiest to learn test automation framework.
Test Automation Framework architecture
An Overview of Robot Framework Libraries
Robot Framework Libraries
Robot Framework scripts are mostly keyword-driven i.e we can type in some simple, plain English words to invoke pre-written logic in some pre-existing libraries that have been made available to us. This gives us the ability to create our scripts in a Natural Language, essentially Business Domain vernacular, and the result is simpler, more readable test scripts. The above diagram makes it easier to visualize this. Inside of our chosen IDE, we will create a script file, which is simply a text file with a dot robot extension and those script files will reference workflow files which are lower-level keywords, also text .robot files and those workflows themselves would be making calls to the various libraries. So, we can see the libraries we have access to include Built-In libraries that come with Robot Framework itself and also external libraries that can be installed by using pip3 install and then the name of the library.
Installation Steps on Mac
- Install Python and PIP (add to your Path)
- Use PIP to Install Robot Framework
- Use PIP to install Selenium Library
- Select and install desired browser Versions
- Install Selenium WebDriver for each browser
- Install the PyCharm IDE and Intellibot Plugin
- Create the base directory for the script
Step 1: Install Python and PIP (add to your Path)
$ brew install python
Homebrew installs pip pointing to the Homebrew’s Python 3 for us
Step 2: Use PIP to Install Robot Framework
$ pip3 install robotframework
Step 3: Use PIP to install Selenium Library
$ pip3 install robot framework-selenium library
Step 4: Install Selenium WebDriver for each browser
E,g Install chrome web driver for chrome
$ brew cask install chromedriver
Step 5: Install the PyCharm IDE and Intellibot Plugin
- Open Pycharm and Pycharm > Preferences
- Select Plugin and search and install IntelliBot @SeleniumLibrary Patched
IntelliBot @SeleniumLibrary Patched
Step 6: Organizing Project files
We can organize our project files by using a layered script approach. As represented in the above figure the script file contains test cases, the keywords files contain lower level keywords that are created to help the script do its work, and the page object files are a way to encapsulate locators and functionality to represent different pages in the system under test. So the script falls under a test directory, the keywords and page objects together fall under resources, If we happen to get into creating our own libraries using Python we could also consider creating a libraries directory to hold those. If instead, we had multiple products and tests we could consider an approach, where inside our test directory we have got a product one directory which might hold feature one and feature two and so on, which would be shorter scripts for specific areas of our product. And of course, this assumes there would be a product two directory and a product three directory and so on. And then inside the resources directory would have a product one directory and a product two directory and inside those directories, those would hold our corresponding keyword files for feature one, feature two, and so on. And of course a single page objects directory for each product, the reason why we might take this approach is so that we could use one common keywords file for all of the different products, so maybe for things like suite setup and suite teardown, which includes things like opening up the browser, closing browsers and such, if we don’t want to have to repeat those keywords for multiple products, we could have this one common keywords file that serves each of our multiple products. And in results, we would have a product one directory and a product two directory that would hold the results for those products respectively.
To summarize, Robot Framework is a feature-rich framework that can assist us in design and development of mature end to end test automation solutions with ease. As the scripts are keywords based hence its readable and it becomes easy for different stakeholders to collaborate in the products quality engineering.
A quick view of the robot framework features:
- Simple Tabular Syntax
- Built-In keywords from the Selenium Library (open browser, close browser, maximize browser, etc.) and also a user-defined keyword.
- Supports a lot of external libraries like SeleniumLibrary, Database Library, FTP Library and Http library.
- Possible to write test cases that work as cross-platform.
- Data-driven Test Cases
- Separate Test Data Editor
- Clear Reports
- Detailed logs
- Generic test libraries
- Support for parallel execution of test scripts
- Text editor support: Eclipse, Emacs, Vim, Visual studio code
- It can be containerized and integrated with a CI tool like Jenkins
Author: Bhanu Pratap Singh