Testing dialogs
Answer dialogs in headless tests, without real windows.
janelkit-desktop System services: native file and message dialogs, and the clipboard. It adds no interface controls. pip install janelkit-desktopAnswer the dialog the user would see
Importing janelkit-desktop adds two methods to the MountedApp of janelkit.inspect, so tests can answer dialogs without real windows. Your application imports the package, so the methods are there in its tests. This test targets the example in Overview.
| Method | What it does |
|---|---|
| app.dialogs() | Open dialogs, oldest first. |
| app.answer_dialog(result) | Answers the most recent dialog: a path for file and folder dialogs, True to accept or False to cancel. |
from janelkit import inspect
def test_cancel_keeps_the_text():
with inspect.mount("src/App.janel") as app:
app.find("textarea").type("Hello")
app.find(text="Open…").click()
app.answer_dialog(False) # the user cancels
assert app.find("textarea").value == "Hello"CopyHow it works
- The click opens a real dialog object, without showing a native window in a headless test.
- answer_dialog(False) cancels it, so open_file returns None and the text stays.
Which dialog is open
dialogs.pending() lists the dialogs open now, and dialogs.kind(d) says the type of one: "MessageDialog", "FileDialog" or "FolderDialog". Use them to check that the right dialog opened before answering it.
Examples
In the JanelKit repository, apps/examples/files chooses a folder, apps/challenges/gestor asks for confirmations, and apps/challenges/hoja opens and saves CSV files and uses the clipboard.
English documentation based on the JanelKit source. For additional details, browse the source docs ↗.