Introduction
As Selenium automation frameworks grow, maintaining a consistent naming style becomes essential. A project may contain hundreds of test files, page classes, utility classes, variables, constants, and test methods. If these components are named inconsistently, the framework becomes difficult to understand and maintain.
Naming Conventions are a set of rules that define how variables, functions, classes, constants, files, and packages should be named. Following consistent naming conventions makes automation code easier to read, improves collaboration among team members, and helps maintain a professional framework.
Python follows the PEP 8 style guide, which recommends specific naming conventions for different program elements. Most Selenium automation frameworks built with Python also follow these conventions.
In this tutorial, you’ll learn the recommended naming conventions for Selenium automation projects using Python.
What are Naming Conventions?
Naming Conventions are standardized rules for naming different components of a program.
They ensure that code is:
Easy to read.
Easy to understand.
Consistent throughout the project.
Easy to maintain.
Professional and well-organized.
Following naming conventions allows every team member to understand the purpose of a variable, method, class, or file without additional explanation.
Why Use Naming Conventions?
Naming conventions provide several benefits:
Improve code readability.
Make code self-explanatory.
Reduce confusion.
Simplify maintenance.
Improve collaboration among team members.
Help new developers understand the framework quickly.
Produce clean and professional automation code.
Naming Conventions Used in Selenium Frameworks
The following naming conventions are commonly followed in Selenium projects:
| Item | Convention | Example |
|---|---|---|
| Test file | test_*.py | test_02_naming_conventions.py |
| Test function | test_* | test_naming_conventions_select_checkbox() |
| Locator constant | UPPER_SNAKE_CASE | AGE_CHECKBOX |
| Variable | lower_snake_case | age_checkbox |
| Page class | PascalCase | SimpleFormPage |
These conventions follow Python’s PEP 8 guidelines and are widely used in professional automation frameworks.
Test File Naming
Every PyTest test file should begin with test_.
Good Examples
test_login.py
test_checkout.py
test_search.py
test_02_naming_conventions.py
Poor Examples
login_test.py
Login.py
automation.py
PyTest automatically discovers files whose names start with test_.
Test Function Naming
Every test function should also begin with test_.
Good Examples
def test_valid_login():
pass
def test_add_product():
pass
def test_naming_conventions_select_checkbox():
pass
Poor Examples
def login():
pass
def testcase():
pass
def abc():
pass
Descriptive test names make reports easier to understand.
Locator Constant Naming
Reusable locators should be stored as constants using UPPER_SNAKE_CASE.
Good Example
AGE_CHECKBOX = (By.ID, "isAgeSelected")
LOGIN_BUTTON = (By.ID, "login")
Poor Example
ageCheckbox = (By.ID, "isAgeSelected")
loginButton = (By.ID, "login")
Uppercase names indicate that locator values should remain constant.
Variable Naming
Variables should use lower_snake_case.
Good Examples
age_checkbox = driver.find_element(By.ID, "isAgeSelected")
displayed_message = "Hello"
login_button = driver.find_element(By.ID, "login")
Poor Examples
a = driver.find_element(...)
temp = "Hello"
loginButton = driver.find_element(...)
Meaningful variable names make the code easier to understand.
Page Class Naming
Page Object classes should use PascalCase.
Good Examples
class LoginPage:
pass
class HomePage:
pass
class SimpleFormPage:
pass
Poor Examples
class loginpage:
pass
class simple_form_page:
pass
class homepage:
pass
Class names should describe the page or object they represent.
Additional Python Naming Guidelines
Python projects generally follow these conventions:
| Component | Naming Style | Example |
|---|---|---|
| Variable | lower_snake_case | user_name |
| Function | lower_snake_case | click_login_button() |
| Method | lower_snake_case | enter_username() |
| Class | PascalCase | DriverFactory |
| Constant | UPPER_SNAKE_CASE | BASE_URL |
| Module/File | lower_snake_case.py | driver_factory.py |
| Package | Lowercase | utilities |
Practical Example
Suppose a Selenium automation framework contains hundreds of test cases.
If every engineer follows the same naming conventions for test files, methods, classes, variables, and locators, new team members can quickly understand the project structure. Test reports become more meaningful, and maintaining the framework becomes much easier.
Automation Testing Example
Consider an online banking application.
The automation framework uses descriptive names such as LoginPage, ACCOUNT_NUMBER_FIELD, enter_password(), and test_fund_transfer(). These names clearly indicate the purpose of each component, making the framework easier to maintain and extend.
Real-World Example
Naming conventions are followed in:
Banking applications
Healthcare systems
E-commerce platforms
CRM applications
ERP systems
Government portals
SaaS products
Enterprise Selenium automation frameworks
Advantages of Naming Conventions
Improves code readability.
Makes code self-explanatory.
Simplifies maintenance.
Reduces confusion.
Improves collaboration.
Produces professional-quality automation frameworks.
Makes test reports easier to understand.
Common Mistakes Beginners Make
Not Using test_ Prefix
PyTest may not discover test files or test functions that do not start with test_.
Using Poor Variable Names
Avoid names like:
a
x
temp
Use descriptive names such as displayed_message or login_button.
Mixing Naming Styles
Avoid mixing camelCase, snake_case, and PascalCase randomly.
Follow the appropriate naming style for each component.
Using Generic Class Names
Avoid names such as:
class Page:
pass
class Test:
pass
Choose names that describe the page or functionality.
Best Practices
Follow Python’s PEP 8 naming conventions.
Name test files using the
test_*.pyformat.Name test methods using the
test_*prefix.Store locators as
UPPER_SNAKE_CASEconstants.Use
lower_snake_casefor variables, functions, and methods.Use
PascalCasefor Page Object classes.Keep names meaningful, descriptive, and consistent throughout the project.
Conclusion
Naming Conventions play an important role in creating clean, readable, and maintainable Selenium automation frameworks. By following Python’s PEP 8 guidelines and using consistent naming styles for files, test methods, variables, locators, and page classes, automation engineers can build professional frameworks that are easy to understand, maintain, and scale.
Frequently Asked Questions (FAQs)
What are Naming Conventions?
Naming Conventions are standardized rules that define how variables, methods, classes, constants, and files should be named.
Why should PyTest test files start with test_?
PyTest automatically discovers files whose names begin with test_, making test execution seamless.
How should locator constants be named?
Locator constants should use UPPER_SNAKE_CASE, for example, LOGIN_BUTTON or AGE_CHECKBOX.
Which naming style should Page Object classes follow?
Page Object classes should use PascalCase, such as LoginPage or SimpleFormPage.
Which naming style should variables and methods follow?
Variables, functions, and methods should use lower_snake_case, following Python’s PEP 8 recommendations.
Key Takeaways
Naming Conventionsimprove readability, consistency, and maintainability.Name test files using the
test_*.pyconvention.Name test methods using the
test_*prefix.Store locators as
UPPER_SNAKE_CASEconstants.Use
lower_snake_casefor variables and methods.Use
PascalCasefor Page Object classes.Following consistent naming conventions helps create professional Selenium automation frameworks.
