Currently, this feature is only available in the TestFirst Desktop App. |
While we provide some basic templates that you can use, including a .csv and a .feature template, they might not suit your needs and you might want to edit them or to create custom templates from scratch.
In order to do that, you will need to have some basic experience in scripting or coding. That being said, it is possible to figure it out even without the relevant experience, it will just take a bit longer.
Write a Template
In order to write a template, use the DotLiquid framework which is a port of Liquid templating language.
In DotLiquid, you can refer to an object and its fields by encasing them in double curly brackets. Example:
{{ test_case.title }} <!-- refers to a test case title -->
{{ test_case.created_by.first_name }} <!-- refers to the first name of the test case author -->
You can also use various filters to achieve your goals as well as iterations to go through a collection of object fields.
Filters
A good example of filter usage could be getting rid of line breaks, for instance. In order to do that, you would use strip
filter along with replace
filter. In this case, using this code
{{ step.action_flat | replace: '\n', " " | strip }}
would transform the step action from multiline
When I scroll up
And I click on "Element"
into
When I scroll up And I click on "Element"
Iteration
In TestFirst templates, the only collection of object fields currently available is the test case steps. In the below code you can see a basic iteration through the steps.
{% for step in test_case.steps %}
{{ step.number }}. {{ step.action.flat }}
{{ step.expected_result.flat }}
{% endfor %}
The output of this iteration in the exported file will look like this:
1. Step 1 action
Step 1 expected result
2. Step 2 action
Step 2 expected result
3. Step 3 action
Step 3 expected result
Further information on DotLiquid
You can read the following articles to help you further understand the syntax and see what you can do with it. Use the Object Model description below to see which fields you can use in your templates.
- DotLiquid templating framework - to understand what it's all about;
- Liquid introduction - to get started with the templates;
- Browse through the Liquid documentation to get an understanding of operators, filters, and more.
Object Model
System fields
You can use the following object model in order to create an export template.
Object type |
Field ID |
Field description |
Test сase test_case |
id |
test case id (for example, 9ec09e39-7a6e-48c5-b1d0-f4616b53e58b) |
parent_id |
test case parent id |
|
created_on |
date and time of when the test case was created |
|
created_by |
creator of the test case. Please check the [Author type]. |
|
updated_on |
date and time of when the test case was updated last time |
|
updated_by |
user who updated the test case last time. Please check the [Author type]. |
|
precondition precondition.markdown |
precondition of the test case (Markdown format) |
|
precondition.flat |
flattened precondition (no Markdown format) |
|
reference |
reference of the test case |
|
status |
status of the test case |
|
key |
key of the test case (for example, TC123) |
|
title |
title of the test case |
|
steps |
array of [Test Step type], can be iterated on |
|
Author test_case.created_by |
id |
user id |
first_name |
user first name |
|
last_name |
user last name |
|
Test step step |
id |
test case id (for example, 22c810b8-e6d2-4090-9341-cf9cca1fcf34) |
number |
step number |
|
created_on |
date and time of when the test step was created |
|
created_by |
creator of the test step. Please check the [Author type]. |
|
updated_on |
date and time of when the test step was updated last time |
|
updated_by |
user who updated the test step last time. Please check the [Author type]. |
|
action action.markdown |
test step action (Markdown format) |
|
action.flat |
flattened test step action (no Markdown format) |
|
expected_result expected_result.markdown |
test step expected result (Markdown format) |
|
expected_result.flat |
flattened test step expected result (no Markdown format) |
Custom fields
Custom fields can be exported using export templates. In the template, a reference to a custom field should always start with c_
followed by the field's system name. Example:
test_case.c_custom_field_system_name
test_case.c_automation_status
In order to refer to a custom field property, use the dot notation:
test_case.c_autotmation_status.markdown
Field | Property | Property Description |
Test case custom field test_case.c_custom_field _system_name |
markdown | The value of the custom field with its markdown formatting |
flat | The value of the custom field with no formatting | |
id | The ID of the custom field value (only for dropdown and multi-select custom field types) | |
name | The name of the custom field value (only for dropdown and multi-select custom field types) |
A multi-select custom field is represented by an array. Thus, if you want to export the IDs or the names for multi-select custom field values, you will have to iterate through them. For instance, if we wanted to export the names of multi-select custom field values, with each name on a new line, we could do it using this code: {% for value in test_case.c_multi_select_field_name %} Alternatively, if we wanted to export them as a string using a semicolon as a separator, this is the code we would use: {% for value in test_case.c_multi_select_field_name %}{{value.name}};{% endfor %} |
Comments
0 comments
Please sign in to leave a comment.