Skip to content

About

This project is the demonstration of a scalable, reusable, maintainable automation framework based on page object model using selenium webdriver, pytest and python

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

AutoTestLab - Automation Frameworks

This repository includes comprehensive test automation frameworks for end-to-end testing using Python, pytest, and Selenium. It includes both API and UI test suites with integrated CI/CD via Jenkins.

πŸ“š Test Suites

1. API Testing - JSONPlaceholder

  • Target: JSONPlaceholder API
  • Framework: pytest with requests
  • Features:
    • JSON Schema validation
    • Multiple API endpoints testing
    • Custom pytest markers
    • HTML and JSON reports

2. UI Testing - SauceDemo

  • Target: SauceDemo Application
  • Framework: Selenium with pytest
  • Features:
    • Page Object Model design pattern
    • Selenium Grid support
    • Cross-browser testing capability
    • HTML reports

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • Git
  • Python 3.8+

1. Local Setup (with Jenkins)

# Clone repository
git clone <repo-url>
cd AutoTestLab

# Run setup script
chmod +x setup-jenkins.sh
./setup-jenkins.sh

This starts:

2. Run Tests Locally

# Start Docker containers (if not already running)
docker compose up -d

# Run all tests
chmod +x run_tests.sh
./run_tests.sh all

# Run specific suite
./run_tests.sh api    # Only API tests
./run_tests.sh ui     # Only UI tests

3. Manual Test Execution

# API Tests
cd JsonPlaceholder-API-Automation-Suite
pip3 install -r requirements.txt
pytest tests/ -v --html=api_report.html

# UI Tests (with Selenium Grid)
cd SauceDemo-UI-Automation-Suite
export USE_GRID=true
export SELENIUM_HUB_URL=http://localhost:4444
pip3 install -r requirements.txt
pytest tests/ -v --html=ui_report.html

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      GitHub Repository (with Webhooks)      β”‚
β”‚  (PR triggers Jenkins pipeline automatically) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Jenkins Container (Orchestration & Reports) β”‚
β”‚  - Runs API Tests                            β”‚
β”‚  - Runs UI Tests (via Selenium Grid)         β”‚
β”‚  - Publishes results to PR                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β–Ό                    β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ API Testsβ”‚        β”‚Selenium   β”‚
    β”‚ JSONPlaceHolder  β”‚ Hub & Chromeβ”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ Project Structure

AutoTestLab/
β”œβ”€β”€ JsonPlaceholder-API-Automation-Suite/
β”‚   β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ resource/          (JSON schemas)
β”‚   β”œβ”€β”€ config.py
β”‚   β”œβ”€β”€ requirements.txt
β”‚   └── pytest.ini
β”‚
β”œβ”€β”€ SauceDemo-UI-Automation-Suite/
β”‚   β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ pages/             (Page Objects)
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   └── browser.py     (WebDriver setup)
β”‚   β”œβ”€β”€ conftest.py
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ generate_report.py
β”‚   β”œβ”€β”€ publish_pr_comment.py
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ jenkins-init/
β”‚   └── configure.groovy
β”‚
β”œβ”€β”€ Jenkinsfile            (CI/CD Pipeline)
β”œβ”€β”€ compose.yml            (Container setup)
β”œβ”€β”€ setup-jenkins.sh       (Quick start script)
β”œβ”€β”€ run_tests.sh           (Local test runner)
β”œβ”€β”€ .env.example           (Configuration template)
β”œβ”€β”€ JENKINS_SETUP.md       (Detailed setup guide)
└── README.md              (This file)

πŸ”§ Configuration

Environment Variables

Copy .env.example to .env and update with your values:

cp .env.example .env
# Edit .env with your configuration

Key variables:

  • GITHUB_TOKEN: GitHub Personal Access Token for PR comments
  • GITHUB_REPOSITORY: Repository in format owner/repo
  • SELENIUM_HUB_URL: Selenium Grid URL (default: http://localhost:4444)
  • USE_GRID: Enable Selenium Grid (true/false)

Jenkins Configuration

  1. Access Jenkins: http://localhost:8080
  2. Create new Pipeline job
  3. Configure with GitHub repository URL
  4. Set script path to Jenkinsfile
  5. Add GitHub webhook for PR triggers

See JENKINS_SETUP.md for detailed instructions.

πŸ“Š Reports

Generated Reports

  • API Report: JsonPlaceholder-API-Automation-Suite/api_report.html
  • UI Report: SauceDemo-UI-Automation-Suite/ui_report.html
  • Combined Report: combined_report.html
  • JUnit XML: For CI/CD integration

Viewing Reports

# Jenkins UI
# http://localhost:8080/job/AutoTestLab-Pipeline/

# Local reports (open in browser)
open combined_report.html

GitHub PR Comments

Test results are automatically posted as PR comments when running via Jenkins with GitHub integration:

## πŸ§ͺ Test Report
**Status:** SUCCESS
**Timestamp:** 2024-01-18 10:30:45 UTC

### API Tests
- **Total:** 15 | **βœ… Passed:** 15 | **❌ Failed:** 0

### UI Tests  
- **Total:** 6 | **βœ… Passed:** 6 | **❌ Failed:** 0

🐳 Docker Commands

# Start containers
docker compose up -d

# Stop containers
docker compose stop

# View logs
docker compose logs -f

# Check status
docker compose ps

# Restart specific service
docker compose restart jenkins

# Clean up
docker compose down -v

πŸ” Monitoring

Selenium Grid Dashboard

Jenkins Dashboard

Container Logs

# Jenkins logs
docker logs -f jenkins

# Selenium Hub logs
docker logs -f selenium-hub

# Chrome node logs
docker logs -f selenium-chrome

πŸ› Troubleshooting

Selenium Hub not responding

# Check if hub is running
docker ps | grep selenium-hub

# Test connection
curl http://localhost:4444/wd/hub/status

# Check logs
docker logs selenium-hub

Jenkins won't start

# Check logs
docker logs jenkins

# Increase timeout and retry
docker compose restart jenkins
sleep 60

Chrome tests failing

# Increase shared memory
# Edit compose.yml: shm_size: 4gb

# Restart containers
docker compose down
docker compose up -d

See JENKINS_SETUP.md for more troubleshooting tips.

πŸ“š Documentation

πŸ”‘ Key Features

βœ… Automated Testing

  • API testing with schema validation
  • UI testing with Page Object Model
  • Parallel execution support

βœ… CI/CD Integration

  • GitHub webhook integration
  • Automated PR comments with results
  • Build artifact archiving

βœ… Containerization

  • Jenkins in Docker
  • Selenium Grid with Chrome/Firefox nodes
  • Isolated test environment

βœ… Reporting

  • HTML reports with trends
  • JUnit XML for CI integration
  • Combined multi-suite reports
  • PR comments with test summary

βœ… Scalability

  • Multi-node Selenium Grid
  • Parallel test execution
  • Configurable browser instances

🀝 Contributing

  1. Create a new branch: git checkout -b feature/your-feature
  2. Make changes and commit: git commit -am 'Add feature'
  3. Push to branch: git push origin feature/your-feature
  4. Create Pull Request
  5. Jenkins will automatically run tests and post results

πŸ“ License

[Add your license information]

πŸ‘₯ Support

For issues, questions, or contributions:

  • Check JENKINS_SETUP.md
  • Review test logs in Jenkins UI
  • Check Docker container logs

πŸ“¦ Requirements

  • Python 3.8+
  • Docker 20.10+
  • Docker Compose 1.29+
  • Git

πŸ”„ Updates

To update container images:

# Pull latest images
docker compose pull

# Rebuild and restart
docker compose up -d --build

Last Updated: January 18, 2024

About

This project is the demonstration of a scalable, reusable, maintainable automation framework based on page object model using selenium webdriver, pytest and python

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages