Turn your manual testers into automation experts! Request a DemoStart testRigor Free

ServiceNow Testing

About ServiceNow

ServiceNow is a cloud-based platform that not only provides IT service management (ITSM), IT operations management (ITOM), and IT business management (ITBM) but also extends its services across various other departments like human resources, customer service, and security operations. In addition to its software offerings, it also provides platform-as-a-service (PaaS) capabilities. ServiceNow is designed to help organizations streamline their business processes, enhance their IT infrastructure, and improve customer service through automated workflows, analytics, and machine learning. The platform is highly customizable, capable of being tailored to meet the unique needs of different organizations across a myriad of industries. ServiceNow is used by businesses of all sizes, offering powerful analytics and reporting capabilities for data-driven decisions.

ServiceNow is developed using JavaScript on the client side and Java on the server side. The server-side scripting engine, built on the JVM, supports Java, JavaScript, and GlideRecord API scripting. ServiceNow also has a proprietary scripting language called “ServiceNow Script”, used for creating business rules, workflows, and server-side scripts. Major companies, including Amazon, Airbnb, and Meta, use ServiceNow to manage their IT operations, automate business processes, and enhance customer service.

Next, we will delve into how testing is performed within ServiceNow applications, focusing on the tools used in the three primary areas of testing:

Unit Testing

Unit testing constitutes the first level of application testing. This stage involves examining individual units or components of a software application in isolation from the rest of the system to verify that each unit operates as expected. By catching defects early in the development cycle, unit testing can save time and resources by preventing more severe bugs further down the line.

For ServiceNow applications, the following tools can be utilized for unit testing: ServiceNow Automated Test Framework and Jasmine.

ServiceNow Automated Test Framework

The Automated Test Framework (ATF) is a testing tool integrated within the ServiceNow platform. It facilitates automated testing of ServiceNow applications. ATF is capable of testing a wide array of aspects in a ServiceNow instance, including UI actions, business rules, workflows, among others. In addition to this, ATF provides test reporting and analytics, simplifying the task of tracking the results of automated tests and identifying potential issues. ATF scripts are written in the JavaScript language.

Test cases are stored within the Test Suites module. Each test suite contains a set of test cases executed collectively. Test suites can be organized based on functionality or module and nested within other test suites. The results of the test cases are archived in the Test Results module.

Consider the following sample unit testing script:
var testSuite = new sn_atf.TestSuite();
var testCase = testSuite.newTestCase("Example Test Case");

testCase.addStep("Example Step 1", function() {
  var gr = new GlideRecord('incident');
  gr.addQuery('number', 'INC0012345');
  gr.query();
  assertEqual(1, gr.getRowCount());
  assertTrue(gr.next());
  assertEquals('New', gr.getValue('state'));
});

testSuite.run();

Jasmine

Jasmine is an open-source testing framework utilized within ServiceNow for unit testing. Written in JavaScript, it offers a straightforward syntax for outlining tests and assertions. Jasmine is frequently used in conjunction with other JavaScript testing tools and frameworks and can be employed for both front-end and back-end testing. The unit test cases are housed in the “Client Test Scripts” section of the Test Management module in ServiceNow. You can access this section by navigating to “Test Management” -> “Test Suites” -> “Client Test Scripts”. From there, you can create a new test script, which lets you write your test cases using the Jasmine framework.

Below is a sample code utilizing Jasmine:
describe('My ServiceNow Application', function() {

  var myApp = new MyApp();

  describe('Functionality Tests', function() {

    it('should define the application', function() {
      expect(myApp).toBeDefined();
    });

    it('should have a function to create a new record', function() {
      expect(myApp.createNewRecord).toBeDefined();
    });

    it('should have a function to update an existing record', function() {
      expect(myApp.updateRecord).toBeDefined();
    });
  });
});

Integration Testing

Integration testing is a software testing technique that examines the interaction between different software components or modules within an application. This stage is typically performed after unit testing and before system testing to ensure that individual components operate correctly when integrated as a system.

In ServiceNow applications, the following tools can be employed for integration testing: ServiceNow Automated Test Framework, SoapUI, and various web-based testing tools.

ServiceNow Automated Test Framework

The Automated Test Framework (ATF) can also serve as an integration testing tool. Built directly into the platform, it is well-equipped for testing all aspects of ServiceNow applications and supports various types of testing. With ATF, users can create and execute automated tests that simulate interactions between ServiceNow and other systems via web services or APIs.

Consider the following integration test script designed to log an incident in a ServiceNow application:
var testSuite = 'My Integration Tests';
var testCaseName = 'My Test Case';

var testCase = new sn_atf.Testcase();
testCase.initialize(testCaseName, testSuite);

testCase.addStep(new sn_atf.Step('Log in to ServiceNow', function() {
  sn_atf.utils.login('admin', 'password');
}));

testCase.addStep(new sn_atf.Step('Create a new incident', function() {
  var gr = new GlideRecord('incident');
  gr.initialize();
  gr.short_description = 'Test Incident';
  gr.description = 'This is a test incident created by ATF';
  gr.insert();
  assert.ok(gr.getUniqueValue(), 'Incident record created successfully');
}));

testCase.run();

SoapUI

SoapUI is a popular open-source tool used for testing web services and APIs, particularly in conjunction with ServiceNow applications. As ServiceNow supports both SOAP and RESTful web services, SoapUI is frequently used for integration testing between ServiceNow and other systems via APIs. Such testing ensures that data exchange between systems is accurate and efficient, and that integrations function as expected.

Below is a sample SoapUI script used to create a new incident record in ServiceNow via a POST request to the ServiceNow REST API:
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStepResult

// Retrieve the ServiceNow REST API interface from the project
def project = testRunner.testCase.testSuite.project
def restService = project.getInterfaceByName("ServiceNow REST API")

// Retrieve the Incident resource and the GET method from the interface
def restResource = restService.getResourceByName("Incident")
def restMethod = restResource.getHttpMethodByName("GET")

// Add a new GET request to the method
def request = restMethod.addNewRequest("Get Incident Request")

// Define the headers for the request
def headers = request.getRequestHeaders()
headers.add("Content-Type", "application/json")
headers.add("Accept", "application/json")

// Set the endpoint (URL) for the request
request.setEndpoint("https://<instance>.service-now.com/api/now/table/incident/<incident_sys_id>")

// Submit the request and store the response
def response = request.submit(new com.eviware.soapui.impl.wsdl.WsdlSubmitContext(request), false)

// Verify that the HTTP status code of the response is 200 (OK)
assert response.httpStatusCode == 200 : "Expected status code: 200, Actual status code: " + response.httpStatusCode

This script sends a GET request to the Incident table in the ServiceNow API, retrieves a specific incident by its sys_id, and verifies that the response status code is 200, indicating a successful request.

Web-Based Testing Tools

Various web-based tools and frameworks can be used to test the integration of ServiceNow applications with different browsers. Examples of such tools include Selenium, TOSCA, and testRigor. We will discuss these tools in greater detail in the section on end-to-end testing.

End-to-End Testing

End-to-End (E2E) testing involves testing an entire application from start to finish, including all components and integrations, to ensure that the application works as intended. Test scenarios are created and executed to simulate real-world user behavior, which may involve interactions with external services or databases. E2E testing can be done manually or with automated testing tools. The latter is preferred for faster and more efficient testing and to ensure that changes or updates do not introduce new issues.

We can perform E2E testing using any of the following tools:

  • ServiceNow Automated Test Framework
  • Selenium
  • TOSCA
  • testRigor

ServiceNow Automated Test Framework

The Automated Test Framework (ATF) integrated with Jasmine can be used for testing E2E cases. However, it’s not an ideal tool for performing E2E testing due to the following factors:

  • Limited browser and device coverage: ATF may not provide comprehensive coverage of all the browsers and devices end-users use. This can result in issues being missed during E2E testing.
  • Maintenance overhead: Creating and maintaining test scripts in ATF can be time-consuming and require significant resources, which can be a disadvantage for E2E testing where comprehensive test coverage is required.
  • Cost: Although ATF is a built-in tool in ServiceNow, additional costs, such as training and support, may be associated with its usage.

Selenium

Selenium is a popular web automation tool for end-to-end ServiceNow application testing. Selenium can be used with any programming language like Java, Python, Ruby, etc. We are not going in-depth about Selenium, as it’s a legacy tool, and there are a lot of tutorials available on the internet.

Let’s see a sample test case created in Selenium:
WebDriver driver = new ChromeDriver();
driver.get("https://<yourinstance>.service-now.com");
WebElement username = driver.findElement(By.id("user_name"));
WebElement password = driver.findElement(By.id("user_password"));
username.sendKeys("your_username");
password.sendKeys("your_password");
driver.findElement(By.id("sysverb_login")).click();
driver.get("https://<yourinstance>.service-now.com/nav_to.do?uri=%2Fincident.do%3Fsys_id%3D-1");
WebElement shortDescription = driver.findElement(By.id("incident.short_description"));
WebElement description = driver.findElement(By.id("incident.description"));
shortDescription.sendKeys("Test Incident");
description.sendKeys("This is a test incident created via Selenium");
driver.findElement(By.id("sysverb_insert")).click();
WebElement incidentNumber = driver.findElement(By.className("outputmsg_text"));
assert incidentNumber.getText().contains("INC");
driver.quit();

Selenium depends heavily on the XPath or the IDs of the elements. So any change in the DOM element property causes the test case to fail. Also, the code complexity when more scenarios are created in Selenium is immense, making it difficult for code debugging. So with all these disadvantages, most organizations are moving out of Selenium.

TOSCA

TOSCA (Topological Open System Architecture) is a test automation tool that can be used for end-to-end (E2E) testing of ServiceNow applications. TOSCA is a model-based testing tool that uses visual modeling techniques to create test cases. It allows for the creation of reusable test assets, such as test cases, test data, and test configurations, which can be used to execute tests in various environments. Though TOSCA is used for end-to-end testing, there are many disadvantages too:

  • Learning curve: TOSCA has a steep learning curve, meaning it can take some time for new users to become proficient in using it.
  • Maintenance: TOSCA test cases can be complex and require ongoing maintenance to keep up-to-date as applications change, which can be time-consuming and costly.
  • Limited support: TOSCA has a smaller community of users than other testing tools, which means there may be little support available online or through forums.
  • Platform limitations: TOSCA may not be suitable for testing applications built on specific platforms or technologies, as it may not have the necessary integration capabilities.

testRigor

testRigor is a revolutionary human emulator that understands English and conducts tests from the perspective of an end-user. This innovative approach to automation allows your organization to simultaneously achieve multiple key objectives:

  1. Enable your existing employees to build test automation, regardless of their technical proficiency. As testRigor is an AI-driven, no-code solution, setting up the environment and building tests becomes a much more seamless and efficient process compared to traditional testing tools.
  2. Ensure your automation system is robust enough to withstand the release of new versions. Unlike other systems, testRigor does not rely on the detailed specifics of the implementation. This results in unparalleled stability, saving countless hours each week.
  3. Enhance visibility within the team, as anyone will be able to understand the tests and contribute if needed.
Now let's look at a sample testRigor code. Here we are creating a new incident in a ServiceNow application:
open URL "https://<yourinstance>.service-now.com"
login
check that page contains expression "Hello, UserName"
click "Create Incident"
enter "New Short Description" into "Incident description"
click "Add Incident"
check that page contains "New incident created successfully!"

Also, testRigor is a powerhouse performing different types of testing like Web and Desktop browser testing, Mobile App testing, Desktop Application testing, API testing, Visual regression testing, Load testing, and so on.

Conclusion

Choosing a reliable testing process and appropriate tools is crucial for successful testing. While the tools discussed above are among the most widely used options, selecting the most suitable tool for a specific project depends on its unique requirements. Therefore, any testing tool should be evaluated based on its ability to meet those requirements before implementation.

Join the next wave of functional testing now.
A testRigor specialist will walk you through our platform with a custom demo.
Related Articles

Infor Testing

Infor ERP is a comprehensive software solution designed to help organizations efficiently manage and streamline their business ...

Oracle ERP Testing

One of the global leaders in the industry, Oracle provides ERP solutions comprising a suite of integrated software applications. ...

Vista by Viewpoint Testing

Experience an all-inclusive construction accounting and operations solution that offers unmatched customizability, scalability, ...