This document is a step-by-step guide to running your basic test in the robot framework. Here, I have discussed and executed my tests in IntelliJ IDE using python. You can use any IDE of your choice such as PyCharm, Eclipse, or Ride.
Installation
1. For the installation of the robot framework the first prerequisite is the installation of python on your system. You can install python using the link provided here: python.
After the installation of the python is complete make sure that the python executable is set in the environmental variable path in order to execute python commands in your windows system.
2. In order to check whether your python has been installed properly you can check the python version using the following command in the command prompt:
python --version
3. After the installation of python next step is to install the robot framework using following command:
pip install robotframework.
4. To verify the proper installation of the robot framework you can check with following command:
robot -–version.
5. After the successful installation of python and robot framework next step includes installation of poetry using following command:
pip install poetry.
Poetry is a python dependency management tool to manage dependencies, packages, and libraries in the python project. It will help to make the project simpler by resolving dependency complexities in the project and managing to install and update for you.
6. After the installation of the poetryyou can verify poetry version with the help of following command:
poetry --version
7. After meeting the basic requirements for implementing a robot framework in python next step would be to configure your IDE in order to execute tests in python. You can create your project in any IDE of your linking, here I have created my project in IntelliJ
8. The next step would be an addition of plugin-ins for python as well as robot-framework in IntelliJ:
Go to File --> Settings --> plugins and add the following plugins:
a. Python Community Edition.
b. Hyper RobotFramework Support.
9. Next step involves the creation of a new python project in IntelliJ. You can create a new python project with the help of the following steps:
File -> New --> Project --> Specify the name of the project, language, Environment, and environment type --> create.
10. PROJECT STRUCTURE:
In a robot framework, a typical project has the following file structure:
· Library Folder – library contains custom keyword libraries.
· Resources Folder – contains the reusable Robot code files.
· Results Folder – contains the results of the executed tests.
· Tests Folder – contains the tests you have to execute in the files with .robot OR .txt extension.
Folder and file names are case-insensitive. The best practice is to give descriptive names to the Folder and file. The names should not be too long and use hyphens to separate words in the file name.
11. TEST SCRIPTS IN ROBOT FRAMEWORK:
Robot Framework test scripts are text files with the *.robot or *.txt extensions. There are basically four sections in robot test script: setting, variables, keywords, and test cases.
Settings: The settings section contains the import statements for the external libraries, resources, and the setup and teardown commands. You can import your Libraries in the robot file using keyword Library followed by double space and name of the library
eg. Library RequestsLibrary
NOTE: Before importing the libraries for your test execution, the first step is to install the libraries you are going to use to execute your tests for example here I am using Requests Library. I have used following command for installing requests library:
pip install requests
Variables: The variables section contains keyword arguments, and global, and local values. Variables make it easy to change the test data in one location.
Variable declaration syntax includes $ followed by {variable_name} double space then variable value
eg. ${base_url} https://anywebsite.com/.
Keywords: The keywords section contains operations used to execute the tests. They correspond to methods in java. The different types of keywords are:
a. built-in keywords
b. library keywords
c. user-defined keywords.
Built-in and library keywords are lower-level keywords defined by the built-in Robot Framework library or an external library such as Selenium. User-defined keywords are keywords created by combining library keywords.
Test Cases: The test cases section contains the test cases. There are two common approaches to writing test cases.
a. keyword-driven
b. Gherkin.
a. Keyword-driven Approach: The keyword-driven approach uses the Robot Framework built-in keywords and keywords from an external library like Selenium.
b.Gherkin: Follows the BDD approach where test cases are defined by keywords Given, when and then.
Defining test case: For defining the test case first create session followed by session_name followed by variable_name, Test_code(action), and write code for specified output.
12. TEST EXECUTION AND RESPONSE VALIDATION:
Running Tests: In robot framework tests are run through the terminal with the following command:
robot name_of_the_robot_file.robot
You can validate your response by logging the status code, response content, headers etc.
13. REPORTING IN ROBOT FRAMEWORK:
Reports and logs are created automatically in robot framework but you can use Rebot for creating the same reports and logs. Using rebot commands can come in handy when you want to have one report with all test cases and another with only some subset of tests.
Examples of rebot commands are:
For generation of the report with all the test cases you can use:
rebot path/to/output_file.xml
For generation of reports with specific group of test cases you can use:
rebot –include group_name (e.g. smoke) --name Smoke_Tests c:\results\output.xml
after the test execution reports will be displayed as follows
CHALLENGES & ERRORS FACED:
1. To find the poetry executable path: Go to the directory where python is installed à scripts à poetry.exe
2. Get Request command has been deprecated and updated to "Get on session" instead.
3. Robot framework is space sensitive and requires two spaces between command and declaration eg. Library (two spaces) Collections, Log to console (two spaces) response.status_code.
4. Error: Keyword definition not found.
Check for missing tabs and spaces
eg.
Under *** Test Cases ***
Test_name
(Tab/ space) create session followed by executable commands.