Understanding the structure of a Robot Framework test file is essential for building maintainable, scalable, and readable automation suites. Robot Framework organizes test data into clearly defined sections, each serving a specific purpose in the test execution lifecycle. In this article, we will break down the four core sections of a Robot Framework test file:
- Settings
- Variables
- Test Cases
- Keywords
Overview of Robot Framework Test File Structure
A Robot Framework test file (usually with .robot extension) is structured in a tabular format. Each section is defined using a header with triple asterisks:
*** Settings ****** Variables ****** Test Cases ****** Keywords ***
Each section plays a distinct role in defining test behavior, data, and reusable logic.
1. Settings Section
The Settings section is used to configure the test suite. It defines dependencies, libraries, resources, and setup/teardown operations.
Common uses of Settings:
- Importing libraries
- Including resource files
- Defining setup and teardown actions
- Setting documentation for test suites
Example:
*** Settings ***Library SeleniumLibraryResource keywords.resourceSuite Setup Open Browser To Login PageSuite Teardown Close All BrowsersDocumentation This suite tests login functionality
Key Components:
- Library → Imports external automation libraries
- Resource → Imports reusable keywords from external files
- Suite Setup/Teardown → Executes once before/after test suite
- Test Setup/Teardown → Executes before/after each test case
2. Variables Section
The Variables section is used to define reusable data values. This helps avoid duplication and improves maintainability.
Variables can be:
- Scalars (
${variable}) - Lists (
@{list}) - Dictionaries (
&{dict})
Example:
*** Variables ***${URL} https://example.com${BROWSER} chrome${USERNAME} testuser${PASSWORD} secret123@{COLORS} red green blue&{USER} name=John role=admin
Benefits:
- Improves readability
- Centralizes test data
- Makes test updates easier
- Supports data-driven testing
3. Test Cases Section
The Test Cases section is the core of a Robot Framework file. It contains the actual test scenarios executed by the framework.
Each test case consists of steps written using keywords.
Example:
*** Test Cases ***Valid Login Test Open Browser ${URL} ${BROWSER} Input Text id=username ${USERNAME} Input Text id=password ${PASSWORD} Click Button id=login Page Should Contain Dashboard Close Browser
Key Characteristics:
- Each test case has a descriptive name
- Steps are written using keywords
- Execution is sequential
- Can include validations and assertions
Best Practices:
- Keep test cases independent
- Use meaningful names
- Avoid hardcoding values
- Reuse keywords instead of duplicating steps
4. Keywords Section
The Keywords section allows you to create reusable custom keywords. This is one of the most powerful features of Robot Framework.
Instead of repeating steps in multiple test cases, you define them once as a keyword.
Example:
*** Keywords ***Open Login Page Open Browser ${URL} ${BROWSER} Maximize Browser WindowLogin With Valid Credentials Input Text id=username ${USERNAME} Input Text id=password ${PASSWORD} Click Button id=login
Why Keywords Matter:
- Promotes reusability
- Reduces duplication
- Improves readability
- Simplifies maintenance
Built-in vs Custom Keywords:
- Built-in keywords: Provided by libraries like SeleniumLibrary
- Custom keywords: Defined in the Keywords section
Relationship Between Sections
Each section works together to form a complete test structure:
- Settings → Configures environment and dependencies
- Variables → Stores reusable test data
- Test Cases → Defines test execution flow
- Keywords → Encapsulates reusable logic
This separation ensures modularity and maintainability.
Best Practices for Structuring Robot Framework Test Files
To maintain clean and scalable automation suites:
- Keep each test file focused on a single feature
- Avoid duplication using Keywords
- Centralize test data in Variables or external files
- Use clear naming conventions
- Keep Test Cases readable and business-focused
- Separate complex logic into reusable keywords
Conclusion
Robot Framework test file sections provide a structured and logical way to design automated test cases. By understanding and correctly using Settings, Variables, Test Cases, and Keywords, you can build scalable, maintainable, and efficient automation frameworks.
Mastering these sections is a fundamental step toward becoming proficient in Robot Framework automation testing.
Related Articles
✓ Complete Robot Framework Tutorial
✓ Robot Framework Architecture Explained
✓ Installing Robot Framework Browser Library
✓ Browser Library vs SeleniumLibrary
✓ Writing Your First Robot Test
Discover more from Rotebit
Subscribe to get the latest posts sent to your email.

