Skip to content

About

This repository is dedicated to Commcare Connect Automation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

900 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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


🎯 Feature Runs (run part of the web suite)

The web suite can run just one area instead of everything. Open playwright_web.yaml, click Run workflow, pick the branch and environment, then use What to run: Full suite, an app area (Opportunities, Programs, Opportunity dashboard, Workers, Tasks, Messaging, Microplanning, Invoices, PersonalID), or Connect PR. The tests input takes an exact list instead, e.g. tests/test_olp_04.py tests/test_plp_list_page.py.

The mobile suite always runs in full: the dev team asked for the complete suite on feature requests rather than partial runs (Mobile Automation QA Plan, "Run scope").

  • Connect PR: enter a commcare-connect PR number in connect_pr. The run covers only the tests that PR affects, worked out from its diff by playwright_web/utils/impact_check.py. Locally: cd playwright_web && python -m utils.impact_check --pr <n> --tests.
  • The change must be deployed first. The suites test a deployed environment (staging or prod), not a branch, so put the feature on staging before a stage run.
  • Areas are picked by test file name (tests/test_olp_*.py is Opportunities, etc.), so a new test file joins its area automatically.
  • The Slack card, email and run name say what ran (for example Programs · stage), so a partial run isn't mistaken for a full one.

🤖 QA Agent for Connect PRs

Design: the "QA Agent for Connect PRs" doc. When a commcare-connect PR changes behaviour, the agent updates the scripts it breaks and drafts cases for what's new, as a QA PR for review. Updated and new tests carry @pytest.mark.pending_prod(pr=<n>) and the originals they replace @pytest.mark.replaced_by_pr(<n>); every run (Playwright and Selenium) picks between them by whether PR <n> is in the deployed build (playwright_web/utils/pr_gating.py).

Workflow What it does Started by
qa_agent_from_pr.yaml Runs the qa-ticket-prep skill's PR mode for one Connect PR and opens or updates the QA PR on qa-agent/connect-pr-<n>. Skips drafts, Dependabot, no-qa and docs-only PRs, and PRs whose head it has already processed. Closes the QA PR if the Connect PR is closed unmerged. commcare-connect on ready for review / approved / closed (job still to be added on their side), or by hand with a PR number
qa_pending_cleanup.yaml For Connect PRs now in production, deletes the replaced_by_pr originals and removes the pending_prod markers, as one standing PR on qa-cleanup/release-pending-tests. commcare-connect's prod deploy (to be added), and weekdays 03:30 UTC as a fallback
  • How it reaches Claude: workload identity federation, with no stored API key. The agent job asks GitHub for an OIDC token and swaps it for a short-lived Claude token, refreshed every 5 minutes. It needs repository variables ANTHROPIC_FEDERATION_RULE_ID and ANTHROPIC_ORGANIZATION_ID (plus ANTHROPIC_SERVICE_ACCOUNT_ID and ANTHROPIC_WORKSPACE_ID, all set on 24 Nov from the rule Simon created), and a federation rule in the Claude Console for repo:dimagi/dimagi-qa-ccc:ref:refs/heads/main.
  • Secrets the agent needs: JIRA_BASE_URL, JIRA_EMAIL and JIRA_API_TOKEN to read tickets. Without them it works from the PR alone and says so.
  • How it's contained: the agent reads untrusted PR text, so it runs in a job with a read-only token and can edit files but not run anything. The impact check and Jira tickets are gathered before it starts. Its changes are checked for Anthropic tokens and the Jira token, tested in a separate job with no secrets, and pushed by a third job that runs only git and gh.
  • Reviewing an agent PR: read every changed .py file, not just the summary. The agent wrote them from untrusted text, and they run with the suites' secrets (HQ, BrowserStack) as soon as a suite is dispatched on that branch. Review the code first, then dispatch.
  • Locally: cd playwright_web && python -m utils.impact_check --pr <n>, python -m utils.jira_ticket CCCT-1234, and python -m utils.pending_cleanup --dry-run.
  • PRs opened by these workflows use the workflow token, so the suites don't run on them automatically: after reviewing the code, dispatch playwright_web.yaml on the branch before merging.
  • Tested cases move from test_plans/pending/ into the master plans with the skill's finalize mode (test_plans/README.md).

⚠️ 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

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages