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
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
- site = Freight(page, ctx).sign_in()
- site.open(f"ops/shipments/{SHIPMENT}/")
- ⏱ Timed phase: open the label (a new tab)
- with page.expect_popup() as popup:
- 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"))
- ⏱ Timed phase: 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
- ⏱ Timed phase: 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()
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
| Run | Status | Queued | Duration | Version | Trigger | Batch |
|---|---|---|---|---|---|---|
| #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) |