drjohnchun
Tera Guru

Last time, we ran a demo test called "Basic UI Test" and created a Service Catalog Task record. We also saw that, by design, the record was permanently deleted after the test was completed, with the Automated Test Framework (ATF) "automatically taking care of rolling back changes after testing". Before going further with more tests, I'd like to take a deeper look at the various building blocks of ATF both on the surface and behind the scenes; this will give us the lay of the land and help us what to look for later as we create and run more tests.

APPLICATION MODULES

As noted in Part 1, the Navigator provides the following modules for the atf_test_admin role under the Automated Test Framework application menu:

pastedImage_11.png

Below is a quick rundown of what you get for each module:

Tests

This module shows list of Tests. Tests include both UI and server tests.

find_real_file.png

Suites

This module shows list of Test Suites. Test Suites are made up of one or more Tests and/or Test Suites.

find_real_file.png

Test Results

This module shows list of Test Results. There may be multiple Test Results for a Test.

find_real_file.png

Suite Results

This module shows list of Test Suite Results. There may be multiple Test Suite Results for a Test Suite.

find_real_file.png

Run > Client Test Runner

This module opens Clint Test Runner window. This window, labeled as UI Test Runner, may also be opened from the Run Test dialog box. Without this window opened, UI tests won't run.

find_real_file.png

Run > Test Run Queue

This module shows list of Tests that are Waiting or Running. When running a Test Suite, this lists all Tests that are part of the Test Suite and its child Test Suites, if any. This list doesn't show the execution order, limiting its usefulness. NOTE: Tests can't be scheduled to run at a later time.

find_real_file.png

Occasionally, when I click on this module while Tests are running, I get the message "Security constraints prevent access to requested page" as shown in the screenshot below:

find_real_file.png

Run > Suite Run Queue

This module shows list of Test Suites that have Started or are Running. As in Test Run Queue, this list doesn't show the execution order. NOTE: Test Suites can't be scheduled to run at a later time

find_real_file.png

Administration > Properties

This module shows property settings. As noted in Part 1, these settings are unchecked by default and the first checkbox must be checked to be able to run tests.

find_real_file.png

Administration > Step Configurations

This module shows list of Test Step Configurations. These are used to build Test Steps. ATF comes with several predefined Test Step Configs and new ones can also be created. Test Steps can only be created from an existing Test Step Config.

find_real_file.png

Administration > Step Environments

This module shows list of Test Step Environments. These are used in Test Step Configurations and there are two predefined environments: UI and Server. NOTE: this doesn't allow selecting a server instance, for example QA, DEV, etc.

find_real_file.png

Administration > Test Templates

This module shows list of Test Templates. These are used to build Test Steps in a Test. One Test Template comes with the demo data. A Test Template contains a list of Test Step Configurations in a Glide List.

find_real_file.png

Administration > Step Configuration Categories

This module shows list of Test Step Configuration Categories. These are used in the Add Test Step dialog box to filter Test Step Configurations when building Test Steps. There are two predefined categories: Form and Server.

find_real_file.png

TEST HIERARCHY

Using Test Suites, multiple Tests can be bundled. A Test Suite may contain Tests and/or other Test Suites. A Test may belong to more than one Test Suite, as shown in the below hierarchy, whereas a Test Suite may belong to only one parent Test Suite:

find_real_file.png

When Test Suite A is executed, here's what happens (within the same level in the hierarchy diagram, assume Tests on the left have lower Execution Order, so executed first):

  1. Test 1 runs and finishes
  2. Test 2 runs and finishes
  3. Test Suite B starts
  4. Test 3 runs and finishes
  5. Test 2 doesn't run again, since it already ran in Test Suite A
  6. Test Suite B finishes
  7. Test Suite A finishes

The test sequence is shown in the Run Test Suite dialog box while the Test Suite is running. When a Test Suite has both Tests and Test Suites, like Test Suite A above, the Tests are always executed first before Test Suites.

While ATF allows a Test to be used in multiple Test Suites, care must be exercised when there are dependencies. In the above example, Test 2 was used twice, first under Test Suite A and second time under Test Suite B. We noticed that Test 2 didn't run again under Test Suite B because it already ran under Test Suite A. If Test 2 had dependency on Test 3 in Test Suite B (e.g., using an output value from Test 3), it may not run correctly.

TABLE RELATIONSHIPS

I used GQL Pad to inspect the database and put together the below ERD (Entity Relationship Diagram) showing the various tables used by ATF and their relationships. This, in conjunction with the module descriptions and test hierarchy above, provides an insight into the inner connections in ATF. For clarity, instead of showing all fields, only the reference fields are shown here to highlight the various relationships. We'll reference this later when we discuss how test records are connected and investigate any issues.

find_real_file.png

I noticed that not all tables had data after loading the demo data; we'll see how and if they're being used as we run more tests later. The Test Suite Test [sys_atf_test_suite_test] table is a many-to-many (m2m) join table that connects between Test Suites and Tests, as shown earlier in Test Hierarchy. Test Template [sys_atf_test_template] has a Glide List for Test Step Configs and is not explicitly related to any tables.

Next time, we'll resume running more Tests as well as creating new ones.

Please feel free to connect, follow, post feedback / questions / comments, share, like, bookmark, endorse.

John Chun, PhD PMP see John's LinkedIn profile

visit snowaid

ServiceNow Advocate

Winner of November 2016 Members' Choice Award

Comments
Tera Contributor

Hi,


Related list validation(Edit/New button visibility onclick() action based on role)


can it be done using ATF?



Thank you.


Tera Guru

You'll need to create a Test Step Configuration for that. You can look at some OOB Test Step Configs, for example, UI Action Visibility / Click a UI Action, and make a copy and modify them.


Giga Expert

How about creating a load test with ATF?


Kilo Patron
Kilo Patron

Hi John,


I just wanted to give you a shout out and thank you for the feedback and review of the ATF. It's extremely helpful and provides a great overview and hand-on experience of what to expect on initial view.


Thanks for sharing - appreciated.



Robbie


Tera Guru

Thanks Robbie - glad to hear that.



John


Tera Guru

What kind of load testing do you have in mind? FYI, ATF can run tests only in series (one test at a time).


Tera Guru

Have you figured out a way to determine if a drop-down doesn't contain certain choices? It seems that we can only test for the presence of a value but not the absence of one. For instance, the ability to set the state of an incident to "Closed" is restricted by removing the option through a client script. We would like to test that only the values we expect to see are available but I haven't found a good way to test this through automation.



Also, what about validating field messages?


Tera Guru

Let me try to provide some clues to get you going.


Prerequisite: you'll need to have a good understanding of querySelector (aka CSS Selector).



Navigate to Automated Test Framework > Administration > Step Configurations and open "UI Action Visibility". Then inspect and scroll to about halfway until you see the following function:



function checkVisibility(actionId) {


  var queryString = "[gsft_id='" + actionId + "']";


  var actionIdExist = testFrameWindow.document.querySelector(queryString);



  if (actionIdExist == null)


      return false;



  if (!isVisible(actionIdExist))


      return false;



  return true;


}



You can copy this to create your own Step Configuration, but with the following:



var valueExist = testFrameWindow.document.querySelector(queryString);



Here, replace "queryString" with the CSS Selector for the "Closed" select option element in the DOM (View Source in the browser will show you what to use). Then you can use it to test the presence or absence of the dropdown value in the field.



You can take a similar approach for testing field messages.



I'd recommend writing a generic function that can test the presence/absence of any DOM element and using it in a reusable Test Step Config.



ps. sorry, I always like using Syntax Highlighting for JavaScript but the editor isn't giving me that option today, somehow. I had to manually insert the <pre> tags to get what you see here.


Tera Guru

Hi John,



Thank you for the response. I was attempting to follow the path you provided however I hit a few road blocks. For starters, the "Step Environment" field will only allow me to select "Server - Independent' and not "UI'. Reviewing the dictionary entry for this field shows that the filter is set to not show the "UI" option. If I remove that filter so that I can select it, I receive an error stating that I need the "maint" role to be able to create a test step with that step environment. I cannot add this role to my user account even with the 'security_admin' role and the 'Elevate Roles' option enabled.



Were you able to copy the "UI Visibility" Step Configuration and modify it accordingly?


Tera Guru

Hi Todd - there are a lot of hoops to jump through to get this working; there must be a good reason for that, so please proceed with caution at your own risk. You can create your own Test Step Config by cloning an OOB record using a Background Script similar to below:



var grOld = new GlideRecord('sys_atf_step_config');


grOld.get('d8fdf5e10b1022009cfdc71437673adc');   // OOB "UI Action Visibility"


var grNew = new GlideRecord('sys_atf_step_config');


grNew.newRecord();


for (var f in grOld) if (f != 'sys_id') grNew[f] = grOld[f];


grNew.name += ' Clone';


grNew.sys_policy = 'NULL';   // make it Unprotected


grNew.setWorkflow(false);   // don't run Business Rule "Check step environment"


grNew.insert();



Please note that this doesn't clone Related Lists. Also, when you try to update this in the form after making changes, the "Check step environment" business rule will prevent your from doing so, which means you can update the record only using Background Script with .setWorkflow(false).


Tera Guru

Hi Todd - I recently learned that the inability to create custom Form Step Configurations is by design, as I suspected. The reason I was told is because form/UI/browser tests tend to be "brittle", that is, they tend to break easily with changes in UI (by switching to a new UI, for example).


Tera Guru

Thank you for the follow up John!


Mega Expert

Is there support in the ATF for unhappy path testing? i.e. make sure a message appears when you try to submit a form with an invalid value.


Tera Guru

As mentioned in the above thread, UI tests, including "unhappy path" or negative tests, are limited to the available OOB Form Step Configurations, since we can't create our own. In Istanbul, I'm not aware of a way to test what you're describing.


Mega Guru

Hi Sagar,



Any chance you created the Test Step Configuration for creation of a new record from a   Related List?



Use Case:   On the Problem Form, click the "New" UI Action on the Problem Tasks Related List



find_real_file.png



Thank you,



John


Kilo Contributor

Thanks for this nice blog John Chun.


Can you please share how ServiceNow rolls back all the changes it made after executing tests? I.e., Data Cleanup. (e.g. cleaning up of incidents/tasks etc which are created as part of test)


Have got two important considerations before executing tests.



1. Does SN rolls back only the data that was created during the tests? Or rolls back all the data created in that session?


2. What if another user creates some legitimate data (in another session) at the same time while tests are running? Is this data also going to be rolled back?



3. When does the roll back happens? Is it after each test run or when the full test suite completes execution?


4. Is there any mechanism to create and restore save points before and after executing tests?


5. Is there any guidance/recommendation on setting up of large data before running a large test suite?



ATF in Jakarta unleashes a lot of ability to automate tests, but while considering automation at a medium to large scale, need to consider all the above points before going through this route. I have been using Selenium to automate tests, but this ATF seems to be much quicker and easier for any user to automate.



Thanks for your time,


-Praveen


Kilo Contributor

Can we test UI Pages using ATF.

Kilo Explorer

can we set sequnence of execution in multiple child test suites which are at same hierarchy level in a parent test suite.