Automated Test Framework Test API - ServiceNow Fluent
The Automated Test Framework Test API defines automated tests [sys_atf_test] that you can run to confirm that your instance works after making a change.
For general information about Automated Test Framework tests, see Automated Test Framework (ATF).
Test object
Create an automated test [sys_atf_test] containing a series of steps to execute.
| Name | Type | Description |
|---|---|---|
| $id | String or Number | Required. A unique ID for the metadata object. When you build the application, this ID is hashed into a unique sys_id. For more information, see ServiceNow Fluent language constructs. Format: |
| name | String | A unique name for the test. |
| description | String | A description of what the test does. |
| active | Boolean | Flag that indicates whether the test is active. Valid values:
Default: true |
| failOnServerError | Boolean | Flag that indicates whether to fail when a server error occurs during the test. Valid values:
Default: true |
| configurationFunction | Function | The steps of the test. Test steps are passed as statements within the atf function. For example:For more information about test steps, see Supported test steps. |
| $meta | Object | Metadata for the application metadata. With the installMethod property, you can map the application metadata to an output directory that loads only in specific
circumstances. Valid values for installMethod:
|
The output values of test steps with output variables can be saved as variables and used as inputs to other steps using the syntax output.<output-variable>. The output variables can be used both directly
as inputs on appropriate fields or inside of a template string, such as with atf.server.log in the following example.
import { Test } from '@servicenow/sdk/core'
Test({
active: true,
failOnServerError: true,
name: 'Simple example',
description: 'An illustrative test written in fluent',
$id: Now.ID[1],
},
(atf) => {
atf.form.openNewForm({
table: 'sn_table_app_reptile_table',
formUI: 'standard_ui',
view: '',
})
atf.form.setFieldValue({
table: 'sn_table_app_reptile_table',
formUI: 'standard_ui',
fieldValues: {
reptiles: 'lizard' as any,
},
})
const output = atf.form.submitForm({ assertType: 'form_submitted_to_server', formUI: 'standard_ui' })
atf.server.recordValidation({
recordId: output.record_id,
table: 'sn_table_app_reptile_table',
assertType: 'record_validated',
enforceSecurity: true,
fieldValues: 'reptiles=lizard',
})
atf.server.log({
log: `Submitted record with sys_id: ${output.record_id} to table ${output.table}`
})
}
)
Supported test steps
The following test steps are supported. For information about step properties, see the Automated Test Framework (ATF) test step categories documentation.
| Category | Steps |
|---|---|
| Application Navigator category |
|
| Email category |
|
| Form category |
|
| Forms in Service Portal category |
|
| Quick start tests for Dashboards |
|
| REST category |
|
| Server category |
|
| Service Catalog category |
|
| Service Catalog in Service Portal category |
|