Adding your own features

in Japanese(日本語)

When the built-in commands are not enough, you can add features inside your own project without modifying fleetest itself. There are five main ways to do it. All of them are written in scenarios (.swift) or in files of your test project.

What you want How Details
Bundle steps you repeat A Swift function (custom command) Custom commands
Run something the DSL has no command for, as one step procedure { } Descriptors
Use test data or talk to external servers account() / data() / dataFile() / httpRequest Test data and accounts, HTTP request
Use a library or share common code Add a dependency to Package.swift Creating a test project
Prepare a database or stub server around a run compose.yaml and start/end scripts Services the app depends on and Running scripts before and after a run on this page

1. Bundle steps into functions

Steps that come up again and again (logging in, preparing a starting state, routine operations on a screen) go into plain Swift functions. Adding @FTCommand("description") lists the function in the command index (ft_dsl_commands), so the AI assistant that writes scenarios reuses it instead of writing the same steps by hand again. The index holds only the name, call shape and summary, and is returned only to the AI assistant on this Mac (nothing goes outside, and the function does not become runnable through MCP).

@FTCommand("Log in with email and password and go to the home screen")
func login(user: String, password: String) {
    tap("#login_email")
    type(user)
    tap("#login_password")
    type(password)
    tap("#btn_login")
    exist("#home_title")
}

Helpers that work on a grabbed element can be written in extension FTElement, so they chain like select("#x").tapAndConfirm("#y").

Common uses:

The report lists the individual commands inside the function, not the function name. To show them as one unit, wrap them in group("name") { }.

2. Run code the DSL has no command for, as one step

The body of procedure("description") { ... } is a synchronous closure (() throws -> Void); await cannot be written in it. DSL commands can be called inside, and the steps inside are recorded with a [description] prefix and folded into one step in the report (.md); the result JSON keeps all of them. Throwing inside it stops the scenario, just like a failed command.

procedure("Create a test order through the API") {
    try seedTestOrder()   // a synchronous function you wrote (it can call DSL commands)
}

To verify values that do not depend on the screen (API responses, computed values), use the thisIs family (for example response.status.thisIs(201)).

3. Use test data and talk to external servers

Function Use it for
account() / data() Reading accounts and input values from JSON. Keep passwords in this Mac's settings, not in the repository
dataFile() Using CSV, JSON, images and other files as files
addMedia() Adding photos and videos to the device's photo library (not possible on a physical iOS device)
httpRequest / fleetestURLSession Creating test data through an API, cleaning up, reading server-side state
writeRunMemo / readRunMemo Passing values prepared in beforeRun() / beforeAll() to other scenarios

Common uses:

By default, scenarios cannot reach anything outside the Mac. Allow the destinations in this Mac's settings first (Network access from scenarios).

4. Add libraries and shared code

External Swift packages (one-time password generation, cryptography, JSON handling, ...) and your own targets shared between several test projects can be imported from scenarios once you list them in two places of Package.swift: dependencies: and fleetestScenarioDependencies. See "Adding dependencies for your scenarios" in Creating a test project.

Building the added dependencies (including macros and build plugins) runs outside the sandbox. Add only packages you trust.

If a shared helper calls withRunLock, keep at least one call under the project's scenarios/ folder: the lock server starts only when such a call is found there (not in _disabled/, comments or strings), and a call that exists only in another target or package fails at once.

Running scripts before and after a run

To prepare data around a run (load a seed, call a setup API) and clean it up afterwards, put scripts in the test project's workspace. Servers, databases and stubs are not started by a script: declare them in scripts/compose.yaml (Services the app depends on).

File When it runs
TestProjects/<project>/workspace/scripts/run-setup.sh At the start of the run, before any device is touched
TestProjects/<project>/workspace/scripts/run-teardown.sh At the end of the run

Feeding results into your own systems

What you cannot add

What you cannot do Why / what to do instead
New kinds of operations on the device, or new information read from it These are driver and bridge features, so fleetest itself has to change. Only what can be written by combining built-in commands is in your hands
Write arbitrary files or read secrets in your home folder from a scenario Scenarios run inside a sandbox. Write through TestLog.directoryForLog / directoryForTemp
Start other apps or use adb / simctl directly from a scenario fleetest itself performs a fixed set of operations on the scenario's behalf. adb can be opened with allowDirectAdb in this Mac's settings (see Sandbox defaults)
Run a custom command through ft_batch ft_batch only runs built-in commands. Write custom commands in a scenario .swift file and run that
Read shell environment variables (tokens and so on) in a scenario Scenarios only receive the variables fleetest uses. Put secrets in this Mac's account() files