← Back to all lessons

03 / Web / 30 min READ + PRACTICE

Browser and API automation.

Automate repeatable checks against a local app with requests or a browser test tool.

Practice boundaryUse your own devices, your isolated practice VM or 127.0.0.1. Get explicit authorization for any other system.

Choose the right level

Use a simple HTTP client when testing an API response. Use browser automation when you must exercise rendering, JavaScript or keyboard interaction. Tests should assert outcomes, not merely click buttons.

Build a small check

Create a local status check that reports the response code and fails cleanly if the service is unavailable. Use a short timeout and a fixed loopback URL; this is a regression check, not an internet-wide crawler.

LAB TERMINAL / EXAMPLE
from urllib.request import urlopen
from urllib.error import URLError
try:
    with urlopen('http://127.0.0.1:8000/', timeout=3) as response:
        assert response.status == 200
        print('Local app responded')
except URLError as exc:
    print('Local app unavailable:', exc.reason)

Make runs reproducible

Seed test data, limit request volume and clean up after every run. Do not hard-code a real password in scripts; use dummy test credentials from a local environment file excluded from version control.

HANDS-ON EXERCISE

Try it in your lab

Write a localhost response-code test for both an existing path and a missing path; assert the expected 200 and 404.

CHECKPOINT

Make sure it clicks

When does a browser automation test teach you something an HTTP-only check cannot?

TRY WITH OPENCODE

A prompt you can adapt

Add clear assertions and a timeout to my localhost-only web check; keep fixtures deterministic and redact any tokens from failures.
How to set up OpenCode ↗
Your progress stays in this browser only.