Scenarios

1file
1figure
5min read
Sheet 11 of 47 · Scenarios

Filesscenarios/island-menu.json

Filescenarios/island-menu.jsonA scenario is a list of steps for one bot, with parallel groups for more. Each step either does something, like joining, typing a command or clicking a slot, or checks something, like a menu being open or a line showing up in chat. A step that does not pass fails the run and the report says which one and why.

A recorded scenario on the Scenarios page, each step written as a sentence.
The Scenarios page: the file list on the left, nine steps written as sentences in the middle, the run panel on the right

A first file

Scenarios are JSON or YAML. The same file works as either.

scenarios/island-menu.json
{
  "name": "Island menu",
  "bot": "TestBotA",
  "steps": [
    { "do": "join" },
    { "do": "chat", "c": "/is" },
    { "do": "expectWindow", "title": "(?i)island", "timeout": 4000 },
    { "do": "click", "custom": "(?i)members" },
    { "do": "parallel", "bots": 3, "pattern": "Test_{n}", "steps": [{ "do": "join" }, { "do": "quit" }] },
    { "do": "quit" }
  ]
}

TestBotA joins, types /is, waits up to four seconds for a menu whose title matches (?i)island, and clicks the item whose name matches (?i)members. Then three more bots named from the pattern Test_{n} join and quit at the same time, and TestBotA quits.

The steps

join, quit, chat, click, close, wait, goto, action, expectWindow, expectNoWindow, expectTitle, expectChat, expectNoChat, expectSlot, expectDialog, answerDialog, assertPos, parallel, loop, group, if, set, log, call, include, expectServer, server, assertServer, rcon, file, checkpoint, and for pictures takeover, frame, key, screenshot, record and release.

Every step and its parameters are on the Step Reference. The tool prints the same reference on one page:

java -jar IgniteTestTool.jar guide

Window titles, item names, lore and chat are matched as written and with small caps read as plain letters, so title: zombies finds a menu called ᴢᴏᴍʙɪᴇꜱ │ ᴀʀᴇɴᴀꜱ.

Server-side checks

A bot cannot see health, velocity, PDC, effects, AI or blocks the way the server holds them. Steps that ask the server need the server agent.

steps:
  - do: server                 # any agent endpoint, "as" keeps the answer or one field of it
    path: dummy
    near: ${bot}
    dx: 2.5
    health: 100
    field: id
    as: dummy
  - do: action
    action: useHold
    ms: 2000
  - do: assertServer           # polls until it passes or the timeout runs out
    path: entity
    id: ${dummy}
    near: ${bot}
    field: health              # dotted path, [n] for list items, pdc.lightfall:mob_level works
    op: eq                     # eq, ne, gt, ge, lt, le, contains, matches, exists, absent
    value: 92
    delta: 0.01
    timeout: 1500
  - do: rcon
    cmd: class info ${bot}
    expect: arc 20             # a regex the answer has to match
finally:                       # runs after the steps, whatever failed before
  - do: server
    path: dummy/clear
  • name is the step label, so a player goes to the agent as player: and a packet to waitFor as packet:. For an agent endpoint that takes name, action or cmd itself (snapshot, tick, exec), server and assertServer take params: {name: arena, action: freeze}, which goes out as written.
  • Config keyinventory.sizeConfig keyeffects.lengthfield can count: inventory.size or effects.length is the number of entries, unless the object has a field of that name.
  • A coordinate can be relative, like in a command: x: "~" is the block the bot stands in, "~2" and "~-1" count from it. This works for every bot action with x, y, z (goto, place, dig, activate, look) and for server and assertServer, so path: block can look next to the bot.

Waiting

  • timeout on an action step reaches actions that wait on their own (waitFor, jumpApex, airJump), so their own message explains a failure. The step gives them two extra seconds before it gives up.
  • action takes as and field too, for example action: mark, as: seen, field: packets, then since: ${seen} later. See Precise Testing.
  • expectSlot with absent: true passes once no slot of the open window matches, and fails with the slot that still does.

Variables

  • Strings can use ${var}. Named groups in an expectChat regex become variables, and ${match} holds the whole match. loop sets ${i}, parallel sets ${n} and ${bot}, expectSlot sets ${slot}.
  • set does arithmetic with calc: {do: set, var: left, calc: "${money} - 2 * ${price}"}. Numbers, + - * / % and brackets. A whole result stays whole, so 350 and not 350.0.

Branches, retries and cleanup

if picks a branch with any other step as its check. A check that does not pass is an answer, not a failure:

- do: if
  check: {do: expectSlot, item: diamond, timeout: 500}
  then:
    - {do: click, item: diamond}
  else:
    - {do: rcon, cmd: "give ${bot} diamond"}
  • loop with until: pass tries until one iteration gets through and fails when none of times does, for anything that rolls dice. The failed tries do not fail the scenario.
  • Any step can be "optional": true, so a failure is logged but does not stop the run. A failure inside an optional group, loop or parallel ends that block only.
  • A failure inside an optional block or one of the until: pass tries is marked optional: like a failed optional step, and JUnit and the short report treat it the same way.
  • finally runs after any failure and to its end: a call, group or loop inside it runs all of its steps, even after one of them failed.

Files on the server

file works on a file in the server folder:

- {do: file, path: plugins/Shop/config.yml, replace: "^price: .*$", with: "price: 20"}

replace is a regex per line and the new text goes in as written. write and append take whole content, expect: <regex> waits until the file holds something (timeout, and as keeps the content), and restore: true puts it back. Whatever a scenario changed is put back when it ends, also after a failure. keep: true on the edit leaves it. A path outside the server folder is refused.

Joining

  • join on a bot that is already online, because an earlier run failed before its quit, lets go of its keys, closes its menu and counts chat from that moment, so since: scenario never reads an older run.
  • join with fresh: true resets the player through the agent once it is in: full health and hunger, no items, effects or levels, the server's default game mode. Health, hunger and items live in playerdata, so without it a scenario that takes eight hearts passes twice and kills its bot the third time. freshPlayers: true at the top of the file does it for every join, and fresh: false on one step leaves that bot alone.
  • join takes account: <name or uuid> to join with a saved premium account. The scenario's bot has to be that account's Minecraft name, and confirmHost: true approves a remote host the first time. See Premium Accounts.

Where to go next

Loading the index

Enter openUp Down moveEsc close