A scraper can return a successful HTTP response and still produce unusable data. This web scraper testing checklist helps you verify selectors, required fields, pagination, encoding, duplicates, status codes, and schema changes before a scheduled run or deployment. Use it with a Python scraper, a Playwright or Puppeteer workflow, or another extraction stack.
Overview
Scraper testing is data-quality testing as much as it is code testing. A broken selector may not raise an exception; it may simply return an empty string. A changed page template may leave half of your records intact while silently dropping prices, identifiers, or pagination links. Reliable validation therefore checks both the mechanics of collection and the meaning of the collected fields.
Before trusting a scraper, define the expected output. Write down the fields, their types, which fields are required, acceptable empty values, and the rules for identifying a unique record. For example, a product record might require a canonical URL and name, allow a missing description, and use a normalized product ID as its uniqueness key.
required_fields = ["url", "name"]
allowed_empty = ["description"]
unique_key = "url"
assert record["url"].startswith("https://")
assert record["name"].strip() != ""
assert record["price"] is None or record["price"] >= 0
Keep a small representative fixture: a saved HTML response or a local test page containing ordinary records, missing optional fields, special characters, and at least one edge case. A fixture gives you a stable input for regression tests when the live site changes or becomes temporarily unavailable.
Checklist by scenario
Before the first production run
- Confirm that the target URLs, request method, query parameters, and authentication assumptions are correct.
- Inspect the response status, final URL, content type, and response size. A login page or error document can look like valid HTML to a parser.
- Test selectors against several records, not only the first visible item. Check that each selector returns the intended element and not a navigation, advertisement, or repeated wrapper.
- Validate required fields and data types. Convert prices, dates, counts, and identifiers deliberately rather than relying on implicit conversion.
- Check whitespace, HTML entities, Unicode characters, and line breaks in extracted text.
- Define a duplicate key and test it on the complete output, including records collected across pages.
- Record a small golden output file. Future runs can compare field names, record counts, and selected values against this known-good sample.
When selectors may have broken
Start with a count check. If a page normally contains records and the parser suddenly returns zero, stop the pipeline instead of exporting an empty file. If the count falls sharply but does not reach zero, compare a sample of current HTML with the saved fixture. Inspect class names, nesting, attributes, and whether content has moved from server-rendered HTML into a client-side application.
Test selector fallbacks carefully. A broad fallback that prevents an error can be worse than a controlled failure if it captures unrelated text. Each fallback should have its own assertion, expected element count, and review path.
When fields are missing or the schema drifts
- Compare the current field set with the expected schema.
- Fail or quarantine records when required fields are absent.
- Track the proportion of null or empty values for each optional field.
- Detect unexpected fields and decide whether to preserve, ignore, or map them.
- Check that date and number formats still parse consistently.
A simple schema check can be expressed as a contract:
expected = {"url", "name", "price", "published_at"}
actual = set(record)
missing = expected - actual
unexpected = actual - expected
if missing:
raise ValueError(f"Missing fields: {missing}")
When pagination or infinite scroll is involved
Test the first page, a middle page, the final page, and an empty-page response. Verify that the next-page condition eventually stops and that a repeated next link cannot create an endless loop. Compare the number of unique keys with the total number of records. For a deeper workflow, see how to scrape pagination and infinite scroll pages without missing or duplicating results.
When using a browser automation tool
For Playwright or Puppeteer, test after the relevant content is visible rather than relying only on a fixed sleep. Check navigation timeouts, console errors, failed network requests, and the behavior of cookie or consent dialogs. Save a screenshot or rendered HTML when an assertion fails. The right wait condition depends on the site, so keep it tied to a meaningful selector or network event. For a tool-selection overview, compare Playwright and Puppeteer for web scraping.
What to double-check
| Failure signal | Likely cause | Validation to add |
|---|---|---|
| Zero records | Changed selector, blocked response, login page, or wrong URL | Assert status, content type, response markers, and minimum record count |
| Required field suddenly empty | Schema change, different template, or client-rendered content | Required-field assertions and null-rate thresholds |
| Duplicate records | Repeated pages, unstable pagination, or non-unique key | Uniqueness check across the entire run |
| Unreadable characters | Encoding mismatch, entity handling, or incorrect decoding | Fixture values containing accents, symbols, and non-Latin text |
| Unexpected status code | Redirect, throttling, authorization failure, or server error | Allowed-status policy, final-URL logging, and retry limits |
| Record count changes sharply | Real content change or extraction regression | Compare against a baseline and review the change before publishing |
Do not treat HTTP success as extraction success. Log the URL, timestamp, status code, response length, parser version, and counts of discovered and accepted records. These details make a failure diagnosable without reproducing the exact run immediately.
Separate transport, parsing, validation, and export tests. A transport test asks whether the response can be obtained. A parsing test asks whether known HTML produces the expected fields. A validation test checks business rules. An export test verifies that JSON, CSV, or a database write preserves types and characters. This separation helps identify the failing layer.
Common mistakes
- Testing only the happy path: Include missing fields, empty results, malformed values, redirects, and special characters.
- Using brittle selectors: Prefer stable attributes or meaningful structural relationships where available, and still monitor selector results after changes.
- Accepting empty output: An empty file should be an explicit outcome, not the default result of a failed selector.
- Checking duplicates only within one page: Deduplicate after all pages and requests have been combined.
- Hard-coding a sleep as readiness logic: A delay may be too short on a slow run and wasteful on a fast one. Wait for observable application state.
- Overwriting evidence: Preserve failed HTML, screenshots, response metadata, and a sample of invalid records when practical.
- Ignoring responsible collection: Review the site's access expectations, use appropriate rate limits, and avoid creating unnecessary load. The workflow in this responsible scraping guide covers those operational checks.
Also avoid making every warning fatal. A missing optional description may be acceptable, while a missing URL should stop publication. Classify checks as blocking errors, warnings, or informational metrics so the response matches the risk.
When to revisit
Run this checklist before the first production deployment, before a scheduled collection resumes, and after changing selectors, browser versions, parsers, schemas, or export destinations. Revisit it when the target site redesigns its templates, changes navigation, introduces a consent flow, or moves content into client-side rendering.
It is also useful before seasonal planning cycles or any period when the output will support a time-sensitive report. Compare a current sample with the previous known-good output, review null and duplicate rates, and confirm that pagination still reaches the intended boundary.
Make the review repeatable: keep fixtures under version control, run parser and schema tests in continuous integration, and alert on meaningful count or null-rate changes. After each incident, add the failure pattern to a fixture and add a test that would have detected it. That turns maintenance experience into a permanent scraper quality check rather than a one-time fix.
Action checklist: save a representative fixture, define required fields, assert response and record counts, test uniqueness, validate types and encoding, capture failure evidence, and review the checklist whenever the workflow or target page changes.