Ready-to-use Code ExampleRegionKVTestingAsset

Multi-Region Smoke Test

Verifies in a single pass that several critical regions of a UI (logo, button, counter) render correctly. Writes the results in one KV.setAll call (every value is validated first, then all are saved together) and reports details on failure. Ideal for a CI-style sanity check.

Completion, parameter hints and type checking. Installation instructions and downloads are hosted on GitHub.

Copyable Example Code

You can paste this into the code editor; still verify target image, region, color, text, and timing values in your own device flow.

-- Multi-region smoke test
-- KV.setAll validates every value first, then saves them together

local checks = {
  { name = "logo",         region = Region(50, 50, 200, 80),    asset = "main_logo" },
  { name = "start_button", region = Region(400, 800, 280, 100), asset = "start_button" },
  { name = "counter",      region = Region(900, 100, 180, 60),  asset = "counter_background" },
}

Snap.screenRefresh()
local results = {}
local failures = {}

for _, check in ipairs(checks) do
  local found = check.region:find(Asset.image(check.asset))
  if found then
    results[check.name] = "OK"
  else
    results[check.name] = "FAIL"
    table.insert(failures, check.name)
  end
end

results["smoke_test_ts"] = DateTime.now():format("yyyy-MM-dd HH:mm:ss")
results["smoke_test_pass"] = (#failures == 0) and "true" or "false"
KV.setAll(results)

if #failures == 0 then
  toast("Smoke test PASS: every region OK")
  System.vibrate(50)
else
  local message = "Smoke test FAIL: " .. table.concat(failures, ", ")
  toast(message)
  System.noti(message)
end

Implementation and Adaptation Notes

  • Before running, replace sample values such as image names, text, colors, coordinates, and file paths with your own macro values.
  • For examples that use Region or coordinates, retest the target area on different resolutions and DPI values.
  • Tune mScore, timeout, and scan rate in a test macro first, then move the verified values into the production macro.
  • Avoid overly wide Region areas; a tighter area scans faster and reduces false matches.