Test data and accounts (account, data, dataFile, addMedia)

in Japanese(日本語)

Read accounts and test data from JSON files instead of writing them into the scenario source.

Functions

Function Description
account("[account1].password") -> String Returns a value of the account dataset (accounts.json).
account("[account1]", "password") -> String Same as above (dataset name and attribute name passed separately).
data("[order1].item") -> String / data("[order1]", "item") -> String Returns a value of the test data (data.json). Locations and overriding are the same as account.

A key is [datasetName].attributeName and is split at the last . ([a.b].x is attribute x of dataset [a.b]). The value can be passed straight to other commands.

A successful call records no step (it only returns a value).

Example

action {
    type("#login_id", account("[account1].id"))
    type("#login_password", account("[account1].password"))
}

Where the files go, and overriding

Attribute values must be strings (a dataset with a number or boolean attribute is rejected).

{
  "[account1]": { "id": "alice@example.com", "password": "..." },
  "[account2]": { "id": "bob@example.com",   "password": "..." }
}
Location Use
<project>/dataset/accounts.json, data.json Shared values kept in the project (values that may go into the repository)
~/.config/fleetest/dataset/<project name>/accounts.json, data.json Values for this Mac only (passwords and the like that stay out of the repository). The project name is the project folder's name

When the value is missing

A missing file, dataset or attribute, broken JSON, or a key without a . fails the step and aborts the scenario. The failure text lists every file it looked at and what was missing (never the value).

Dry-run

Dry-run and listing do not read the files and return the key string as is.

Using a file as it is (dataFile)

Data that does not fit keys and values (a CSV with many rows, a JSON body to send to an API, an image...) goes in the dataset folder as a file, and dataFile("file name") returns its location (a URL). Read it the usual Swift way.

let rows = (try? String(contentsOf: dataFile("csv/users.csv"), encoding: .utf8)) ?? ""
for line in rows.split(separator: "\n").dropFirst() {   // the first line is the header
    // ...
}

let body = (try? String(contentsOf: dataFile("api/new_order.json"), encoding: .utf8)) ?? ""
httpRequest("https://api.example.com/orders", method: "POST", body: body)

Adding a photo or video to the device (addMedia)

addMedia("file name") puts an image or video from the dataset folder into the device's photo library. Use it for screens that pick a photo (profile picture, attachment).

addMedia("img/avatar.png")

Masking secrets

Values are not masked by default. If you write type(account("[account1].password")), the password stays in the step description, the execution log and the report as it is.

Write redactAccountValues in ~/.config/fleetest/config.json on the Mac that runs the scenarios, and scenarios run on that Mac replace values returned by account() with *** in reports, execution logs and result JSON (data() is not masked). The setting of the Mac that runs the scenario is used (when you run on another Mac, write it on that Mac).

{
  "redactAccountValues": true
}

When masking is on: