group, procedure, beforeEach, afterEach, beforeAll, afterAll, setUpDevice, tearDownDevice

in Japanese(日本語)

Structuring commands: grouping steps in the report, running arbitrary Swift as one step, and per-test setup/teardown.

Functions

function description
group("name") { } Prefixes the steps inside with [name] in the report. Execution and failure semantics are unchanged.
procedure("description") { ... } Names a group of steps as one procedure. You can call commands inside. The report shows only the procedure "description" line and folds the inner steps that passed (a failed step is still shown). A thrown error fails the scenario.
func beforeEach() Defined on the test class; runs automatically before each @Test.
func beforeAll() Defined on the test class; runs once per run, per class, before any scenario of that class on any device (order: beforeAll() → setUpDevice() → beforeEach() → body → afterEach()). Other devices that pick up a scenario of that class wait until it finishes. Share what it prepares with writeRunMemo / readRunMemo.
func setUpDevice() Defined on the test class; runs at most once per run, per device, per class — before beforeEach() of the first scenario of that class that lands on the device. Per-device preparation. It can read the run memo (readRunMemo) but cannot write it.
func afterEach() Defined on the test class; runs automatically after each @Test, including after a failure.
func tearDownDevice() Defined on the test class; runs once, after the device has finished all of its scenarios in the run (if at least one scenario of that class ran on the device). Use it to clean up after setUpDevice().
func afterAll() Defined on the test class; runs once per run, per class, after every device has finished the run (after each device's tearDownDevice()), in a process of its own. It runs only when at least one scenario of that class ran in the run. It runs whether or not beforeAll() passed, so use it for run-wide cleanup (for example deleting the test data you created). It can read the run memo. It does not run in an interrupted run. The result goes to the execution log and a report, and does not count toward pass/fail.

Example

@TestClass
class LoginFlow {
    func beforeEach() {
        irregularHandler("#promo_modal", dismiss: "#btn_promo_close")
    }

    func afterEach() {
        terminateApp()
    }

    @Test("login succeeds with valid credentials")
    func S0010() {
        scenario {
            group("prepare test data") {
                procedure("seed the account via API") {
                    let response = httpRequest("https://api.example.com/test-accounts", method: "POST",
                                               body: #"{"email":"user@example.com"}"#)
                    response.status.thisIs(201)
                }
            }
            scene(1, "log in") {
                action {
                    launchApp()
                    type("#email", "user@example.com")
                    type("#password", account("[account1].password"))
                    tap("#login_btn")
                }.expectation {
                    exist("#welcome_text")
                }
            }
        }
    }
}

Notes