Skip to main content

CI/CD

Jihed Othmani avatar
Written by Jihed Othmani
Updated over a month ago

Overview

The Thunder Code API provides a powerful endpoint for executing automated browser-based tests. This document explains how to use the /api/test-cases/run endpoint, which allows you to trigger test case execution programmatically, including through GitHub Actions workflows.

API Endpoint

POST https://api.thundercode.ai/api/test-cases/run

Authentication

The API requires authentication using a Bearer token:

Authorization: Bearer YOUR_THUNDER_TEST_TOKEN

You must obtain a valid API token from the ThunderCode platform. This token should be stored securely as a secret in your environment or GitHub repository.

Headers

Header

Value

Description

Authorization

Bearer YOUR_THUNDER_TEST_TOKEN

Authentication token

X-MS-API-ROLE

M2M

Indicates a machine-to-machine API call

Content-Type

application/json

Specifies the request body format

Request Body

The request body must be a JSON object with the following properties:

{ 
"ProjectId": "c8e34ec4-2464-43c7-8db8-1b3a47a22337",
"TestCaseIds": ["a836fadc-377a-46fe-96b0-21f37c626bf9",
"61015c47-612f-47fa-82a6-41d910832c1b", "8eea2fd3-da6d-4434-a310-176be84c5646"], "EnvironmentId": "eca24252-e566-40a8-b2b0-707b7efa85d8",
"PersonaId": "70d0ac52-fe94-4d89-aba9-8ef28dd8c04c"
}

Parameters

Parameter

Type

Description

ProjectId

string (UUID)

The unique identifier of the project containing the test cases.

TestCaseIds

array of strings (UUIDs)

Array of test case identifiers to execute.

EnvironmentId

string (UUID)

The unique identifier of the environment to use.

PersonaId

string (UUID)

The unique identifier of the persona to use when executing the tests

Response

The API returns a response with details about the test execution. The exact format may vary depending on the test results, but typically includes:

  • Test execution status

  • Test results summary

  • Detailed results for each test case

  • Any errors or failures encountered

Error Handling

The API uses standard HTTP status codes to indicate success or failure:

  • 200 OK: The request was successful, and the tests were executed

  • 400 Bad Request: The request was malformed or missing required parameters

  • 401 Unauthorized: Authentication failed or token is invalid

  • 403 Forbidden: The authenticated user does not have permission to execute the specified tests

  • 404 Not Found: One or more of the specified resources (project, test cases, environment, or persona) were not found

  • 500 Internal Server Error: An unexpected error occurred on the server

Using with GitHub Actions

You can easily integrate the Thunder Code API with your GitHub Actions workflows to automate test execution as part of your CI/CD pipeline.

Example GitHub Action Workflow

name: Run ThunderCode Test Cases

on:
workflow_dispatch: # This allows manual triggering from the GitHub UI
# You can add other triggers here as needed, such as:
# push:
# branches: [ main ]
# schedule:
# - cron: '0 0 * * *' # Run daily at midnight

jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run ThunderCode API Test Cases
id: run-tests
uses: fjogeleit/http-request-action@v1
with:
url: ''
method: 'POST'
customHeaders: >
{
"Authorization": "Bearer $",
"X-MS-API-ROLE": "M2M",
"Content-Type": "application/json"
}
data: >
{
"ProjectId": "c8e34ec4-2464-43c7-8db8-1b3a47a22337",
"TestCaseIds": ["a836fadc-377a-46fe-96b0-21f37c626bf9", "61015c47-612f-47fa-82a6-41d910832c1b", "8eea2fd3-da6d-4434-a310-176be84c5646"],
"EnvironmentId": "eca24252-e566-40a8-b2b0-707b7efa85d8",
"PersonaId": "70d0ac52-fe94-4d89-aba9-8ef28dd8c04c"
}

- name: Output API Response
if: $
run: echo "API Response - $"

Setting Up GitHub Secrets

To use the Thunder Code API in your GitHub Actions workflow, you need to set up a secret for your API token:

  1. Go to your GitHub repository

  2. Navigate to Settings > Secrets and variables > Actions

  3. Click "New repository secret"

  4. Name: THUNDER_TEST_TOKEN

  5. Value: Your Thunder Code API token

  6. Click "Add secret"

Customizing the Workflow

You can customize the workflow by:

  1. Changing the trigger events (e.g., on push, on schedule)

  2. Modifying the test parameters (ProjectId, TestCaseIds, EnvironmentId, PersonaId)

  3. Adding additional steps to process the test results

Maintenance and Updates

This documentation reflects the current state of the Thunder Code API. As the platform evolves, new features and parameters may be added. Please refer to the official Thunder Code documentation for the most up-to-date information.

Did this answer your question?