Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sumanreddy568/selenium-python-pytest-framework

This repository houses a robust Selenium Python Pytest framework for efficient automated testing of web applications. Leveraging Selenium WebDriver and Pytest, it offers streamlined test case management, Docker support, and Jenkins integration for seamless continuous testing.
https://github.com/sumanreddy568/selenium-python-pytest-framework

containerization docker jenkins-pipeline pytest selenium-python test-automation

Last synced: about 1 month ago
JSON representation

This repository houses a robust Selenium Python Pytest framework for efficient automated testing of web applications. Leveraging Selenium WebDriver and Pytest, it offers streamlined test case management, Docker support, and Jenkins integration for seamless continuous testing.

Awesome Lists containing this project

README

        

Certainly! Here's the complete README.md file with the framework overview, project structure, usage instructions, Jenkins pipeline configuration, Docker containerization, and contribution guidelines:

```markdown
# Python Selenium pytest Framework

This is a Python Selenium pytest framework designed for automated testing of web applications. Frameworks provide a structured approach to software development, and in the context of testing, they offer a systematic way to organize, execute, and maintain tests.

## Framework Overview

The framework follows a modular architecture and utilizes several key components:

1. **pytest**: pytest is a popular testing framework for Python that provides a simple yet powerful way to write and execute tests. It offers features such as fixture management, parameterized testing, and test discovery.

2. **Selenium**: Selenium is a widely-used tool for automating web browsers. It allows testers to simulate user interactions with web applications, such as clicking buttons, filling out forms, and verifying page content.

3. **Page Object Model (POM)**: The framework employs the Page Object Model (POM) design pattern to enhance test maintainability and readability. POM separates the page elements and their interactions into individual classes, making it easier to manage changes in the UI.

4. **Configuration Management**: Test parameters and settings are stored in a separate configuration file (`config.ini`). This allows users to customize test behavior without modifying the test code.

5. **Reporting**: After test execution, detailed test reports are generated in HTML format (`reports/report.html`). These reports provide insights into test results, including passed tests, failed tests, and any errors encountered during execution.

## Benefits of the Framework

- **Modularity**: The framework's modular structure promotes code reusability and maintainability. Test scripts, page objects, and utility functions are organized into separate modules, making it easier to manage and update individual components.

- **Scalability**: The framework can scale to accommodate larger test suites and complex web applications. pytest's flexible test discovery mechanism allows tests to be organized and executed efficiently, even as the test suite grows.

- **Ease of Use**: With its intuitive syntax and powerful features, pytest simplifies the process of writing and executing tests. Test scripts are written in plain Python, making them easy to understand and maintain.

- **Integration**: The framework seamlessly integrates with other tools and technologies commonly used in the software development lifecycle. This includes continuous integration servers like Jenkins, version control systems like Git, and containerization platforms like Docker.

## Project Structure

├── config.ini # Configuration file for storing test parameters
├── Dockerfile # Docker configuration file
├── Jenkinsfile # Jenkins pipeline configuration
├── logs/ # Directory to store test logs
│ └── test_log.log # Example test log file
├── POM/ # Page Object Model directory
│ ├── __init__.py # Initialization file for POM package
│ ├── locators/ # Directory for storing web element locators
│ │ └── swag_labs_locators.py # Example locator file
│ ├── notifications/ # Directory for storing notification messages
│ │ └── swag_labs_messages.py # Example message file
│ └── pages/ # Directory for storing page objects
│ ├── base_page.py # Base page object class
│ ├── __init__.py # Initialization file for pages package
│ └── swag_labs_pages.py # Example page object file
├── pytest.ini # pytest configuration file
├── reports/ # Directory to store test reports
│ ├── assets/ # Directory for report assets (e.g., screenshots)
│ └── report.html # Example HTML test report
├── requirements.txt # File listing required Python packages
├── tests/ # Directory containing test scripts
│ ├── conftest.py # pytest configuration file for fixtures
│ ├── test_setup.py # Example test setup file
│ └── test_swag_labs.py # Example test script
└── utils/ # Directory containing utility modules
├── data/ # Directory for test data files
├── helper/ # Directory for helper modules
└── screenshots/ # Directory to store screenshots captured during tests
```

This section provides an organized view of the project's directory structure, with brief descriptions of each file and directory's purpose. It helps users understand how the project is organized and where to find specific components.

## Usage

1. **Setup Environment**: Ensure Python is installed. Create and activate a virtual environment:

```bash
python3 -m venv venv
source venv/bin/activate
```

2. **Install Dependencies**: Install required packages:

```bash
pip install -r requirements.txt
```

3. **Configuration**: Customize test parameters in `config.ini`.

4. **Writing Tests**: Create test scripts under `tests/`. Utilize Page Object Model (POM) for better organization.

5. **Running Tests**: Execute tests using pytest:

```bash
pytest
```

6. **Viewing Reports**: Open `reports/report.html` after test execution.

## Jenkins Pipeline Configuration

This framework includes a Jenkins pipeline configuration (`Jenkinsfile`) for continuous integration. The pipeline consists of stages for building, testing, and reporting. Jenkins fetches the code from the repository, builds the Docker image, runs tests inside a container, and generates reports.

```groovy
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'docker build -t my-test-image .'
}
}
stage('Test') {
steps {
sh 'docker run my-test-image pytest'
}
}
stage('Report') {
steps {
sh 'docker cp $(docker ps -q -n=1):/path/to/reports ./reports'
}
}
}
}
```

## Docker Containerization

The framework supports Docker containerization for easy setup and execution. The `Dockerfile` defines the Docker image, including dependencies and test execution environment. To build and run tests inside a Docker container:

```bash
docker build -t my-test-image .
docker run my-test-image pytest
```

The Docker container automatically handles the setup and execution of tests, ensuring consistency across environments.

## Contributing

Contributions are welcome! Fork the repository, make changes, and submit pull requests.

## License

This project is licensed under the MIT License.
```

This complete README.md file includes all the sections you requested, providing users with a comprehensive guide to understanding and using the Python Selenium pytest framework.