Any actions you can execute on the Cometa Frontend User Interface can be triggered programmatically via REST API. Cometa uses Django for the backend REST API services. It is implemented in python.
Find below a short overview of REST API endpoints to use. Further down, you will find details on the specific endpoints, such as POST parameters and JSON results to be expected.
This documentation is work in progress and may need some help.
Execute a Feature / Test from Django
- POST /backend/exectest/
Account roles
- GET /backend/api/account_roles/
Accounts
- GET /backend/api/accounts/
- PATCH /backend/api/accounts/<user_id>/
- DELETE /backend/api/accounts/<user_id>/
Actions
- GET /backend/api/actions/
Applications
- GET /backend/api/applications/
- POST /backend/api/applications/
Browsers
- GET /backend/api/browsers/
Departments
- GET /backend/api/departments/
- GET /backend/user/departments/
Environments
- GET /backend/api/environments/
- POST /api/environments/
Feature Results
- GET /api/feature_results/<feature_id>/
- POST /api/feature_results/
Features
- GET /backend/api/features/
- POST /api/features/
Folders
- GET /backend/api/folders/
- POST /backend/api/folders/
- PATCH /backend/api/folders
- DELETE /backend/api/folders/<folder_id>/remove/
Step Results
- GET /backend/api/feature_results/<feature_result_id>/step_results/
- POST /backend/api/feature_results/<feature_result_id>/step_results/
Steps
- GET /backend/steps/<feature_id>/
- POST /backend/steps/<feature_id>/patch/
Screenshots
- GET /backend/screenshots/<step_result_id>/
- GET /backend/screenshot/<screenshot_name>/
- GET /backend/removeScreenshot/<screenshot_name>/
Variables
- GET /backend/api/variables/<environment_name>/
- POST /backend/api/variables/
- DELETE /backend/api/variables/<variable_id>/
Others
- GET /backend/addoidcaccount/
- GET /backend/steps/<step_result_id>/pixel_diff/<pixel_diff>/
- GET /backend/updateTask/
- GET /backend/getJson/<feature_id>/
- GET /backend/killTask/<feature_id>/
- GET /backend/killTaskPID//
- GET /backend/stepsByName/
- GET /backend/schedule/<feature_id>/
- GET /backend/exectest/
- GET /backend/info/
- GET /backend/encrypt/
- GET /backend/parseActions/
- GET /backend/browsers/browserstack/
- GET /backend/feature_results/<feature_result_id>/log/
- GET /backend/feature_results/<feature_result_id>/remove/<feature_result_id>/
- GET /backend/feature_runs/<run_id>/remove/
For more details see http://your_server:8000/docs/
All create POST
methods returns code 201
and the row inserted if created correctly.
All request body parameters should be "application/json", unless specified.
All request responses are in JSON format, unless specified.
HTTP_X_SERVER
: Confidential ... or noneAMVARAORIGIN
: CRONTAB ... or emptyContent-Type: application/json
{
"feature_id": 169,
"wait": false
}
Example Curl:
curl -vvv --data '{"feature_id":147,"wait":false}' -H "Content-Type: application/json" -H "X_SERVER: none" -H "AMVARAORIGIN: CRONTAB" -X POST http://behave:8001/run_test/
Implemented by: Alex
Changelog:
- 13.07.2020 RRO documentation and fixing latest changes breaking scheduling
Retrieve all available roles for accounts, this is used for Admin --> Accounts and will be empty if the user doesn't have permissions.
http://localhost:8000/backend/api/account_roles/
[
{
"account_role_id":1,
"user":1,
"department":1
},
{
"account_role_id":2,
"user":2,
"department":1
}
]
Retrieve all available accounts in database. Will be empty is user doesn't have enough permissions.
http://localhost:8000/backend/api/accounts/
[
{
"user_id":2,
"name":"Alex",
"email":"[email protected]",
"user_role":"DEVOPS",
"created_on":"2020-07-17T13:50:56.584849",
"last_login":"2020-07-17T21:07:47.920158",
"favourite_browsers":[],
"user_permissions": {},
"departments":["Default"]
}
]
Modify account information.
user_id: number;
name: string;
email: string;
user_role: string;
departments: number[];
created_on?: string;
last_login?: string;
http://localhost:8000/backend/api/accounts/26/
Delete an account by UserID
Retrieve available actions.
Retrieve available applications for the current user.
http://localhost:8000/backend/api/applications/
[
{
"app_id": 1,
"app_name": "App 1",
"slug": "app-1"
},
{
"app_id": 2,
"app_name": "App 2",
"slug": "app-2"
}
]
Create application.
app_name: string;
Retrieve local browsers.
http://localhost:8000/api/browsers/
[
{
"browser_id": 1,
"browser_json": {
"os": "Generic",
"device": null,
"browser": "chrome",
"os_version": "Selenium",
"real_mobile": false,
"browser_version": "69"
}
}
]
Retrieve all available departments for the current logged-in user. NOTE: If the current logged-in user has Admin/SUPERUSER permissions, all departments in the database will be retrieved.
http://localhost:8000/backend/api/departments/
[
{
"department_id": 1,
"department_name": "Department 1",
"slug": "department-1"
},
{
"department_id": 2,
"department_name": "Department 2",
"slug": "department-2"
}
]
Retrieve the available departments for the current logged user, only retrieves the departments assigned to the user.
http://localhost:8000/backend/user/departments/
[
{
"department_id": 1,
"department_name": "Department 1",
"slug": "department-1"
},
{
"department_id": 2,
"department_name": "Department 2",
"slug": "department-2"
}
]
Retrieve environments available for the current logged user.
http://localhost:8000/backend/api/environments/
[
{
"environment_id":1,
"environment_name":"Environment 1"
},
{
"environment_id":2,
"environment_name":"Environment 2"
}
]
Create environment.
environment_name: string;
Retrieve feature results for the given feature_id.
http://localhost:8000/api/feature_results/26/
[
{
"feature_result_id":1730421,
"feature_id":1,
"result_date":"2018-04-04T22:46:36.247605Z",
"feature_name":"Feature",
"app_id":8,
"app_name":"MIF",
"environment_id":32,
"environment_name":"ENV-1",
"department_id":7,
"department_name":"Dep-8",
"browser_id":8,
"browser_name":"Firefox",
"total":89,
"fails":94,
"ok":67,
"skipped":55,
"execution_time":"5.57",
"pixel_diff":2242,
"success_rate":91,
"screen_style":"/code/file.png",
"screen_actual":"/code/file.png",
"screen_diff":"/code/file.png"
}
]
Create a new feature result (actually only used for behave).
| Parameter | Type | Required |
| feature_id | IntegerField | Yes |
| result_date | Datetime | Yes |
| feature_name | CharField(max_length=100) | Yes |
| app_id | IntegerField | Yes |
| app_name | .CharField(max_length=100) | YEs |
| environment_id | IntegerField | Yes |
| environment_name | CharField(max_length=10) | Yes |
| department_id | CharField(max_length=10) | Yes |
| department_name | CharField(max_length=100) | Yes |
| browser_id | CharField(max_length=10) | Yes |
| browser_name | CharField(max_length=100) | Yes |
| total | IntegerField | Yes |
| fails | IntegerField | Yes |
| ok | IntegerField | Yes |
| skipped | IntegerField | Yes |
| execution_time | DecimalField(decimal_places=2, max_digits=10) | Yes |
| pixel_diff | IntegerField | Yes |
| success | BooleanField | Yes |
| screen_style | CharField(max_length=100) | Yes |
| screen_actual | CharField(max_length=100) | Yes |
| screen_diff | CharField(max_length=100) | Yes |
Retrieve feature information's.
http://localhost:8000/backend/api/features/
Create feature.
feature_name: string;
app_id: number;
app_name: string;
description: string;
environment_id: number;
environment_name: string;
browser_id: number;
browser_name: string;
browser_code: string;
department_id: number;
department_name: string;
steps: number;
schedule: string;
steps_content: GroupContent[];
wait: boolean;
browsers: BrowserstackBrowser[];
cloud: string;
depends_on_other: boolean;
send_mail: boolean;
email_address: string[];
email_subject: string;
email_body: string;
last_edited: number;
video: boolean;
The schedule is saved in the crontab file inside cometa_behave docker.
To view crontab inside container: root@883b40ddbed0:/opt/code/behave_django# cat /etc/cron.d/crontab
To view it outside: cat behave/schedules/crontab
The output when an error occurs can be:
status code 400
{
"Error": "Invalid app_id , not found in Application model"
}
status code 500
{
"Error" : "Schedule was not saved"
}
Retrieve available folders and feature of the current user.
{
"features": Feature[],
"folders": [
{
"features": Feature[],
"folder_id": 1,
"folders": [],
"name": "New",
"owner": 1,
"parent_id": null
}
]
}
Create a folder.
name: string;
parent_id?: number;
NOTES: If no parent_id is provided, it is null or 0, the parent folder will be the Home folder.
Also, to move a folder to inside another folder, provide the following in the same request:
old_folder: number;
new_folder: number;
Both parameters are IDs.
Rename a folder by FolderID.
folder_id: number;
folder_name: string;
Delete a folder by FolderID
Retrieve step results for a given feature_result_id.
http://localhost:8000/backend/api/feature_results/18599/step_results/
[
{
"step_result_id":9919776,
"feature_result_id":18599,
"step_name":"Step-9919776",
"execution_time":"-0.95",
"pixel_diff":2866,
"ok":50,
"fails":39,
"skipped":96,
"success":74
}
]
Create a step result (mostly used for behave).
| Parameter | Type | Required |
| feature_result_id | IntegerField | Yes |
| step_name | CharField(max_length=100) | Yes |
| step_id | IntegerField | Yes |
| execution_time | DecimalField(decimal_places=2, max_digits=10) | Yes |
| pixel_diff | IntegerField | Yes |
| success | BooleanField | Yes |
Retrieve the steps defined for a given feature.
http://localhost:8000/backend/api/steps/
[
{
"id": 1,
"feature_id": 1,
"step_name": "Step 1",
"enabled": true
},
{
"id": 2,
"feature_id": 2,
"step_name": "Step 2"
}
]
Save the feature and steps info.
feature_id: number;
steps: any;
description: string;
environment_id: number;
environment_name: string;
app_id: number;
app_name: string;
department_id: number;
department_name: string;
depends_on_other: boolean;
cloud: string;
browsers: BrowserstackBrowser[];
send_mail: boolean;
email_address: string[];
email_subject: string;
email_body: string;
send_mail_on_error: boolean;
last_edited: number;
video: boolean;
Retrieve available screenshot for a given step result.
["AMVARA_63.png", "AMVARA_63_style.png", "AMVARA_63.png_diff.png"]
Retrieve screenshot by name from Django. NOTES: Django will automatically compress the image at 70%, it will also detect if the requesting browser is WebP compatible and serve the image as WebP instead of JPG.
Delete a screenshot by name from the server. NOTES: If the screenshot removal requested is about the style/template version, another removal request should be done to remove the original template file, for example for a given feature and step index (index of step ignoring previous disabled steps):
http://localhost:8000/backend/removeScreenshot/AMVARA_23_4.png/
Retrieve variables names and values for a given environment.
Set variables for a given environment.
{
"environment_name": "ENV-3",
"variables": [
{
"variable_name": "password",
"variable_value": "12345"
}
]
}
Remove variable by it's ID.
Retrieves the OIDC Account information.
Used from Behave to update the Pixel Difference on running features.
Used from Behave to update the task status of running features.
action: 'start' | 'finish';
browser: BrowserstackBrowser;
feature_id: number;
pid: number;
Retrieves the JSON information of a given feature.
Kills all running feature results by it's Feature ID.
Kill a specific running feature result.
Retrieves the definition for a given feature name.
feature_name: string;
Set schedule for a given feature.
schedule: string;
NOTES: The format for the schedule is the same as in Cron. Leave empty to remove the schedule.
Executes a given feature.
feature_id: number;
Retrieves some useful information from the server, like the compilation version.
Let the user encrypt or decrypt a value using the server token.
action: 'encrypt' | 'decrypt';
text: string;
Using this API endpoint updates the available actions, parsing the actions.py file and saving it on database. It also sends a WebSocket Event to front in order to automatically update the actions without any reload.
Retrieves Browsertstack usable browsers.
Retrieves the log information for a given feature result.
Removes a feature result by it's ID. It will also remove the parent run object if it is finally empty.
Removes a feature run by it's ID. It will also remove all child feature results.