This is the Robot framework with POM model framework
To get started with the Robot Framework, follow these steps:
Robot Framework requires Python to be installed on your system. You can download Python from the official website.
Make sure to install Python 3.7 or later. You can verify the installation by running:
python --version
Once Python is installed, you need to install the Robot Framework and any necessary dependencies. Typically, you will use a requirements.txt file to manage dependencies.
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
robotframework-seleniumlibrary
robotframework
robotframework-requests
robotframework-jsonlibrary
If you are automating web applications using Selenium, you need to install WebDriver binaries. This can either be done manually or by using a library like WebDriverManager.
-
Manual installation: Download the WebDriver for the browser you plan to use (e.g., ChromeDriver for Chrome, GeckoDriver for Firefox) and place it in a folder accessible by the system's PATH.
-
Using WebDriverManager (Recommended): The WebDriverManager Python package automatically handles browser driver installations. You can install it via pip:
pip install webdriver-manager
Here are the primary tools used in the Robot Framework automation setup:
-
Robot Framework: The core automation framework that provides a simple, readable syntax for writing tests. It uses a keyword-driven approach, which makes it easy to write tests without writing complex code.
-
SeleniumLibrary: A Robot Framework library used for web automation. It is built on top of Selenium WebDriver and allows interaction with web pages using keywords like Open Browser, Click Element, Input Text, etc.
-
WebDriverManager: (Optional) A tool to manage browser drivers like ChromeDriver and GeckoDriver automatically, without needing to manually download and update the drivers.
-
Other Robot Libraries: Depending on your testing requirements, you may also use libraries like RequestsLibrary (for API testing), DatabaseLibrary (for database testing), or OperatingSystemLibrary (for file system operations).
The Page Object Model (POM) is a design pattern that is used to enhance the maintainability and reusability of test scripts in an automation framework. In this pattern, each web page is represented by a class (or module in the case of Robot Framework), which contains all the methods (or keywords) that interact with elements on that page.
Separation of Concerns: The main advantage of POM is the separation of the test scripts (which describe the high-level flow of the tests) from the details of interacting with web elements (which is encapsulated in the page objects). This makes tests easier to maintain and scale.
-
Reusability: Once you define the page object for a page, you can reuse it across multiple test cases, reducing code duplication.
-
Maintainability: When a web page’s structure changes (e.g., element locators change), you only need to update the page object, not the individual test cases.
In Robot Framework, the Page Object Model can be implemented by creating separate Python files for each page. These files contain methods (or keywords) that perform actions on the elements of that page. The tests then interact with these methods instead of directly dealing with Selenium commands.
/project-root
│
├── /tests/ # Test cases
│ ├── login_test.robot # Test case for login functionality
│
├── /pages/ # Page Objects
│ ├── login_page.py # Page Object for login page
│
├── /resources/
| ├── commonkeywprds.resources # Common keyword
|
├── /testdata/ # test files
├── requirements.txt # Python dependencies
└── results/ # Test results
-
Page Object: A class (or Python module) representing a page or component in the web application. It encapsulates all interactions with the page.
-
Keywords: Methods within the page object that represent actions a user can take on that page, such as entering text, clicking a button, or verifying content.
-
Test Case: A separate Robot Framework test case file that uses the page objects to perform high-level actions (like testing the login functionality).
Once you’ve set up the environment and written the test cases, running the tests is simple:
- Run all tests:
robot tests/
This will execute all test cases in the tests/ folder.
- Run a specific test file:
robot tests/LoginTest.robot
- Run a specific test case from file:
robot --test 'Login With Valid Username and Valid Password Test' ./tests/LoginTest.robot
- Storing the logs into result folder:
robot -d ./results --test 'Login With Valid Username and Valid Password Test' ./tests/LoginTest.robot
1. Clone the repository :
git Clone https://github.com/shivdebugger/e2e_robot_framework
2. Installing the required libraries run the requirement.txt :
pip install -r requirements.txt
Once you're donw the installation run the below commands to execute test cases.
3. Commands for executing test cases:
- Run all tests:
robot tests/
This will execute all test cases in the tests/ folder.
- Run a specific test file:
robot tests/LoginTest.robot
- Run a specific test case from file:
robot --test 'Login With Valid Username and Valid Password Test' ./tests/LoginTest.robot
- Storing the logs into result folder:
robot -d ./results --test 'Login With Valid Username and Valid Password Test' ./tests/LoginTest.robot