Build SEO Regression Tests: Catch Canonical, noindex, and Content Errors Before Launch

Use a dependency-free Python example to check status codes, titles, canonicals, noindex, body text, internal links, and sitemaps. Learn how to verify failures and add an SEO gate to CI.

Technical SEO SEO, Technical SEO, SEO Regression Testing, Automation, Advanced SEO Series
Build SEO Regression Tests: Catch Canonical, noindex, and Content Errors Before Launch

AI changes a shared SEO component.

The build passes, and the site looks fine.

But what if every article’s canonical now points to the homepage?

A visual review can miss that change.

SEO regression testing checks whether previously correct SEO conditions survive a change.

This guide builds a small check that compares representative URL responses with explicit expectations and fails when they differ.

Quick Summary

TopicDetails
PurposeDetect SEO conditions broken by deployment changes
Example environmentPython 3.9+, standard library only
ScopeGET response status, initial HTML, headers, and sitemap
Main checksTitle, canonical, noindex, body sentence, and links
Failure behaviorExit code 1 on an expectation mismatch
LimitDoes not test Google indexing, rankings, or browser rendering

This is the final article in the advanced technical SEO series.

1. Indexing diagnosis → 2. Rendering comparison → 3. Canonical conflicts → 4. SEO regression tests

Define Expected Behavior Before Chasing Scores

The starting point is not “get a score of 100.”

Define the conditions this particular site should preserve.

Page TypeExample Expected Behavior
Blog listingContains links to published articles
ArticleUnique title, appropriate canonical, and actual content
Language versionPreserves the correct language-specific canonical
Nonexistent URLReturns 404 instead of the homepage
Moved URLPermanently redirects to an appropriate replacement

Do not apply identical rules to every page.

A noindex on a login page may be intentional. The HTML checks in this example target public pages intended for search.

What Can You Automate?

Suitable for Automated ChecksNeeds Separate Review
HTTP status and headersGoogle’s actual canonical selection
Initial titles and canonicalsContent changes after JavaScript runs
Unintended noindexIndependent content value
A distinctive body sentenceSearch intent and explanatory quality
Expected links and sitemap URLsActual indexing and search performance

An automated test checks a contract you define.

It does not reproduce Google’s assessment. Even a live URL Inspection test does not guarantee indexing or predict the final canonical choice. Search Console URL Inspection documentation

1. Store Representative Pages and Expectations

Here is a small example:

[
  {
    "path": "/blog/seo-checklist/",
    "status": 200,
    "canonical": "https://example.com/blog/seo-checklist/",
    "title": "SEO Checklist",
    "text": "Check the HTTP response and canonical URL first.",
    "link": "/guides/technical-seo/"
  },
  {
    "path": "/this-page-does-not-exist/",
    "status": 404
  }
]

Replace the placeholder URL and text with your site’s values, then save it as cases.json.

title and text use substring matching. Choose a distinctive article sentence for text, rather than something that also appears in navigation or a heading.

canonical must exactly match the absolute URL in the HTML. link compares resolved link destinations.

When testing a preview, retain the production canonical expectation if that is the intended design.

If previews are intentionally protected by authentication or noindex, they will not pass these public-page checks unchanged. Define separate environment expectations first.

2. Parse Initial HTML and Compare Expectations

The example uses Python’s HTMLParser to read elements. Unlike a document-wide string search, it can distinguish a head canonical from text inside a script. Python HTMLParser documentation

Download the executable example and a configuration for this site:

The script requires no external packages and does not execute downloaded JavaScript.

The comparison follows this pattern:

# In the complete file, Document collects canonicals from the head.
if page.canonicals != [case["canonical"]]:
    errors.append("canonical mismatch")

if case["text"] not in body_text:
    errors.append("expected body text is missing")

This is an explanatory excerpt, not a standalone executable snippet. Use the linked complete file for actual checks.

The script checks:

  • Expected status without following redirects
  • One nonempty title in a 200 public HTML response
  • One head canonical matching the expected URL
  • Conflicting canonical declarations in HTTP Link headers
  • noindex or none in robots/googlebot meta tags and X-Robots-Tag
  • A distinctive sentence outside script, style, and template content
  • The expected destination in an a[href] link

What This Example Does Not Check

It does not evaluate CSS visibility or responses served specifically to Googlebot. Text existing in HTML does not prove it is readable on screen.

The HTTP Link header check handles simple canonical declarations. It is not a complete parser for every complex header syntax.

robots.txt, hreflang, JSON-LD, and the browser-rendered DOM are outside scope. X-Robots-Tag is checked conservatively: a noindex scoped to another bot also fails this gate.

3. Run It Against a Local Build

For an Astro static site, build and serve the output:

npm run build
python3 -m http.server 4321 --directory dist

In another terminal:

python3 check_seo.py \
  --base-url http://127.0.0.1:4321 \
  --cases cases.json \
  --sitemap /sitemap.xml

This assumes the two downloaded files are in your working directory.

--sitemap is optional. When supplied, it checks that the canonical of each expected 200 page is listed in that sitemap.

The example supports a urlset, not a sitemap index. For an index, select the relevant child sitemap or add recursive processing.

Sitemap inclusion is a policy adopted for this test. A URL missing from a sitemap is not automatically unindexable. Google’s sitemap documentation

4. Test Deliberate Failures Too

Passing on a healthy page does not prove the gate catches regressions.

Introduce controlled failures in local test pages and verify that the checks detect them.

Introduced ErrorExpected Finding
Canonical changed to homepagecanonical mismatch
Development noindex addednoindex/none found
Content replaced with Loadingexpected body text is missing
A nonexistent URL returns 200status 200, expected 404
Article link removed from listingexpected anchor link is missing

The sample is intended for checking healthy responses and deliberate failures locally. It does not reproduce Google’s actual crawler.

Use local fixtures or a dedicated test environment. You do not need to break production to test the gate.

5. Place the Gate After Building and Before Deployment

The CI sequence is:

Install dependencies
→ Build
→ Serve the build locally
→ Run SEO checks
→ Deploy the artifact that passed

In GitHub Actions, a step like this can follow an existing build step. Prepare Python first, for example with actions/setup-python. GitHub’s Python CI guide

- name: Check initial HTML SEO contracts
  shell: bash
  run: |
    set -euo pipefail
    python3 -m http.server 4321 --directory dist > /tmp/seo-server.log 2>&1 &
    seo_server_pid=$!
    trap 'kill "$seo_server_pid"' EXIT
    for attempt in {1..30}; do
      if curl -fsS http://127.0.0.1:4321/ko/guides/ > /dev/null; then
        break
      fi
      sleep 1
    done
    python3 public/examples/seo-regression/check_seo.py \
      --base-url http://127.0.0.1:4321 \
      --cases public/examples/seo-regression/cases.json \
      --sitemap /sitemap.xml

This example matches this repository’s file layout. Adapt URLs, file paths, and the build output directory for another site.

If a deployment tool changes configuration and rebuilds after the test, the published files may differ from those checked.

Version deployment configuration and verify the artifact you actually publish.

6. Repeat Checks on Production URLs

A local file server does not reproduce CDN behavior or production routing.

After deployment, change --base-url to the production domain:

python3 check_seo.py \
  --base-url https://example.com \
  --cases cases.json \
  --sitemap /sitemap.xml

The case file must contain the real site’s canonical expectations.

On failure, inspect which URL and condition changed. Investigate connectivity for a timeout; prioritize shared configuration when canonicals or noindex change across many pages.

Track Google’s actual indexing separately in Search Console.

An AI Prompt for Adding Regression Tests

Add SEO regression tests for this site's public pages.

First list expected URLs, canonicals, body sentences, and links by page type.
Separate public pages from intentional noindex pages.
Distinguish HTTP response checks from browser rendering checks.

Locally reproduce and detect incorrect canonicals, noindex, missing content,
soft 404s, and missing article links, alongside healthy cases.
Check server and content readiness instead of relying only on fixed delays.
Report actual execution results and anything outside test scope.

FAQ

Should every URL be tested on every change?

Start with representative home, listing, article, language, and 404 cases. Catch shared-template failures, then expand where useful.

Can this script test a CSR site?

It inspects initial HTML, so content that appears only after JavaScript runs fails the body expectation. If CSR is intentional, add a browser-based stage checking the rendered result.

Should an intentionally noindex preview fail?

It fails this sample’s public-page checks. Such an environment needs separate expectations and test policy.

Does passing guarantee indexing?

No. Preserving tested technical conditions and being indexed are separate outcomes.

Conclusion

SEO regression tests preserve an explicitly defined healthy state.

Choose representative URLs, canonicals, body text, and links, then check the same conditions after changes.

When AI makes edits, you can record which conditions were rechecked alongside its explanation.

If a check fails, return to indexing diagnosis and investigate whether rendering or canonical signals broke.