Test a component for Virtual Agent
Test your Virtual Agent custom component before deploying it to your instance.
Before you begin
- Set up your environment. For instructions, see the ServiceNow® Developer Site.
- Set up your component project. For instructions, see the ServiceNow® Developer Site
- Develop your component. For instructions, see the ServiceNow® Developer Site
- Add properties to communicate with Virtual Agent
Role required: virtual_agent_admin or admin
About this task
Virtual Agent components must be tested within the Virtual Agent client chat to ensure that the component responds correctly to user input. You can set properties in your component project to test your component in a mock Virtual Agent test client tool.
Procedure
Add a dependency on the test client tool to your component project.
Open the
<component-name>/package.jsonfile in your component project.Add
"@servicenow/sdk-ci": "1.0.8"and"@servicenow/library-translate": "^18.0.0"to thedevDependenciesobject.
Here is an example
package.jsonfile with the correct dependencies."dependencies": { "@servicenow/ui-renderer-snabbdom": "australia", "@servicenow/library-translate": "^18.0.0", "@servicenow/now-button": "australia", "@servicenow/now-dropdown": "australia", "@servicenow/sass-generic": "australia", "@servicenow/cli-archetype": "australia", "@servicenow/sdk-ci": "1.0.8" }Add sample properties to use as the initial state of the component in your test.
- Add a
<component-name>/example/sampleProps.jsonfile with initial properties to render in your test.
Here is an example
sampleProps.jsonfile with initial properties set for a slider component.{ "label": "How many penguins do you want to buy?", "defaultValue": 10, "sliderMin": 20, "sliderMax": 80, "unitName": "penguins", "unitIcon": "https://image.flaticon.com/icons/svg/141/141836.svg" }- Add a
Update the
example.jsfile to open the component through the test client tool using the sample properties that you created.Open the
<component-name>/example/element.jsfile in your component project.Add statements to import
@servicenow/sdk-ciand the sample properties file you created.Add the following statement, replacing
<component-name>with your component's name to create the test tool with initial data from your sample properties.const el = document.createElement('tool-ci-custom-control-tester'); el.componentTagName="<component-name>"; el.initialExampleData=sampleProps; document.body.appendChild(el);
Here is an example
example.jsfile that opens the component using the test client tool.import '../src/now-chat-control-slider'; import '@servicenow/sdk-ci'; import sampleProps from './sampleProps.json'; const el = document.createElement('tool-ci-custom-control-tester'); el.componentTagName="<component-name>"; el.initialExampleData=sampleProps; document.body.appendChild(el);Run the development server command to view your component in a test browser.
$ snc ui-component develop [--entry entry --open --port port --host host]Pass in values for these parameters.
| Name | Description |
|---|---|
| entry | Path to the test module in your component project. Default: `example/index.js`. |
| open | Opens the default browser and navigates to the test page. Default: false. |
| port | Port where the development server runs. Default: 8081. |
| host | Host address to use if you want your local development server to be accessible externally by others. Typically set to `0.0.0.0` |
```
$ snc ui-component develop --entry example/hello.js --open --port 3000
```
The component opens in the test client tool. You can see the initial data provided in the **Custom Control JSON Input Data** field and the component's output in the **Custom Control Return Data** field.
What to do next
If your component is working as expected, deploy it to your instance. For instructions, see the ServiceNow® Developer Site.
After developing the component and deploying it to your instance, add it to Virtual Agent Designer using a custom control and definition. For more information, see Virtual Agent custom controls.
Parent Topic:Develop a component for Virtual Agent
Related topics