Jenkins
Instructions
You can use the Endtest API
together with Jenkins Pipeline
.
This can be done by creating a test.sh
file and executing it from your Jenkins Pipeline.
Jenkins Pipeline
pipeline {
stages {
stage('build') {
steps {
sh './test.sh'
}
}
}
}
test.sh
#!/bin/bash
hash=$(curl -X GET --header "Accept: */*" "${3}")
for run in {1.."${4}"}
do
sleep 30
result=$(curl -X GET --header "Accept: */*" "https://app.endtest.io/api.php?action=getResults&appId=${1}&appCode=${2}&hash=${hash}&format=json")
if [ "$result" == "Test is still running." ]
then
status=$result
# Don't print anything
elif [ "$result" == "Processing video recording." ]
then
status=$result
# Don't print anything
elif [ "$result" == "Stopping." ]
then
status=$result
elif [ "$result" == "Erred." ]
then
status=$result
echo $status
elif [ "$result" == "" ]
then
status=$result
# Don't print anything
else
echo "$result" | jq
exit 0
fi
done
exit
This sample script would require the following arguments:
- The
App ID
for your account. - The
App Code
for your account. - The API Request for starting the test execution.
- The number of times the API request for fetching the results will be sent once every 30 seconds.
For example, if you know that your test execution usually takes 3 minutes, you should use the value 7.
7 x 30 seconds = 210 seconds > 3 minutes
Don't forget to make your Shell script executable by running the following command:
sudo chmod +x test.sh
And you would also need to install the jq
package:
sudo apt-get install jq
The command for running the sample Shell script would have the following format:
./test.sh app-id app-code api-request-to-start-test-execution number-of-loops
Let's pretend we have the following values:
App ID = 44233559
App Code = 22381137
Endtest API Request to start test execution = "https://app.endtest.io/api.php?action=runWeb&appId=44233559&appCode=22381137&suite=380667&platform=windows&os=windows10&browser=chrome&browserVersion=latest&resolution=1280x1024&geolocation=sanfrancisco&cases=all¬es="
Number of loops = 10
The command for running the sample Shell script would look like this:
./test.sh 44233559 22381137 "https://app.endtest.io/api.php?action=runWeb&appId=44233559&appCode=22381137&suite=380667&platform=windows&os=windows10&browser=chrome&browserVersion=latest&resolution=1280x1024&geolocation=sanfrancisco&cases=all¬es=" 10
The JSON with the results contains the following keys:
test_suite_name
{string} - The name of the test suite.configuration
{string} - The configuration of the machine or mobile device on which the test was executed.test_cases
{int32} - The number of test cases.passed
{int32} - The number of assertions that have passed.failed
{int32} - The number of assertions that have failed.errors
{int32} - The number of errors that have been encountered.start_time
{timestamp} - The timestamp for the start of the test execution.end_time
{timestamp} - The timestamp for the end of the test execution.detailed_logs
{string} - The detailed logs for the test execution.screenshots_and_video
{string} - The URLs for the screenshots and the video recording of the test execution.test_case_management
{string} - The name, status and external IDs for each test case.
You can also use the value of the hash
variable to generate the link to the Results page for that test execution:
results=https://app.endtest.io/results?hash="$hash"
If your Jenkins is running on Windows machine, you can use the same logic from the
test.sh
script in a Batch file (.bat).You can find more details about our API in the Endtest API chapter.