You can define a webhook that will be called at the end of a monitor and test run execution.
In order to define the ‘end of test/monitor webhook’, add #webhook field in the test configuration page – ‘Run Options’ parameter.
Two types of ‘end of test/monitor webhook’ field structure are supported:
- Simple webhook: [URL] (see example below)
- Advanced webhook
The advanced webhook definition supports a complete JSON data like:
{"url": "http://mockbin.org/bin/4cb03fa6-d1aa-4533-a857-11d90293a4e8", "headers": {"custom-webhook-header": "web-testrtc-webhook"}}
Code language: JSON / JSON with Comments (json)
If a webhook exists for a given executed test or monitor, testRTC manager will call that webhook after the execution of the test with the following information:
- Type (monitor | test)
- Test name
- Test run ID
- Execution status
For further information about the JSON data format and available parameters, please refer to https://github.com/request/request
A nice utility to validate your JSON structure: http://www.jsoneditoronline.org
For Slack integration check this article.
We support different webhook formats.
Variables
You can pass certain variables to the webhook in its advanced format. This is useful for collecting information and when you want to format the message itself.
Variable | Description |
testRunId | Identifier of the specific test execution |
testName | The name of the test script |
projectName | The name of the testRTC project running this test |
runName | The random name allocated for the specific test execution |
runType | The type of execution. Will be either test or monitor |
status | The status of the test execution (essentially, if it succeeded or failed) |
error | Associated error message in case the test failed |
additionalInfo | The information provided via rtcSetAdditionalInfo() |
failureReasons | Textual reason for failure |
failureScreenshot | URL to the screenshot taken on failure, if such exist |
score | Media score for the test execution |
resultUrl | URL to the test result for easy access |
concurrentUsers | Total number of probes in the test execution |
numberOfProbesSuccess | Number of probes in the test execution with a successful result status |
numberOfProbesWarning | Number of probes in the test execution with a warning result status |
numberOfProbesFailure | Number of probes in the test execution with a failure result status |
totalTestTimeMin | Full length of the test execution in minutes |
userName | The name of the user who executed the test |
You can integrate these variables anywhere in the body section of your webhook by placing them in <% %>
For example:
{
"url":"https://webhook-destination.com",
"body":{
"testRunId":"<%this.testRunId%>",
"testName":"<%this.testName%>",
"runName":"<%this.runName%>",
"status":"<%this.status%>",
"error":"<%this.error%>"
}
}
Code language: JSON / JSON with Comments (json)
Sample webhook calls data
Successful test execution:
testRunId=56fd35107c458d1400baee63&testName=AppRTC&runType=test&status=completed
Failed test execution:
testRunId=56fd3d617c458d1400baee6f&testName=AppRTC&runType=test&status=failure
webhook testing example
In order to test the end of test/monitor webhook, you can follow the following steps:
- Generate a custom endpoint in Mockbin – in http://mockbin.org/ click on ‘Create Bin’
- In the ‘Bin Builder’ page, leave all suggested default parameters and just click on ‘Create Bin’ at the bottom-right area of the page
- In the next page your temporary created Bin Identifier will be presented
Your URL should be http://mockbin.org/bin/[Bin Identifier]
You can generate this URL yourself or copy it from the code samples at the bottom of the ‘Bin Identifier’ page. Note that if you copy the URL from the codesample, you should take off the URL parameters at the end of the URL (remove “?foo=bar&foo=baz”) - Add the URL to your test – in the test configuration page under Webhook (for example):
http://mockbin.org/bin/5b76146c-37da-40ef-bf01-89043b0d6a75 - Click on ‘View History’ to go to the Mockbin Bin History page
- Run the test
- After the test was ended refresh the Mockbin Bin History page
- You should find a new entry in the history. Click on the new entry history entry to see the request details and body: