Custom commands
When the built-in DSL commands don't cover a repeated step in your own app (log in, a shared
precondition, a custom multi-finger gesture assembled with gesture),
write it as a plain Swift function under scenarios/.
func login(user: String, password: String) {
type("#login_email", user)
type("#login_password", password)
tap("#btn_login")
exist("#home_title")
}
Call it like any other step inside a scene:
scene(1, "Sign in") {
action {
login(user: account("[user1].id"), password: account("[user1].password"))
}
}
Shareable values go in the project's dataset/accounts.json; passwords go in this Mac's ~/.config/fleetest/dataset/<project name>/accounts.json (Test data and accounts).
Listing it in the command index (@FTCommand)
A plain function like the one above works, but it doesn't show up anywhere — an agent writing
scenarios with the MCP server (ft_dsl_commands) or the fleetest-scenario skill has no way to
know it exists, so it never reuses it and may write the same steps out by hand instead. Mark the
function with @FTCommand("summary") to list it in the command index:
@FTCommand("Logs in with email and password and waits for the home screen")
func login(user: String, password: String) {
type("#login_email", user)
type("#login_password", password)
tap("#btn_login")
exist("#home_title")
}
fleetest api dsl-commands --project <name> and the MCP tool ft_dsl_commands (called with
project: — when omitted it resolves to your only project, then the machine setting's default project, then project1; if none of these decides, only the built-in commands are returned) now list it alongside the built-in commands, tagged [project: file:line] so its origin is
clear. An agent asked to write a new scenario is told to prefer it over inventing similar steps
by hand, because it encodes your team's own conventions (e.g. what "logged in" means for your
app).
@FTCommand is a marker only — it generates no code. The function behaves exactly the same
whether or not it's marked; marking it only makes it discoverable.
The index lists only the function's name, call shape, summary, and file and line — not its body.
The MCP server builds the list by reading the scenario sources on this Mac and returns it only to
the AI assistant connected to it (nothing is exposed on the network). Being listed does not make
the function runnable through MCP (see ft_batch under "Rules" below). The summary is passed to
the AI assistant, so write only what the function does.
extension FTElement methods
A helper that acts on a grabbed element can be written as an FTElement extension instead of a
free function, so it chains the same way built-in commands like .textIs(...) do:
extension FTElement {
@FTCommand("Taps this element and checks that the next element appears")
@discardableResult
func tapAndConfirm(_ next: String) -> FTElement {
tap()
return exist(next)
}
}
select("#btn_add_to_cart").tapAndConfirm("#txt_cart_badge")
The index marks this kind of entry so a reader knows it's called as select(...).tapAndConfirm(...),
not as a free function.
Rules
@FTCommandcan only be attached to a top-level function, or a method inside anextension(anextension FTElement { }block, most commonly). A method inside aclassorstructbody is rejected at compile time — write it as a top-level function or move it into an extension.- The argument is one non-empty string literal:
@FTCommand("what it does"). - Giving it the same name as a built-in DSL command (
tap,type, …) is flagged as a warning in the index reply — pick a different name, since a reader can't tell which one a call means. - A
private/fileprivatefunction marked@FTCommandcannot actually be called from a different scenario file, so it is not listed as a command — instead the index reply carries a warning naming it. Drop the access modifier if it should be reusable from other scenario files, or drop@FTCommandif it's genuinely private to the file. - Reports and execution logs show the commands inside your helper, one step each — not the helper's name. A failure points at the inner command's line.
- The index lists your helpers; it doesn't run them.
ft_batch(the MCP tool that executes DSL lines one at a time without saving a scenario) can only run built-in commands. Call your@FTCommandfunctions from the scenario.swiftfile instead.