Screenshots and evidence

Screenshots

Terminal
endia desktop screenshot -o evidence/desktop.png "$m"              # the whole screen
endia desktop screenshot --pid "$pid" -o evidence/window.png "$m"  # that process's largest visible window
endia desktop screenshot "$m" > shot.png                           # PNG on standard output

The screenshot is returned to your test; nothing is kept on the PC or in the machine. A machine's screen is 1024 by 768 unless its service asks for another size in the Compose file:

compose.yaml
services:
  client:
    image: lab/tools:1
    x-eastindia:
      screen: 1920x1080

The size takes effect when the machine is created, so change it and run compose up again to recreate the machines.

Collecting evidence and logs

Keep everything a failed run needs to be understood without rerunning it. The sample keeps it in evidence/<run>:

Evidence Command
Files the application wrote endia cp "$m:C:/ProgramData/MyApp" evidence/
Windows event log entries endia exec "$m" powershell -NoProfile -Command "Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='MyApp'} | Format-List TimeCreated,Message" > evidence/events.txt
The last 200 entries of the System event log, for later reading endia exec "$m" powershell -NoProfile -Command "Get-WinEvent -LogName System -MaxEvents 200 | Export-Csv C:\Windows\Temp\system.csv -NoTypeInformation", then endia cp "$m:C:/Windows/Temp/system.csv" evidence/
The processes running endia process ls "$m" (process ID, parent, session, user, start time, name)
The visible windows endia desktop windows "$m"
A window's elements and values endia desktop inspect "$m" "$pid"
Screenshots endia desktop screenshot -o ...
Processor, memory, disk and network use endia stats --no-stream "$m"
The machine's settings, addresses and ports endia inspect "$m"
A main process's output endia compose -p "$run" logs <service>, for a service with a command
Collect the evidence before compose down

Removing a machine deletes its disk.

SSH access

Every machine runs an OpenSSH server on port 22, because the root image installs one. To use it from your test, publish the port and give testuser your public key:

compose.yaml
services:
  app:
    image: lab/tools:1
    ports:
      - "12222:22"
Terminal
ssh-keygen -q -t ed25519 -N "" -f ./id && cp ./id.pub ./authorized_keys
endia exec "$m" cmd /c "mkdir C:\Users\testuser\.ssh"
endia cp ./authorized_keys "$m:C:/Users/testuser/.ssh/"
endia exec "$m" icacls C:\Users\testuser\.ssh\authorized_keys /inheritance:r /grant "testuser:F" /grant "SYSTEM:F"
ssh -i ./id -p 12222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null testuser@host.docker.internal whoami

OpenSSH refuses a key file that other accounts may change, hence the icacls line. A new machine has new host keys, so the test should not record them. Most tests need no SSH, because exec and cp run programs and copy files without keys.

Cleaning up

Terminal
endia compose -p "$run" down -v
endia ps -a        # nothing of the run is left

down shuts each machine down, removes it with its disk, and removes the fleet's networks; -v also removes its named volumes. Images stay, for the next run. down gives Windows up to stopTimeoutSeconds (120 seconds by default) to shut down, then turns the machine off; -t <seconds> changes the wait for one command.

Sample project

The Windows app testing sample holds a Windows service, a desktop program and a tray program, with image recipes, a Compose file and a test script, run-tests.sh. The script does all of the above against the three programs:

  1. publishes the programs for Windows with dotnet publish -r win-x64;
  2. builds the tools layer and sample/server:1;
  3. starts the fleet from compose.yaml under a project name of its own, with a trap that removes it;
  4. checks the service: Windows reports it running, and the client reaches it by name;
  5. drives the desktop program by element, then by keyboard and mouse, and checks the file it saved each time;
  6. starts the tray program and checks its process and the file it writes every five seconds;
  7. collects the files, event-log entries, process list, screenshots and resource use into evidence/<run>.

It needs endia with a working context, the .NET 10 SDK and jq. The service must hold a root image tagged lab/win11:base, which the sample's tools recipe builds on. The script prints PASS: evidence in evidence/<run>, or FAIL: with the check that failed and exits with 1.