🧪 Test Hub
testing: Demo target v3.0.0 · built-in demo site

DEMO-024 Freight: shipping label -- new tab, barcode, PDF

Edit Load test Duplicate

Opens the label (a new tab, caught with expect_popup), decodes its Code 128 barcode from the bars with the test's own decoder, downloads the PDF and reads the barcode out of it too.

barcodedemodownloadfreightpopup version: 1.0 DEMO-024__freight_shipping_label.py group: Freight extrasgroup: Python and TypeScript, side by side

Runs
7
Pass rate
100%
7 passed / 0 failed
Avg duration
3s
p95 3s
Estimate
3s
avg of last 10 judged runs
Flakiness
0.00
0 stable · 1 alternates
Current streak
7
passed

Last 7 results newest on the right — click a square to open that run

Duration per run point color = outcome; dashed = 7-run average; click a point to open the run

Step timing trends the same step compared across the last 7 runs — slowest steps first, one line each

How long it takes distribution of 7 runs — two humps mean two different behaviours hiding behind one average

fastest 2s · slowest 3s

Why this test failed grouped by message, last 90 days

No failures recorded. 👍

Outcomes by target version

What this test does plain language, derived from the code

  1. site = Freight(page, ctx).sign_in()
  2. site.open(f"ops/shipments/{SHIPMENT}/")
  3. ⏱ Timed phase: open the label (a new tab)
  4. with page.expect_popup() as popup:
  5. Click #print-label
  6. label = popup.value
  7. label.wait_for_selector("#label-barcode")
  8. ctx.log(f"the label opened in a new tab: {label.url}")
  9. label.screenshot(path=str(ctx.artifacts_dir / "screenshots" / "label-tab.png"))
  10. ⏱ Timed phase: scan the barcode
  11. scanned = decode(label.eval_on_selector_all("#label-barcode g rect", BARS))
  12. ctx.log(f"the barcode reads {scanned!r}")
  13. assert scanned == SHIPMENT, (
  14. f"the label's barcode reads {scanned!r}: a depot scanner would route this parcel "
  15. f"as {scanned}, not {SHIPMENT}")
  16. assert label.inner_text("#label-number").strip() == SHIPMENT
  17. ⏱ Timed phase: download the PDF
  18. with label.expect_download() as download:
  19. label.click("#label-pdf")
  20. pdf = ctx.artifacts_dir / f"label-{SHIPMENT}.pdf"
  21. download.value.save_as(str(pdf))
  22. data = pdf.read_bytes()
  23. assert data.startswith(b"%PDF-"), "the download is not a PDF"
  24. in_pdf = decode(pdf_bars(data))
  25. assert in_pdf == SHIPMENT, f"the PDF's barcode reads {in_pdf!r}, not {SHIPMENT}"
  26. ctx.log(f"the PDF ({len(data)} bytes) carries the same barcode")
  27. label.close()
Show the code
"""A shipping label: a new tab, a barcode a scanner can read, a PDF.

"Print label" opens the label in a NEW TAB -- page.expect_popup() catches it
and hands the test a second page to drive. The test then reads the barcode
the way a depot scanner would: from the bars alone, with its own decoder
(_lib/barcode.py -- it shares no code with the site that printed the label,
so a label that encodes the wrong thing cannot fool it). Finally it
downloads the PDF, checks it is one, and reads the barcode out of the PDF
too. Both files are kept with the run.

The activity reel and video follow the first tab, so the label's picture is
saved explicitly.
"""
from _lib.barcode import decode, pdf_bars
from _lib.freight import Freight

SHIPMENT = "AF-100001"
BARS = "rs => rs.map(r => [+r.getAttribute('x'), +r.getAttribute('width')])"


def run(page, ctx):
    site = Freight(page, ctx).sign_in()
    site.open(f"ops/shipments/{SHIPMENT}/")

    with ctx.timed("open the label (a new tab)"):
        with page.expect_popup() as popup:
            page.click("#print-label")
        label = popup.value
        label.wait_for_selector("#label-barcode")
    ctx.log(f"the label opened in a new tab: {label.url}")
    label.screenshot(path=str(ctx.artifacts_dir / "screenshots" / "label-tab.png"))

    with ctx.timed("scan the barcode"):
        scanned = decode(label.eval_on_selector_all("#label-barcode g rect", BARS))
    ctx.log(f"the barcode reads {scanned!r}")
    assert scanned == SHIPMENT, (
        f"the label's barcode reads {scanned!r}: a depot scanner would route this parcel "
        f"as {scanned}, not {SHIPMENT}")
    assert label.inner_text("#label-number").strip() == SHIPMENT

    with ctx.timed("download the PDF"):
        with label.expect_download() as download:
            label.click("#label-pdf")
        pdf = ctx.artifacts_dir / f"label-{SHIPMENT}.pdf"
        download.value.save_as(str(pdf))
    data = pdf.read_bytes()
    assert data.startswith(b"%PDF-"), "the download is not a PDF"
    in_pdf = decode(pdf_bars(data))
    assert in_pdf == SHIPMENT, f"the PDF's barcode reads {in_pdf!r}, not {SHIPMENT}"
    ctx.log(f"the PDF ({len(data)} bytes) carries the same barcode")
    label.close()

All runs

RunStatusQueuedDuration VersionTriggerBatch
#474 passed 2026-09-25 00:30:11 1s 3.0.0 group group: Python and TypeScript,…
#364 passed 2026-09-24 22:05:07 3s 3.0.0 group group: Freight extras
#349 passed 2026-09-24 20:41:19 3s 3.0.0 cli-adopted 3 tests (terminal)
#346 passed 2026-09-24 20:41:04 3s 2.1.0 cli-adopted 3 tests (terminal)
#343 passed 2026-09-24 20:40:49 3s 2.0.0 cli-adopted 3 tests (terminal)
#340 passed 2026-09-24 20:40:35 3s 1.1.0 cli-adopted 3 tests (terminal)
#337 passed 2026-09-24 20:40:21 3s 1.0.0 cli-adopted 3 tests (terminal)