Skip to main content

CLI testing

SHAFT provides terminal, Docker, SSH, and file actions with the same reporting model used by browser and API tests.

Prerequisites​

  • A SHAFT Maven project. Install SHAFT walks through generating one.
  • The command you test available to the user that runs Maven. For Docker actions, a running Docker daemon. For SSH actions, a reachable host, user, and key, with secrets injected by CI rather than committed.

Open the terminal actions reference for executable examples and result handling.

First useful command test​

Use CLI actions when the product behavior depends on a process, file, Docker command, deployment script, or remote shell state. Start with a harmless local command and assert on the captured output:

SHAFT.CLI terminal = new SHAFT.CLI();
String output = terminal.performTerminalCommand("echo Hello SHAFT");

SHAFT.Validations.assertThat().object(output).contains("Hello SHAFT");

Run the test with Maven:

mvn test

The command, output, and validation status are attached to the same Allure evidence flow as the rest of the suite.

Verify​

  • Maven reports the test as run and passed.
  • The Allure report shows the command, its captured output, and the contains("Hello SHAFT") validation.
  • To prove the assertion is live, change the expected text and rerun. The validation fails with the captured output attached.

Troubleshooting​

SymptomCheck
Command works locally but fails in CIUse absolute paths or set the working directory explicitly.
Docker command times outVerify Docker is running before tuning command timeout properties.
SSH command cannot connectValidate host, user, key, network route, and CI secret injection.
File assertion fails on WindowsPrefer forward slashes in Java paths; Java resolves them on Windows.