Interceptor options on Automated test framework
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2020 05:04 AM
Hi Everyone,
We have upgraded one of our instances to Paris and was trying few options in ATF. I can see they have included UI actions in related tabs as a new feature in ATF inParis release. Is the interceptor option also added in Paris?
In our implementation, when the "New" button in Related tabs is clicked, an interceptor page opens with few options. Is it possible to test these interceptor options in Automated test framework? I did not find a suitable option which can do this.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2020 05:29 PM
Hi Vishnu,
For testing a change interceptor, I've used a custom UI step configuration that I created called Click UI Element (Custom). I've documented how to create it here.
You'll need to know the query selector to use. Fortunately for links they are pretty simple, for example to click on the link that contains the link text Standard: Select from available pre-approved change templates. These changes do not require approval, I used the querySelector a:contains('Standard: Select')
Once you click on the link, you'll be navigated to wherever the link takes you. You can keep using the Click UI Element (Custom) steps to click things.
Assuming your navigator takes you to a change request record, you won't be able to use "regular" ATF steps like Set Values on Form, because the Client Test Runner won't have loaded the page through the g_ui_testing_util.
To get a form you've navigated to by clicking on links loaded the client test runner so that you can use the OOTB ATF steps, you'll need to create another Custom UI Step configuration. I have a step configuration that does that.
Here is the Step Execution Script in my step configuration:
(function(step, stepResult, assertionObject) {
assertionObject.executeStep = function(step, stepResult) {
var MESSAGE_KEY_SUCCESSFULY_OPENED = "Successfully opened record page";
var MESSAGE_KEY_FAILED_TO_OPEN = "FAILURE: Failed to open record page";
var MESSAGE_KEY_FAILED_TO_LOAD_GFORM = "FAILURE: Failed to open record. Either you don't have access to the Catalog Item or g_form is not defined";
var MESSAGE_KEY_OPENING = "Opening record";
var MESSAGE_KEY_LOCATION_NOT_VALID = "Could not open the location {0}.";
var MESSAGE_KEY_PARAMS_MISSING = "Params were missing when the location {0} was parsed.";
var MESSAGE_KEY_PARAMS = "URL {0}\nParameters:\n- table = {1}\n-record_id = {2}\n-view = {3}.";
var MESSAGE_KEY_ERROR = "A script error occurred: {0}";
var messageMap = new GwtMessage().getMessages([MESSAGE_KEY_SUCCESSFULY_OPENED, MESSAGE_KEY_FAILED_TO_OPEN, MESSAGE_KEY_FAILED_TO_LOAD_GFORM, MESSAGE_KEY_OPENING, MESSAGE_KEY_LOCATION_NOT_VALID, MESSAGE_KEY_PARAMS_MISSING, MESSAGE_KEY_PARAMS, MESSAGE_KEY_ERROR]);
function updateStepResultMessage(message) {
stepResult.message += (stepResult.message ? ("\n") : "") + message;
}
function onSuccess() {
g_ui_testing_util.setTestStepStatusMessage(messageMap[MESSAGE_KEY_SUCCESSFULY_OPENED]);
stepResult.success = true;
stepResult.message = messageMap[MESSAGE_KEY_SUCCESSFULY_OPENED];
step.defer.resolve();
}
function onFailure() {
g_ui_testing_util.setTestStepStatusMessage(messageMap[MESSAGE_KEY_FAILED_TO_OPEN]);
stepResult.success = false;
updateStepResultMessage(messageMap[MESSAGE_KEY_FAILED_TO_OPEN]);
step.defer.reject();
}
function onFailureGetLocation() {
g_ui_testing_util.setTestStepStatusMessage(formatMessage(messageMap[MESSAGE_KEY_LOCATION_NOT_VALID], location));
stepResult.success = false;
updateStepResultMessage(formatMessage(messageMap[MESSAGE_KEY_LOCATION_NOT_VALID], location));
step.defer.reject();
}
function onFailureGetParams(location) {
g_ui_testing_util.setTestStepStatusMessage(formatMessage(messageMap[MESSAGE_KEY_PARAMS_MISSING], location));
stepResult.success = false;
updateStepResultMessage(formatMessage(messageMap[MESSAGE_KEY_PARAMS_MISSING], location));
step.defer.reject();
}
function onGFormFailure() {
g_ui_testing_util.setTestStepStatusMessage(messageMap[MESSAGE_KEY_FAILED_TO_LOAD_GFORM]);
stepResult.success = false;
updateStepResultMessage(messageMap[MESSAGE_KEY_FAILED_TO_LOAD_GFORM]);
step.defer.reject();
}
function gFormLoaded() {
var $q = g_ui_testing_util.q();
var deferred = $q.defer();
var count = 0;
var testFrameWindow = g_ui_testing_util.getTestIFrameWindow();
var interval = setInterval(function() {
if (typeof testFrameWindow.g_form === 'undefined') {
count++;
if (count >= 10) {
clearInterval(interval);
deferred.reject();
}
} else {
clearInterval(interval);
deferred.resolve();
}
}, 2000);
return deferred.promise;
}
try {
// This expression is for parsing the URL to get the parameters for loading a record
// Sample URL https://xxxxx.service-now.com/nav_to.do?uri=change_request.do?sys_id=32f720f71b1bd05022c8baebcc4bcbd6
var expression = "service-now.com\\/[\\S\\s]*\\?uri=([\\da-zA-Z_]*).do[\\S]*sys_id=([\\da-zA-Z_]*)[&]{0,1}";
var re = new RegExp(expression);
var testFrameWindow = g_ui_testing_util.getTestIFrameWindow();
testFrameWindow.alert = function(){ return true;};
testFrameWindow.confirm = function(){ return true;};
var location = testFrameWindow.location.href + "";
var params = location.match(re);
if (params != null) {
if (params.length == 3) {
var view = location.match(/sysparm_view=([\da-zA-Z_]*)[&]{0,1}/);
if (view == null) {
view = "";
} else if (view.length == 2) {
view = view[1];
} else {
view = "";
}
params.push(view);
updateStepResultMessage(formatMessage(messageMap[MESSAGE_KEY_PARAMS], params));
var inputs = {};
inputs.form_ui = "standard_ui";
inputs.table = params[1];
inputs.record_id = params[2];
inputs.view = params[3];
g_ui_testing_util.setTestStepStatusMessage(messageMap[MESSAGE_KEY_OPENING]);
// Open the page
var afse = new ATFFormStepExecutor(inputs);
afse.openExistingRecord().then(onSuccess, onFailure);
} else {
onFailureGetParams(location);
}
} else {
//%3F|%3D|%26
var url = location.replace(/%3F/g, "?");
url = url.replace(/%3D/g, "=");
url = url.replace(/%26/g, "&");
g_ui_testing_util.openURL(url).then(function() {
gFormLoaded().then(onSuccess, onGFormFailure);
}, onFailureGetLocation);
}
} catch (e) {
updateStepResultMessage(formatMessage(messageMap[MESSAGE_KEY_ERROR], e));
onFailure();
}
};
assertionObject.canMutatePage = step.can_mutate_page;
})(step, stepResult, assertionObject);
Good luck. Let me know if you try it out. You'll be entering into relatively uncharted territory.
Thanks,
Cody
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2021 05:14 AM
It worked! Thank you so much for this post!