Server category
Perform server-side operations. For example, query and update a record, impersonate a user, or run a server-side script.
Create a User
Create a user with specified roles and groups for the test. The user record gets rolled back after the test completes.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them. You can change this default order by editing the Execution order values. |
| Application | Application scope in which the system runs this step. |
| Active | Option to activate this test step for use. |
| Test | Name of the test that you're adding the step to. |
| Step config | Name of the step. |
| Notes | Notes about the test step. |
| First name | First name of the user. |
| Last name | Last name of the user. |
| Roles | Assigned roles of the user. |
| Groups | Assigned groups of the user. |
| Impersonate this user | Option to impersonate the new user. |
| Field | Description |
|---|---|
| user | The user ID of the user impersonated. |
Impersonate
Impersonate the specified user for the test.
- Do not impersonate a user with the test author role. Doing so can lead to conflicts that interfere with executing the test.
- Tests which involve impersonated users which no longer exist fail.Tip:It is recommended to create a new user to avoid data dependencies. See Create a User, for more information.
- Do not rely on user IDs being consistent across different instances. The system dynamically assigns users IDs, so the ID for a particular user often differs from one instance to the next.
- When exporting and importing automated tests, keep in mind that update sets do not update the user field.
- Tests can impersonate users with the snc_external role, which allows testing users who do not have login access. See Explicit Roles for requirements of the snc_external role.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| User | The user ID for the test to impersonate. |
| Field | Description |
|---|---|
| user | The user ID of the user impersonated. |
Search for a Catalog Item
Searches for a catalog item or record producer in the specified catalog and category. You can perform this step both in Platform and Service Portal.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Notes | Notes about the test step. |
| Search in Portal only | Selected if the search is restricted to the Service Portal only. Otherwise, not selected. |
| Search term | Term used to search for a catalog item. |
| Catalog | Catalog in which to search for the catalog item. |
| Category | Category in which to search for the catalog item. |
| Assert item | Catalog items that should be available in the search results. |
| Assert Type | Specifies how searching the catalog item affects the test:
|
| Field | Description |
|---|---|
| catalog_item_id | The sys_id of the first catalog item found that the user can view. |
Record Query
Query the database to verify that a record exists matching the conditions set in this step.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Timeout | Number of seconds allowed before the step fails. If the validation fails, the system repeats the step until it reaches the duration of the timeout. If the validation fails after the timeout duration has passed, the step fails. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Enforce security | Selected to enforce ACLs. Otherwise, not selected. |
| Notes | Notes about the test step. Note: Use the
condition builder to set the field value. The condition builder displays an
appropriate control for the field data type. For example, a reference field displays
a Lookup record control. |
| Assert type | Specifies how querying the record affects the test:
|
| Table | The table to be queried. |
| Conditions | Conditions used to run the query. |
| Field | Description |
|---|---|
| table | The table queried. |
| first_record | The first record resulting from the query. |
Record Insert
Inserts a record into a table with the field values you specify.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Notes | Notes about the test step. Note: Use the
condition builder to set the field value. The condition builder displays an
appropriate control for the field data type. For example, a reference field displays
a Lookup record control. |
| Assert type | Specifies how inserting the record affects the test:
|
| Enforce security | Selected to enforce ACLs and the read-only role. Otherwise, not selected. |
| Table | The table into which the record should be inserted. |
| Conditions | Specific field values to be set when the test runs this step. |
| Field | Description |
|---|---|
| table | The table to which the new record belongs. |
| record_id | The sys_id of the new record. |
Record Update
Changes field values on a record on the server.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Notes | Notes about the test step. Note: Use the
condition builder to set the field value. The condition builder displays an
appropriate control for the field data type. For example, a reference field displays
a Lookup record control. |
| Assert type | Specifies how updating the record affects the test:
|
| Enforce security | Selected to enforce ACLs and the read-only role. Otherwise, not selected. |
| Table | The table containing the record to be updated. |
| Record | ID of the record to be updated. |
| Field values | Fields for which you want to set values and the values you
want to set for those fields. Note: Use the condition builder to set the field value.
The condition builder displays an appropriate control for the field data type. For
example, a reference field displays a Lookup record
control. |
Record Delete
Deletes a specified record in a table.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Notes | Notes about the test step. |
| Assert type | Specifies how updating the record affects the test:
|
| Enforce security | Selected to enforce ACLs and the read-only role. Otherwise, not selected. |
| Table | The table containing the record to be deleted. |
| Record | ID of the record to be deleted. |
Record Validation
Validates that a record meets the specified conditions on the server side.
For the Record Validation step, specify the values you want to test using the standard conditions builder. You can apply several conditions to the same field.
This step passes if the overall condition is satisfied and fails if it is not. If you need to test the values of individual fields independently of each other, include a separate Record Validation step for each value to be tested.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Timeout | Number of seconds allowed before the step fails. If the validation fails, the system repeats the step until it reaches the duration of the timeout. If the validation fails after the timeout duration has passed, the step fails. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Notes | Notes about the test step. Note: Use the
condition builder to set the field value. The condition builder displays an
appropriate control for the field data type. For example, a reference field displays
a Lookup record control. |
| Assert type | Specifies how validating the record affects the test:
|
| Table | The table that contains the field to be validated. |
| Record | The record that contains the field to be validated. |
| Field values | Specific fields to be validated when the test runs this step. |
Run Server Side Script
Executes a script on the server.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Notes | Notes about the test step. |
| Jasmine version | The version of the Jasmine testing framework to use for running the server-side script. Any new scripts you create use Jasmine version 3.1. Your existing scripts can continue to use Jasmine version 1.3, or you can upgrade them to Jasmine version 3.1. |
| Test script | The javascript for the server to execute. Supports the
Jasmine testing framework. Note:
steps(SYS_ID) can be defined as a function to retrieve
Output variable data from a step that executed earlier in the test. The Run Server Side Script test step now supports parameters as step inputs. |
| Field | Description |
|---|---|
| record_id | The sys_id output by the server-side script. |
| table | The table output by the server-side script. |
- Test
script
// Test step 1 - add data var now_GR = new GlideRecord('sc_task'); // this sample step's Step config has Output variables named table and record_id outputs.table = 'sc_task'; outputs.record_id = gr.insert(); // Test step 2 - access added data and validate // check that the record exists (or that business logic changed it) var now_GR = new GlideRecord("sc_task"); gr.get(steps(PREVIOUS_STEP_SYS_ID).record_id); assertEqual({name: "task gr exists", shouldbe: true, value: gr.isValidRecord()}); stepResult.setOutputMessage: Log a message to step results after step executes. Can only be called once or will overwrite previous message - Create a suite of test
scripts
var now_GR = new GlideRecord('sc_task'); gr.setValue('short_description', 'verify task can be inserted'); var grSysId = gr.insert(); var justCreatedGR = new GlideRecord('sc_task'); if (justCreatedGR.get(grSysId)) { stepResult.setOutputMessage("Successfully inserted task record"); return true; // pass the step } else { stepResult.setOutputMessage("Failed to insert task record"); return false; // fail the step } - Jasmine test
describe('my suite of script tests', function() { it('should meet expectations', function() { expect(true).not.toBe(false); }); }); // make sure to uncomment jasmine.getEnv().execute(); outside the function body assertEqual: A function used to compare that assertion.shouldbe == assertion.value; in case of failure it throws an Error and logs that the assertion by name has failedNote:describeis only supported in Global scope. Usedescribeto create a suite of test scripts anditto define test expectations. - Logs message to test step
output
var testAssertion = { name: "my test assertion", shouldbe: "expected value" value: "actual value", }; assertEqual(testAssertion); // throws Error, logs message to test step output - See Step Execution Scripts for Run Server Side script example.
Replay Request Item
Get the item and requester from an existing request item, add the item to a new cart for that user, and place an order.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Notes | Notes about the test step. |
| Original Request Item | The request item to be replayed. |
| Field | Description |
|---|---|
| table | The table to which the replayed request item belongs. |
| request | The replayed request item. |
Log
Logs a message and stores it as a step result.
The log message can contain variables and other information pertaining to the test. The message is stored as a step result.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Notes | Notes about the test step. |
| Log | The message to be logged. To include the value of an output variable from a previous step, click the input value icon ( |
Add Attachments to Existing Record
Add one or more mandatory attachments to the specified record. Use Upload Attachments to select from the attachments the test step adds to the record.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them. You can change this default order by editing the Execution order values. |
| Application | Application scope in which the system runs this step. |
| Active | Option to activate this test step for use. |
| Test | Name of the test that you're adding the step to. |
| Step config | Name of the step. |
| Notes | Notes about the test step. |
| Table | Valid table selection from the list. |
| Record | Pre-existing record either from before the test or inserted as a part of the test. |
| Upload Attachments | Button to add one or more mandatory attachments to the record. |
Checkout Shopping Cart
Submits the cart and generates a request. You can perform this step both in the ServiceNow AI Platform and Service Portal.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Timeout | Number of seconds allowed before the step fails. If the validation fails, the system repeats the step until it reaches the duration of the timeout. If the validation fails after the timeout duration has passed, the step fails. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Notes | Notes about the test step. |
| Assert Type | Criteria for the test to pass.
|
| Requested For | User for whom the request is generated. |
| Delivery Address | Delivery address for the request. |
| Special Instructions | Special instructions for the request. |
| Field | Description |
|---|---|
| request_id | The sys_id of the submitted request. |
Custom Scripted StepConfig
Provides an example of scripts for a custom step configuration.
This example checks if the user name provided starts with the letter A. This step is useful primarily to users with the [atf_test_admin] role. Users with the [atf_test_admin] role can view the example scripts by opening the record for this step in Step configurations.
| Field | Description |
|---|---|
| Execution order | Integer specifying the order in which the test executes this
step. As you create steps, the system automatically assigns each step an incremental value. This value causes the test to execute steps in the order that you created them in. You can change this default order by editing the Execution order values. |
| Active | Option to activate this test step for use. |
| Application | Application scope in which the system runs this step. |
| Test | Read-only name of the test that you're adding the step to. |
| Step config | Read-only name of the step. |
| Description | Description of the test step. This field value is automatically set based on the field values of the test step. This field appears after the test step is submitted. |
| Notes | Notes about the test step. |
| User | The user whose name the system checks to see if it starts with the letter A. To include the value of an output variable from a previous step, click the input value icon ( |
| Field | Description |
|---|---|
| value | The name of the user. |