Trigger test with GitHub Actions Using Hypertest CLI
The following are the steps to trigger a test when a pr is raised on the designated master branch.
name: Run HyperTest on PR
on:
pull_request:
types: [opened, synchronize, reopened] # Runs when PR is opened or updated
branches:
- main # Or whichever target branch you protect
jobs:
hypertest-test:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install HyperTest CLI
run: npm install -g @hypertestco/ht-cli-v3@develop
- name: Create HyperTest Config
env:
HT_CLI_TOKEN: ${{ '' }} // You can take it from dashboard(profile page)
HT_SERVICE_ID: ${{ '' }} // Available in dashboard under the current service
HT_BASE_URL: ${{ '' }} // dashboard url without the /
# github.head_ref is the source branch name for Pull Requests
HT_TEST_BRANCH: ${{ github.head_ref }}
run: |
cat <<EOF > .htConf.js
process.env.HT_CLI_REFRESH_TOKEN = "$HT_CLI_TOKEN";
const requestTypes = {
HTTP: 'HTTP',
GRAPHQL: 'GRAPHQL',
KAFKA: 'KAFKA',
GRPC: 'GRPC',
AMQP: 'AMQP',
MANUAL: 'MANUAL'
};
module.exports = {
htBackendBaseUrl: '$HT_BASE_URL',
serviceIdentifier: '$HT_SERVICE_ID',
requestTypesToTest: [requestTypes.HTTP],
htExtraHeaders: {
// Please replace USERNAME and PASSWORD with correct creds.
authorization: 'Basic ' + Buffer.from('USERNAME:PASSWORD').toString('base64'),
},
// Use the environment variable we set above
testBranch: "$HT_TEST_BRANCH"
};
EOF
- name: Run HyperTest
run: htcli start-new-test --config-file-path ./.htConf.jsLast updated