Bird
Raised Fist0
Selenium Pythontesting~8 mins

Test reporting in CI in Selenium Python - Framework Patterns

Choose your learning style10 modes available
Framework Mode - Test reporting in CI
Folder Structure
selenium-python-project/
├── tests/
│   ├── test_login.py
│   ├── test_checkout.py
│   └── __init__.py
├── pages/
│   ├── login_page.py
│   ├── checkout_page.py
│   └── __init__.py
├── utils/
│   ├── driver_factory.py
│   ├── logger.py
│   └── __init__.py
├── reports/
│   └── (generated test reports here)
├── config/
│   ├── config.yaml
│   └── __init__.py
├── conftest.py
├── requirements.txt
└── pytest.ini
Test Framework Layers
  • Driver Layer: Handles browser setup and teardown (e.g., driver_factory.py).
  • Page Objects: Encapsulate page elements and actions (e.g., login_page.py).
  • Tests: Test cases using pytest that call page objects (e.g., test_login.py).
  • Utilities: Helpers like logging, screenshot capture, and report generation.
  • Configuration: Environment settings, credentials, and browser options (e.g., config.yaml).
Configuration Patterns
  • Environment Config: Use config/config.yaml to store URLs, credentials, and browser types for different environments (dev, staging, prod).
  • pytest.ini: Configure pytest options like markers and test paths.
  • Command Line Overrides: Use pytest command line options to select environment or browser dynamically.
  • Secrets Management: Store sensitive data outside the repo or use environment variables.
Test Reporting and CI/CD Integration
  • Test Reports: Use pytest plugins like pytest-html or pytest-allure to generate readable HTML or XML reports saved in reports/ folder.
  • CI Integration: Configure CI tools (e.g., GitHub Actions, Jenkins) to run tests on code push and collect reports as build artifacts.
  • Fail Fast and Notifications: Configure CI to fail the build on test failures and send notifications (email, Slack).
  • Report Archiving: Keep historical test reports for trend analysis and debugging.
Best Practices for Test Reporting in CI
  1. Clear and Readable Reports: Use HTML or Allure reports with screenshots on failure for easy debugging.
  2. Automate Report Generation: Integrate report creation in test runs automatically.
  3. Store Reports as Artifacts: Save reports in CI to access after runs.
  4. Fail Builds on Test Failures: Prevent broken code from merging by failing CI on test errors.
  5. Use Tags and Filters: Organize tests with markers to run subsets and generate focused reports.
Self Check

Where in this folder structure would you add a new test report plugin configuration to generate HTML reports automatically?

Key Result
Organize Selenium Python tests with clear layers and generate automated HTML reports integrated into CI pipelines.

Practice

(1/5)
1. What is the main purpose of test reporting in Continuous Integration (CI)?
easy
A. To provide quick feedback on test results automatically
B. To write test cases manually
C. To deploy the application to production
D. To create user documentation

Solution

  1. Step 1: Understand CI test reporting role

    Test reporting in CI is designed to give fast feedback on whether tests pass or fail after code changes.
  2. Step 2: Identify the correct purpose

    Among the options, only providing quick automatic feedback matches the main purpose of test reporting in CI.
  3. Final Answer:

    To provide quick feedback on test results automatically -> Option A
  4. Quick Check:

    Test reporting = quick feedback [OK]
Hint: Test reporting = fast feedback on tests [OK]
Common Mistakes:
  • Confusing test reporting with deployment
  • Thinking test reporting is about writing tests
  • Mixing test reporting with documentation
2. Which pytest command option generates a test report in XML format suitable for CI tools?
easy
A. --html=report.html
B. --junitxml=report.xml
C. --json=report.json
D. --output=report.txt

Solution

  1. Step 1: Recall pytest report options

    Pytest uses --junitxml to create XML reports compatible with many CI tools.
  2. Step 2: Match option to XML report

    Among the options, only --junitxml=report.xml generates the correct XML format for CI.
  3. Final Answer:

    --junitxml=report.xml -> Option B
  4. Quick Check:

    Pytest XML report = --junitxml [OK]
Hint: Use --junitxml for CI XML reports in pytest [OK]
Common Mistakes:
  • Using --html instead of --junitxml
  • Confusing JSON or text output with XML
  • Missing the file name after the option
3. Given this pytest command:
pytest tests/ --junitxml=results.xml
What will happen after the tests run?
medium
A. Tests will run but no report file will be created
B. Tests will fail due to syntax error in command
C. A file named results.xml will be created with test results in XML format
D. A HTML report named results.xml will be generated

Solution

  1. Step 1: Understand the command effect

    The --junitxml=results.xml option tells pytest to save test results in XML format to the file named results.xml.
  2. Step 2: Identify the output file type

    The file created is XML, not HTML, and the command syntax is correct, so tests run and report is saved.
  3. Final Answer:

    A file named results.xml will be created with test results in XML format -> Option C
  4. Quick Check:

    --junitxml creates XML report file [OK]
Hint: --junitxml creates XML report file after tests [OK]
Common Mistakes:
  • Thinking no report is created
  • Confusing XML with HTML report
  • Assuming command syntax error
4. You added --junitxml=report.xml to your pytest command, but the CI tool shows no test report. What is the most likely cause?
medium
A. The tests did not run due to errors in test code
B. The pytest command syntax is incorrect
C. The CI tool does not support XML reports
D. The report.xml file is not saved in the CI workspace directory

Solution

  1. Step 1: Check report file location

    CI tools need the report file in the workspace folder to read it. If saved elsewhere, the tool won't find it.
  2. Step 2: Verify other causes

    The command syntax is correct, tests likely ran, and most CI tools support XML reports, so the missing file location is the main issue.
  3. Final Answer:

    The report.xml file is not saved in the CI workspace directory -> Option D
  4. Quick Check:

    Report file location matters in CI [OK]
Hint: Ensure report file is in CI workspace folder [OK]
Common Mistakes:
  • Assuming command syntax error without checking
  • Ignoring file save location
  • Thinking CI tools don't support XML reports
5. In a CI pipeline, you want to fail the build if any Selenium tests fail and generate a detailed report. Which approach is best?
hard
A. Run pytest with --junitxml=report.xml and configure CI to fail on test failures using this report
B. Run tests without report and manually check logs after build
C. Use --html=report.html and ignore test failures in CI
D. Run tests locally and upload screenshots only

Solution

  1. Step 1: Generate machine-readable test report

    Using --junitxml=report.xml creates a detailed XML report that CI tools can parse.
  2. Step 2: Configure CI to fail build on test failures

    CI tools can read the XML report and mark the build as failed if tests fail, automating quality checks.
  3. Final Answer:

    Run pytest with --junitxml=report.xml and configure CI to fail on test failures using this report -> Option A
  4. Quick Check:

    Use XML report + CI fail on test fail [OK]
Hint: Use --junitxml and CI fail on test failure [OK]
Common Mistakes:
  • Ignoring test failures in CI
  • Not generating machine-readable reports
  • Relying on manual log checks
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard