Skip to content

How To Use Postman To Test Scripts In Servicenow

API Testing Blog

Harnessing Postman for Streamlined ServiceNow Script Testing

Postman, a powerful tool for API testing, empowers developers and testers alike to validate ServiceNow scripts with ease. This comprehensive guide provides a step-by-step walkthrough, complete with practical examples and sample codes, to help you effectively integrate Postman into your ServiceNow testing workflow.

The Power of Postman for ServiceNow Script Testing

ServiceNow, a leading platform for IT Service Management (ITSM), boasts an extensive API suite, enabling seamless integration and automation. Postman excels at leveraging these APIs to rigorously test your ServiceNow scripts, validating functionality, identifying bugs, and enhancing overall quality.

Your First Steps: Setting Up Postman and ServiceNow

Before diving into testing, ensure your environment is ready:

1. Install Postman: Download and install Postman from https://www.postman.com/.

2. ServiceNow Instance: Access your ServiceNow instance with the necessary permissions to perform API operations.

3. Authentication:

  • ServiceNow employs Basic authentication. Obtain your API user credentials from your ServiceNow instance.
  • In Postman, navigate to the Authorization tab and select “Basic Auth”. Enter your username and password.

Testing ServiceNow Scripts: A Practical Guide

Let’s explore how to use Postman to test various types of ServiceNow scripts:

1. Testing a Business Rule

Scenario: You have a business rule that validates user input during Incident creation.

Steps:

  • Construct the Request:
    • HTTP Method: POST (to create a new incident)
    • Endpoint: [Instance URL]/api/now/table/incident
    • Headers:
      • Content-Type: application/json
      • Accept: application/json
    • Body: JSON payload containing the incident details.
      {
      "short_description": "Example incident",
      "urgency": "2 - High"
      }
  • Send the Request: Execute the request in Postman.
  • Validate the Response:
    • Status Code: A successful response will have a status code of 201 (Created).
    • Response Body: Inspect the response body for the newly created incident. Verify that the business rule logic was applied correctly (e.g., any mandatory fields are populated).
  • Sample Code (Postman Request):
POST [Instance URL]/api/now/table/incident
Authorization: Basic [base64 encoded username:password]
Content-Type: application/json
Accept: application/json
{
"short_description": "Example incident",
"urgency": "2 - High"
}

2. Testing a Client Script

Scenario: You have a client script that dynamically updates a form field based on user input.

Steps:

  • Construct the Request:
    • HTTP Method: GET (to retrieve the form data)
    • Endpoint: [Instance URL]/api/now/table/your_table_name/[record_id] (replace ‘your_table_name’ and ‘[record_id]’ with your actual table and record ID)
    • Headers:
      • Content-Type: application/json
      • Accept: application/json
  • Send the Request: Execute the request in Postman.
  • Validate the Response:
    • Status Code: The response should have a status code of 200 (OK).
    • Response Body: Inspect the response data. Your client script should have dynamically updated the field values according to your logic.
  • Sample Code (Postman Request):
GET [Instance URL]/api/now/table/incident/[record_id]
Authorization: Basic [base64 encoded username:password]
Content-Type: application/json
Accept: application/json

3. Testing a Script Include

Scenario: You’ve defined a script include to perform a specific calculation or interact with external systems.

Steps:

  • Construct the Request:
    • HTTP Method: POST (to call the script include)
    • Endpoint: [Instance URL]/api/now/table/your_script_include_name (replace ‘your_script_include_name’ with your actual script include name)
    • Headers:
      • Content-Type: application/json
      • Accept: application/json
    • Body: JSON payload containing the parameters required by your script include.
  • Send the Request: Execute the request in Postman.
  • Validate the Response:
    • Status Code: The response should have a status code of 200 (OK).
    • Response Body: Examine the response body. The response should include the output generated by your script include based on the parameters provided.
  • Sample Code (Postman Request):
POST [Instance URL]/api/now/table/your_script_include_name
Authorization: Basic [base64 encoded username:password]
Content-Type: application/json
Accept: application/json
{
"param1": "value1",
"param2": "value2"
}

Advanced Testing Techniques with Postman

Postman offers a wealth of features to enhance your ServiceNow script testing:

1. Test Collections:

  • Organize your tests into logical collections, grouping various script calls and validation scenarios.
  • Collections streamline test execution and facilitate sharing test suites among team members.

2. Environments:

  • Define distinct environments for different ServiceNow instances (development, testing, production).
  • Environments allow you to manage environment-specific configurations (endpoints, credentials) easily.

3. Assertions:

  • Use assertions within your Postman test scripts to verify specific aspects of the API response.
  • Define expectations like status code checks, response body validation, and data comparison.

Example - Assertions:

pm.test("Status code is 201", function () {
pm.response.to.have.status(201);
});
pm.test("Response body contains expected value", function () {
pm.expect(pm.response.text()).to.include("Created");
});

Leveraging Postman for Enhanced ServiceNow Script Testing

By integrating Postman into your ServiceNow testing workflow, you can unlock significant benefits:

  • Automated Testing: Automate script validation, eliminating manual effort and reducing errors.
  • Rapid Feedback: Get immediate results, allowing for faster bug detection and resolution.
  • Improved Quality: Increase code confidence, leading to more robust and reliable scripts.
  • Collaboration: Share tests with your team, promoting knowledge sharing and standardizing quality practices.

Conclusion

Postman stands out as a powerful tool for comprehensive ServiceNow script testing. It empowers developers and testers to build, execute, and analyze tests efficiently, ensuring the reliability and quality of their ServiceNow implementations. Embrace the capabilities of Postman to streamline your testing process, boost productivity, and deliver high-performing, bug-free ServiceNow applications.

API Testing Blog