How do I run Fume tests on a schedule (e.g., twice daily) and post results to Slack?
Automated QA Testing Platforms

How do I run Fume tests on a schedule (e.g., twice daily) and post results to Slack?

9 min read

Running Fume tests on a schedule and automatically posting results to Slack is a powerful way to keep your team informed and catch issues early. Whether you want to run tests twice daily or on a more custom cadence, the core building blocks are:

  • A way to run Fume from a script/CLI
  • A scheduler (cron, GitHub Actions, CI, or serverless)
  • A Slack integration (webhook or Slack app)

Below is a step‑by‑step guide that covers common setups and best practices so you can choose the approach that fits your stack.


1. Prerequisites

Before you set up scheduled Fume tests and Slack notifications, you should have:

  • A working Fume test suite (e.g., fume.config.* and tests passing locally).
  • Access to the environment where tests will run:
    • A CI system (GitHub Actions, GitLab CI, CircleCI, etc.) or
    • A server/VM where you can configure cron or
    • A serverless platform that supports scheduled triggers.
  • A Slack workspace where you can:
    • Create an Incoming Webhook or
    • Use a Slack Bot token (more advanced usage).

For the rest of this guide, we’ll assume you can run tests via a command such as:

fume test
# or, if you use npm/yarn:
npm run fume:test

Replace with your own command wherever relevant.


2. Creating a Slack webhook for posting results

The easiest way to post Fume test results to Slack on a schedule is via an Incoming Webhook.

2.1 Create an Incoming Webhook

  1. Go to: https://my.slack.com/apps

  2. Search for Incoming WebHooks and click Add.

  3. Choose the workspace and channel where you want Fume test results to appear.

  4. Click Add Incoming WebHooks integration.

  5. Copy the generated Webhook URL, which will look like:

    https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
    

Store this URL securely as an environment variable, for example:

export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..."

In CI systems, store this in the platform’s Secrets or Environment Variables settings, not directly in code.


3. Basic script to run Fume tests and send Slack notification

To connect Fume test execution with Slack, you can use a simple shell script (or a Node/Python script if you prefer). The script:

  • Runs Fume tests.
  • Captures the exit code and/or summary.
  • Sends a formatted message to Slack via the webhook URL.

3.1 Example Bash script

Create a file, for example run_fume_and_notify.sh:

#!/usr/bin/env bash
set -euo pipefail

# Configuration
FUME_COMMAND="${FUME_COMMAND:-fume test}"
SLACK_WEBHOOK_URL="${SLACK_WEBHOOK_URL:?SLACK_WEBHOOK_URL is required}"

# Run Fume tests, capture output and exit code
echo "Running Fume tests..."
TEST_OUTPUT_FILE=$(mktemp)
set +e
$FUME_COMMAND &> "$TEST_OUTPUT_FILE"
EXIT_CODE=$?
set -e

TEST_OUTPUT=$(cat "$TEST_OUTPUT_FILE")
rm "$TEST_OUTPUT_FILE"

# Prepare summary
if [ $EXIT_CODE -eq 0 ]; then
  STATUS="SUCCESS"
  COLOR="#2eb886"  # green
else
  STATUS="FAILURE"
  COLOR="#e01e5a"  # red
fi

# Truncate output for Slack (optional safety)
MAX_CHARS=3500
SHORT_OUTPUT="${TEST_OUTPUT:0:$MAX_CHARS}"

# Build Slack payload
PAYLOAD=$(cat <<EOF
{
  "attachments": [
    {
      "color": "$COLOR",
      "title": "Fume test run: $STATUS",
      "fields": [
        {
          "title": "Command",
          "value": "$FUME_COMMAND",
          "short": false
        },
        {
          "title": "Exit Code",
          "value": "$EXIT_CODE",
          "short": true
        }
      ],
      "text": "Latest scheduled Fume test run completed.\n\`\`\`\n$SHORT_OUTPUT\n\`\`\`",
      "footer": "Fume Scheduled Tests",
      "ts": $(date +%s)
    }
  ]
}
EOF
)

# Send to Slack
curl -X POST -H 'Content-type: application/json' --data "$PAYLOAD" "$SLACK_WEBHOOK_URL"

# Exit with the same code as the tests to allow CI to fail the job if needed
exit $EXIT_CODE

Make the script executable:

chmod +x run_fume_and_notify.sh

This script is generic: it can be triggered by cron, GitHub Actions, or any scheduler. It posts a status summary plus a truncated log of the Fume test run to Slack.


4. Scheduling Fume tests with cron (e.g., twice daily)

If you have a server or VM that’s always on, cron is a simple way to schedule Fume tests and Slack notifications.

4.1 Set environment variables

In the user’s shell or a secure environment file:

export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/..."
export FUME_COMMAND="fume test"

4.2 Edit crontab

Run:

crontab -e

To run Fume tests twice daily at 9:00 and 17:00, add:

0 9,17 * * * /path/to/run_fume_and_notify.sh >> /var/log/fume_cron.log 2>&1

Explanation:

  • 0 9,17 * * * = at minute 0 of 9:00 and 17:00 every day.
  • Adjust times as needed (24-hour format).

If you need more frequent schedules, for example, every 6 hours:

0 */6 * * * /path/to/run_fume_and_notify.sh >> /var/log/fume_cron.log 2>&1

Cron will now run your Fume tests on schedule and send results to Slack.


5. Running Fume tests on a schedule using GitHub Actions

If your project is on GitHub, using GitHub Actions makes it easy to run scheduled Fume tests and post results to Slack without managing servers.

5.1 Store your Slack webhook securely

In your GitHub repository:

  1. Go to Settings → Secrets and variables → Actions → New repository secret.
  2. Add a secret named SLACK_WEBHOOK_URL with your Slack webhook URL.

5.2 Add a GitHub Actions workflow

Create .github/workflows/fume-scheduled-tests.yml:

name: Scheduled Fume Tests

on:
  schedule:
    # Twice daily at 09:00 and 17:00 UTC
    - cron: "0 9,17 * * *"
  workflow_dispatch: {}  # Allow manual trigger

jobs:
  run-fume-tests:
    runs-on: ubuntu-latest

    env:
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Install dependencies
        run: npm ci

      - name: Run Fume tests and notify Slack
        run: |
          chmod +x ./run_fume_and_notify.sh
          ./run_fume_and_notify.sh

Notes:

  • Adjust node-version and npm ci to match your project.
  • Ensure run_fume_and_notify.sh is committed to your repo or generated in an earlier step.
  • The cron time is in UTC; if you want twice daily in your local timezone, convert appropriately.

The workflow will run your Fume tests twice daily, and every run will post a formatted message to your Slack channel.


6. Using other CI systems for scheduled Fume tests

The core pattern is the same across CI platforms: scheduled triggers + environment variable for SLACK_WEBHOOK_URL + script invocation.

6.1 GitLab CI

In .gitlab-ci.yml:

stages:
  - test

fume_scheduled_tests:
  stage: test
  image: node:20
  script:
    - npm ci
    - chmod +x ./run_fume_and_notify.sh
    - ./run_fume_and_notify.sh
  only:
    - schedules

Then, in GitLab:

  1. Go to CI/CD → Schedules.
  2. Create a schedule with a cron like 0 9,17 * * * for twice daily runs.
  3. Set SLACK_WEBHOOK_URL in Settings → CI/CD → Variables.

6.2 CircleCI

In .circleci/config.yml:

version: 2.1

workflows:
  version: 2
  fume_scheduled_workflow:
    triggers:
      - schedule:
          cron: "0 9,17 * * *"
          filters:
            branches:
              only:
                - main
    jobs:
      - fume_scheduled_tests

jobs:
  fume_scheduled_tests:
    docker:
      - image: cimg/node:20.0
    environment:
      SLACK_WEBHOOK_URL: $SLACK_WEBHOOK_URL
    steps:
      - checkout
      - run: npm ci
      - run: chmod +x ./run_fume_and_notify.sh
      - run: ./run_fume_and_notify.sh

Set SLACK_WEBHOOK_URL in CircleCI’s project environment variables.


7. Customizing Slack messages for better visibility

To make scheduled Fume test notifications more useful, consider:

7.1 Adding environment or branch information

In your script, you can inject context:

ENV_NAME="${ENV_NAME:-production}"
BRANCH_NAME="${BRANCH_NAME:-main}"

And update the Slack payload:

"fields": [
  {
    "title": "Environment",
    "value": "$ENV_NAME",
    "short": true
  },
  {
    "title": "Branch",
    "value": "$BRANCH_NAME",
    "short": true
  },
  {
    "title": "Exit Code",
    "value": "$EXIT_CODE",
    "short": true
  }
],

Set these environment variables in your CI or cron environment.

7.2 Only posting on failures

If your Slack channel is busy, you might want notifications only when Fume tests fail. Modify the script:

if [ $EXIT_CODE -eq 0 ]; then
  echo "Fume tests passed. Not sending Slack notification."
  exit 0
fi

Place this right after capturing EXIT_CODE and TEST_OUTPUT.


8. Advanced: Using a Node or Python script instead of Bash

If you want richer formatting or more logic, you can implement the Slack posting in a higher-level language.

8.1 Node.js example

Install axios:

npm install axios

Create run_fume_and_notify.js:

const { exec } = require('child_process');
const axios = require('axios');

const FUME_COMMAND = process.env.FUME_COMMAND || 'fume test';
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL;

if (!SLACK_WEBHOOK_URL) {
  console.error('SLACK_WEBHOOK_URL is required');
  process.exit(1);
}

exec(FUME_COMMAND, { maxBuffer: 1024 * 1024 }, async (error, stdout, stderr) => {
  const exitCode = error ? error.code || 1 : 0;
  const output = (stdout + '\n' + stderr).trim();
  const maxChars = 3500;
  const shortOutput = output.slice(0, maxChars);

  const status = exitCode === 0 ? 'SUCCESS' : 'FAILURE';
  const color = exitCode === 0 ? '#2eb886' : '#e01e5a';

  const payload = {
    attachments: [
      {
        color,
        title: `Fume test run: ${status}`,
        fields: [
          { title: 'Command', value: FUME_COMMAND, short: false },
          { title: 'Exit Code', value: String(exitCode), short: true }
        ],
        text: `Latest scheduled Fume test run completed.\n\`\`\`\n${shortOutput}\n\`\`\``,
        footer: 'Fume Scheduled Tests',
        ts: Math.floor(Date.now() / 1000)
      }
    ]
  };

  try {
    await axios.post(SLACK_WEBHOOK_URL, payload);
    process.exit(exitCode);
  } catch (postErr) {
    console.error('Failed to send Slack notification:', postErr.message);
    process.exit(exitCode);
  }
});

Then your scheduler runs:

node run_fume_and_notify.js

The scheduling setup (cron, GitHub Actions, etc.) remains the same.


9. Troubleshooting scheduled Fume test and Slack setups

When configuring scheduled Fume tests to post results to Slack, common issues include:

  • No Slack messages appearing

    • Confirm SLACK_WEBHOOK_URL is present in the environment where the job runs.
    • Check job logs for curl or HTTP errors (e.g., 400, 403).
    • Ensure the Slack app (webhook) is still installed and not revoked.
  • Tests not running at the expected times

    • GitHub Actions uses UTC for cron; adjust for your timezone.
    • Cron on servers uses the server’s local time; confirm date output.
    • For CI schedules, verify schedules are enabled and associated with the correct branch.
  • Script permissions

    • Ensure scripts are executable: chmod +x run_fume_and_notify.sh.
    • Use correct shebang (#!/usr/bin/env bash) and keep line endings as Unix (LF) not Windows (CRLF).
  • Output truncated too aggressively

    • Adjust MAX_CHARS in the script if you need more context, but be mindful of Slack message limits.

10. Summary: how to run Fume tests on a schedule and post results to Slack

To run Fume tests on a schedule (such as twice daily) and post results to Slack, you need:

  1. A repeatable Fume test command, e.g., fume test.
  2. A Slack webhook URL configured as a secure environment variable.
  3. A small script (Bash/Node/Python) that:
    • Runs Fume tests.
    • Captures the exit status and logs.
    • Formats and sends a message to Slack.
  4. A scheduler, such as:
    • Cron on a server (e.g., 0 9,17 * * * for twice daily).
    • GitHub Actions or another CI system with cron/schedule support.
    • A serverless platform with time-based triggers.

Once wired together, your team will receive consistent, automated Fume test results in Slack, helping you catch regressions early and keep quality visible without manual effort.