Skip to content

dimagi/dimagi-qa-ccc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

220 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dimagi

CommCare - Connect Pytest Automation Suite

This repository contains an end-to-end test automation framework built using Python, Pytest, Selenium, and Appium, with full CI/CD integration using GitHub Actions.

The framework supports:

  • 🌐 Web automation
  • πŸ“± Mobile automation (BrowserStack)
  • πŸ“Š Allure reporting
  • πŸ” CI/CD pipelines
  • πŸ”” Slack & Email notifications
  • 🌍 Allure report publishing to GitHub Artifacts

πŸ“Œ Tech Stack

Tool Purpose
Python 3.10 Programming language
Pytest Test framework
Selenium Web automation
Appium Mobile automation
BrowserStack Cloud mobile testing
Allure Test reporting
GitHub Actions CI/CD
Slack Notifications

πŸ“‚ Project Structure

Dimagi/
β”œβ”€β”€ .github/
β”‚ └── workflows/
β”‚
β”œβ”€β”€ .venv/
β”‚
β”œβ”€β”€ app/
β”‚
β”œβ”€β”€ config/
β”‚
β”œβ”€β”€ drivers/
β”‚
β”œβ”€β”€ locators/
β”‚
β”œβ”€β”€ pages/
β”‚ β”œβ”€β”€ web_pages/
β”‚ └── mobile_pages/
β”‚
β”œβ”€β”€ reports/
β”‚ β”œβ”€β”€ allure-report/
β”‚ β”œβ”€β”€ allure-results/
β”‚ └── results.xml
β”‚
β”œβ”€β”€ test_data/
β”‚
β”œβ”€β”€ tests/
β”‚ β”œβ”€β”€ web_tests/
β”‚ └── mobile_tests/
β”‚
β”œβ”€β”€ utils/
β”‚
β”œβ”€β”€ .gitignore
β”œβ”€β”€ conftest.py
β”œβ”€β”€ pytest.ini
β”œβ”€β”€ README.md
β”œβ”€β”€ settings-sample.cfg
└── requirements.txt


🧠 Framework Design Highlights

  • Page Object Model (POM) for clean separation of tests and UI logic
  • Pytest fixtures for driver management and setup/teardown
  • Separate execution flows for Web and Mobile tests
  • Allure reporting for detailed test insights
  • Pytest reporting for easier access and test insights
  • CI/CD ready with GitHub Actions
  • BrowserStack integration for cloud mobile execution
  • Secure secrets handling via GitHub Secrets

πŸ“Œ Key Directories Explained

Directory Purpose
tests/ Contains all web and mobile test cases
pages/ Page Object Model implementations
locators/ Element locators for web and mobile tests
drivers/ WebDriver and Appium driver setup
config/ Environment and capability configurations
test_data/ Test data required for web and mobile test cases
reports/ Allure reports and test artifacts
utils/ Reusable helper utilities
.github/workflows/ CI/CD pipeline definitions

πŸ—‚οΈ Test Data Configuration (Web & Mobile)

All test-related data is maintained under the test_data/ directory.

  • Update or add new test data files as required for your test cases.
  • Ensure the data format matches what is expected by the corresponding test cases.
  • Test data can be customized separately for:
    • Web tests located under test_data/web_test_data
    • Mobile tests located under test_data/mobile_workers

Any changes made in test data will directly affect test execution.


πŸ› οΈ Environment Configuration (config Folder)

The config/ directory contains environment-specific configuration files.

env.yaml

  • Used to manage environment-level settings such as:
    • Application URLs
    • BrowserStack URL
    • Appium local server URL
  • Modify this file to switch between environments (e.g., Staging, Production).

android_caps.json

  • Used for mobile automation configuration.
  • Update this file to modify Android capabilities such as:
    • Device name
    • Platform name & version
    • App package and activity
    • Other Appium-related capabilities

settings-sample.cfg

  • Used to manage test credentials and execution platform:
    • Rename the file settings-sample.cfg to settings.cfg
    • Execution platform for mobile tests- "browserstack" or "local" (in case an emulator is setup on local)
    • BrowserStack Username and Access Key
    • Commcare login credentials
  • Modify this file to switch between Execution platforms, user credentials.

πŸ“± Mobile Application Update

The app/ directory contains the Android application .apk file.

  • When a new version of the mobile app is available:
    • Replace the existing APK in the app/ folder with the new version.
    • Ensure the APK name and path match the values defined in the configuration.

Local vs BrowserStack Execution

By default:

  • Web tests run locally
  • Mobile tests run on BrowserStack

βš™οΈ Prerequisites

  • Python 3.10+
  • Google Chrome (for web tests)
  • BrowserStack account (for mobile tests)

πŸ“¦ Install Dependencies

pip install -r requirements.txt

πŸ”‘ Storing Environment Variables

BrowserStack (Required for Mobile Tests)

Run the below commands in terminal/PowerShell
macOS / Linux
export BROWSERSTACK_USERNAME=your_username
export BROWSERSTACK_ACCESS_KEY=your_access_key
Windows
$env:BROWSERSTACK_USERNAME="your_username"
$env:BROWSERSTACK_ACCESS_KEY="your_access_key"

▢️ Run Tests Locally

Run Web Tests

pytest -v tests/web_tests

Run Mobile Tests

pytest -v tests/mobile_tests

Run a specific test file

pytest -v tests/web_tests/test_olp_1_2_3.py
pytest -v tests/mobile_tests/test_tc_1.py 

πŸ“Š Normal Pytest Reports (Local Execution)

Generate Allure Results

pytest -v tests/web_tests --html=report.html --self-contained-html --tb=short

No extra steps needed to generate the reports after execution.

πŸ“Š Allure Reports (Local Execution)

Generate Allure Results

pytest -v tests/web_tests --alluredir=reports/web/allure-results

Generate HTML Report

allure generate reports/web/allure-results -o reports/web-allure-report --clean

Open Report

allure open reports/web-allure-report

⚠️ allure open works only on local machines, not in CI/CD.


πŸš€ CI/CD with GitHub Actions

Trigger Conditions

  • Push to main
  • Pull request to main
  • workflow_dispatch for manual workflow execution

CI Pipeline Includes

  • Web tests execution
  • Mobile tests execution (BrowserStack)
  • Allure report generation
  • Slack & email notifications

Steps to Open Allure report from GitHub Artifacts

  • Download the Allure report zip file from workflow artifacts
  • Unzip and extract the files in file explorer
  • Execute the below command in Windows PowerShell
allure open "path_to_downloaded_report_folder"

Steps to Open Pytest report from GitHub Artifacts

  • Download the html report zips file from workflow artifacts
  • Unzip and extract the files in file explorer
  • Or if your email address is one of the recipients in the email notifications, the report.html files for we and prod will be attached

πŸ” GitHub Secrets Configuration

Add secrets under:

Repository β†’ Settings β†’ Secrets and variables β†’ Actions

Secret Name Description
BROWSERSTACK_USERNAME BrowserStack username
BROWSERSTACK_ACCESS_KEY BrowserStack access key
SLACK_WEBHOOK_URL Slack incoming webhook
FROM_EMAIL_USERNAME Username of the sender email
FROM_EMAIL_PASSWORD Password of the sender email
TO_EMAIL_USERNAME Username of the receiver email

πŸ”” Configuring Slack Incoming Webhook for Notifications

To enable the CI pipeline to send notifications to a specific Slack channel, follow these steps:

  1. Open Slack and navigate to workspace settings

    • Click on your workspace name in the top left corner of Slack.
    • Select Tools & Settings β†’ Manage Apps.
      This will open the Installed Apps section of the Slack Marketplace.
  2. Add Incoming Webhooks

    • Search for Incoming WebHooks in the marketplace.
    • Click Add to Slack.
  3. Select the channel for notifications

    • Choose the Slack channel where you want the notifications to appear from the dropdown.
    • Click Add Incoming Webhook Integration.
  4. Copy the Webhook URL

    • After adding the integration, Slack will provide a Webhook URL.
    • Copy this URL β€” it will be used to send messages to the selected channel.
  5. Store the Webhook URL securely

    • In your GitHub repository, navigate to:
      Settings β†’ Secrets and variables β†’ Actions
      
    • Click New repository secret and add:
      • Name: SLACK_WEBHOOK_URL
      • Value: <your-webhook-url>

The webhook URL should be treated as a secret; anyone with this URL can post messages to the channel.

Currently the channel showcasing the Connect test results is #qa-connect-automated-test-results

βœ‰οΈ Configuring Email Notifications

The framework can send test execution notifications via email. Follow these steps to securely set up email notifications using GitHub repository secrets:

  1. Store Sender Email Credentials

    • Save the sender email username and password as GitHub secrets.

    • Important: For security, use an app password instead of your real email password if your email provider supports it (e.g., Gmail, Outlook).

    • FROM_EMAIL_USERNAME β†’ your email address

    • FROM_EMAIL_PASSWORD β†’ app password

  2. Store Recipient Email Addresses

    • Save the recipient email addresses as a comma-separated string in a GitHub secret.
    • TO_EMAIL_USERNAME β†’ qa1@example.com, qa2@example.com

The workflow or script will use these secrets to send notifications to the specified recipients.


▢️ Manually Trigger Tests on Github

⚠️ Mobile Test Execution – Important Considerations

1. Payment Flow Limitation (TC_6)

  • TC_6 (Payment Flow) can be executed only once per user per day as per functionality.
  • If this test needs to be re-run multiple times:
    • Update the user details in:
      test_data/mobile_workers.yaml
      
    • Use a different user for each execution.

This limitation is due to business rules on the backend.

**P.S. This testcase is currently skipped due to a known bug on the latest apks.

About

This repository is dedicated to Commcare Connect Automation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages