Manuals / Selenium WebDriver / Ch 7

C · Test InfrastructureIntermediate55 min read

7. Test runners — pytest, TestNG, or JUnit

Selenium WebDriver · 48 pages source format

Raw scripts do not scale. Test runners give discovery, reporting, markers, and parallel hooks.

What you'll learn

  • Test discovery
  • Markers / groups
  • HTML reports
  • Parametrize data-driven tests

pytest or TestNG setup

pytest: tests/test_*.py, assert keywords. TestNG: @Test annotations, testng.xml suite.

# pytest.ini
[pytest]
markers =
    smoke: quick checks
    regression: full suite

Do this now

Organize tests under tests/. Run full suite with one command.

Clear?

Markers / groups

Smoke vs regression — run smoke in CI fast path, full nightly.

Do this now

Mark 3 tests @pytest.mark.smoke. Run pytest -m smoke.

Clear?

Parametrize

One test function, multiple data rows — invalid users, boundary inputs.

Do this now

Parametrize login with 3 invalid credential tuples.

Clear?

HTML report

pytest-html or Allure or ExtentReports (Java). Attach to CI artifacts.

Do this now

Generate HTML report locally. Include screenshot on failure if plugin supports.

Clear?

Checklist