Frontend Example (Operator UI)
The upstream frontend_example.py — start StationServer on port 4444, launch the browser Operator UI, and run the same test five times in a row with a DUT ID prompt between runs.
Last updated · Verified with OpenHTF 1.6.1
The minimal Operator UI setup: a station server, the browser launcher, and a loop that runs the test repeatedly so the station stays up between units. Based on examples/frontend_example.py.
import openhtf as htf
from openhtf.output.servers import station_server
from openhtf.output.web_gui import web_launcher
from openhtf.plugs import user_input
from openhtf.util import configuration
CONF = configuration.CONF
@htf.measures(htf.Measurement('hello_world_measurement'))
def hello_world(test):
test.logger.info('Hello World!')
test.measurements.hello_world_measurement = 'Hello Again!'
def main():
CONF.load(station_server_port='4444')
with station_server.StationServer() as server:
web_launcher.launch('http://localhost:4444')
for _ in range(5):
test = htf.Test(hello_world)
test.add_output_callbacks(server.publish_final_state)
test.execute(test_start=user_input.prompt_for_test_start())
if __name__ == '__main__':
main()python frontend_example.pyThe default browser opens http://localhost:4444, shows the station, and prompts for a DUT ID. Enter one in the browser or the console; the phase runs, the result appears in the history panel, and the prompt returns for the next unit. After five units the server stops.
What it shows
CONF.load(station_server_port='4444')The server reads its port from configuration. Default 0 picks a free port, which is fine for a bench but not for a bookmarked URL. Configuration →
with station_server.StationServer() as serverStarts the Tornado server in a background thread and stops it on exit. Optional history_path shows past JSON records in the UI. Operator UI →
web_launcher.launch(url)Opens the URL in the default browser. Omit it on a kiosk that already points a browser at the station.
server.publish_final_stateAn output callback that pushes the finished record to the UI's history. Without it the UI only shows the live test.
for _ in range(5)execute() runs one DUT. A production station loops forever (while True) and lets the operator abort with Ctrl-C.
Production notes
- The UI is served on
localhostwithout authentication. To reach it from another machine bind the host's IP and firewall accordingly, or use the multi-station dashboard to list stations on the LAN. - For HTTPS, user accounts, multiple tests per station and searchable history across stations, TofuPilot's Operator UI runs the same script unchanged.
- If the page is blank, see the FAQ.
Next
Ignore early-canceled tests
The upstream ignore_early_canceled_tests.py example — subclass OutputToJSON to skip writing records for tests aborted (Ctrl-C) before an operator entered a DUT ID, using default_dut_id.
All the things
The upstream all_the_things.py example — configuration-bound plugs, a frontend-aware plug, a monitor, htf.Dimension, attachments, templated limits with with_args, test metadata, and three output callbacks (pickle, JSON, console) in one script.