Skip to content

Feature Request: Screensaver-Based Automated Testing #6

@sl5net

Description

@sl5net

Maybe want:

  1. Detect Inactivity: Automatically detect when the mouse and keyboard have been idle for a specified period (e.g., 3 minutes).
  2. Start Testing: When inactivity is detected, start the automated testing process (which involves running pyautogui on the host).
  3. Pause Testing on Activity: Immediately pause the testing process if any mouse or keyboard activity is detected.
  4. Log Results: Log the results of the tests to a file.
  5. Provide Audio Feedback: Use espeak-ng to provide audio feedback on the status of the tests.
  6. Run pyautogui on the Host: Run the pyautogui script directly on the host machine (instead of inside the Docker container).

Here's a possible approach to achieve this:

1. Detect Inactivity (Host - Linux Specific):

You can use xprintidle command to detect inactivity. You may need to install it first

sudo apt-get install xprintidle

or

sudo pacman -S xprintidle

Then you can check the inactivity

xprintidle

This command will print the time, in milliseconds, that the system has been idle.

2. Main Script on the Host:

#!/bin/bash

# Settings
IDLE_TIME=180000    # 3 minutes in milliseconds (3 * 60 * 1000)
LOG_FILE="$HOME/test_results.log"
PY_SCRIPT="$HOME/path/to/your/script.py" #Set your right path here
SPEAK_CMD="espeak-ng"  # Assuming espeak-ng is in your PATH

# Function to speak a message
speak() {
    $SPEAK_CMD "$1" &
}

# Start with a clean log file
> "$LOG_FILE"

# Function to run the tests
run_tests() {
    speak "Starting automated tests"
    echo "Starting tests at $(date)" >> "$LOG_FILE"

    # Run your python script and append output
    python3 "$PY_SCRIPT" >> "$LOG_FILE" 2>&1

    TEST_EXIT_CODE=$?
    if [ $TEST_EXIT_CODE -eq 0 ]; then
        speak "Automated tests completed successfully"
        echo "Tests completed successfully at $(date)" >> "$LOG_FILE"
    else
        speak "Automated tests failed with code $TEST_EXIT_CODE"
        echo "Tests failed with code $TEST_EXIT_CODE at $(date)" >> "$LOG_FILE"
    fi
    speak "Stopping automated tests"
}

# Main loop
while true; do
    idle_time=$(xprintidle)
    if [ "$idle_time" -gt "$IDLE_TIME" ]; then
        run_tests
        # Sleep for sometime to avoid constantly triggering the tests.
        sleep 60 
    fi
    sleep 10 # Check for idle every 10 seconds.
done
  • It uses a loop to constantly check the idle time using xprintidle.
  • If the idle time exceeds the specified threshold (IDLE_TIME), it runs the test suite.
  • It logs the output and exit code of the test suite to a log file.
  • It uses espeak-ng to provide audio feedback.
  • All configuration is in the first 4 lines, change the paths there
  • To stop, use ctrl + c (and improve this with better method)

Remember that it does NOT pause the tests as you asked. Since the sleep command makes it work correctly I dont see how a pause command should improve it, you may want to run all the test

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions