This repository contains the test framework for the Domain Monitoring System, including Selenium-based functional tests and Locust performance tests.
The test suite verifies functionality across several key areas:
- User authentication (registration, login, logout)
- Domain management (adding, deleting, refreshing domains)
- Scheduler functionality (hourly/daily checks)
- Load testing using Locust
domain-monitoring-tests/
├── conftest.py # Test configuration and logging setup
├── test_base.py # Base test class with common functionality
├── test_auth.py # Authentication tests
├── test_domains.py # Domain management tests
├── test_scheduler.py # Scheduler tests
├── locustfile.py # Performance/load testing with Locust
├── run_tests.py # Test runner script
├── requirements.txt # Python dependencies
└── README.md # This readme file
Tests user registration, login, and logout functionality:
test_registration_success
: Verifies new user registrationtest_login_success
: Tests login with valid credentialstest_logout
: Confirms logout functionality
Tests domain monitoring functionality:
test_add_domain
: Adds single domainstest_delete_domain
: Removes domainstest_refresh_domains
: Tests domain status refreshtest_file_upload
: Tests bulk domain addition via file upload
Tests scheduling functionality:
test_hourly_schedule
: Sets up hourly domain checkstest_daily_schedule
: Sets up daily domain checkstest_stop_schedule
: Tests stopping scheduled checks
Load testing using Locust:
- Tests API performance under load
- Monitors for performance degradation
- Simulates multiple concurrent users
- Python 3.8 or higher
- Chrome browser and ChromeDriver
- Access to the Domain Monitoring System application
-
Clone the repository:
git clone <repository-url> cd domain-monitoring-tests
-
Install dependencies:
pip install -r requirements.txt
-
Configure the environment:
# Set the application URL (default: http://host.docker.internal:8080) export APP_URL=http://localhost:8080
Execute the test runner script:
python run_tests.py
This will run the core test suite defined in run_tests.py
.
To run only authentication tests:
python -m unittest test_auth.py
To run only domain management tests:
python -m unittest test_domains.py
To run only scheduler tests:
python -m unittest test_scheduler.py
To run a specific test method:
python -m unittest test_auth.AuthenticationTests.test_login_success
To run the Locust performance tests:
locust -f locustfile.py --host=http://localhost:8080
Then open http://localhost:8089 in your browser to access the Locust web interface.
The BaseTest
class in test_base.py
provides common functionality:
- Browser setup and teardown
- Helper methods for finding elements
- Alert handling
- Test user creation
The test suite uses a configured logger (conftest.py
) that:
- Logs to both console and file
- Creates daily log files in the
test_logs
directory - Records different log levels for debugging
The tests are designed to run in both local and Docker environments:
- Chrome is configured to run in headless mode
- Tests can target a Docker container via
host.docker.internal
- Configurable timeouts accommodate container networking
- Create a new test file or add to an existing one
- Inherit from
BaseTest
for common functionality - Use the logger for debugging and tracking
- Follow the existing pattern for element interaction:
def test_new_functionality(self): logging.info("Starting new test") element = self.wait_for_element(By.ID, "element-id") element.click() # ... more test steps ... self.assertIn("Expected Result", result.text)
Each test should:
- Log the start of the test
- Perform setup operations if needed
- Execute the test steps
- Verify the results with assertions
- Log the test outcome
-
Element not found exceptions:
- Increase the timeout in
wait_for_element()
- Check if the element ID or selector has changed
- Verify the page is fully loaded before searching
- Increase the timeout in
-
Test timing issues:
- Add explicit waits for dynamic elements
- Use
WebDriverWait
for elements that take time to appear - Add small
time.sleep()
delays when necessary
-
Browser or WebDriver issues:
- Update ChromeDriver to match your Chrome version
- Try running with
--headless=new
instead of just--headless
- Check Chrome's sandbox settings
-
Use the logging system:
logging.debug("Detailed debug information") logging.info("General test progress") logging.error("Test failures or errors")
-
Review the log files in
test_logs/test_YYYYMMDD.log
-
Add screenshots for failures:
def take_screenshot(self, name): self.driver.save_screenshot(f"screenshots/{name}.png")
The test suite is designed to integrate with CI/CD pipelines:
- The tests run automatically during the CI/CD pipeline
- Exit code 0 indicates success, non-zero indicates failure
- Log files are generated for troubleshooting
Example Jenkins pipeline integration:
stage('Functional Tests') {
agent {
docker {
image 'python:3.9-slim'
args '--network host'
}
}
steps {
sh '''
pip install -r requirements.txt
python run_tests.py
'''
}
post {
always {
archiveArtifacts artifacts: 'test_logs/*.log', allowEmptyArchive: true
}
}
}