ATF - FAILURE: g_form is not defined. A valid form must have g_form defined

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2019 11:36 PM
Have anybody found a solution for this error
FAILURE: g_form is not defined. A valid form must have g_form defined
I am getting this error in the test step "Open a Form (SP)". I open a custom portal with a custom page that contains 3 custom widgets.
I have tried to setup g_form with code like this
$scope.$on('spModel.gForm.initialized', function (e, gFormInstance) {
g_form = gFormInstance;
}
but the event spModel.gForm.initialized is never fired.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 11:24 AM
No it is not solved yet. I am in the process of creating a HI case. ServiceNow must give us some guidance here. I am hoping that servicenow will create a copy of the step in the customer instance that we can modify.
I would very much like the javacript code you have thanks 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 12:32 PM
You can try to get help on Hi portal, but don't expect too much.
The code of of "Step execution script", which I use is the following:
/* global step, stepResult, assertionObject */
(function (step, stepResult, assertionObject) {
/* global setTimeout, g_ui_testing_util, GwtMessage */
assertionObject.executeStep = function (step, stepResult) {
var inputs = step.inputs;
var MESSAGE_KEY_OPENING = "Opening Service Portal page";
var MESSAGE_KEY_SUCCESSFULY_OPENED = "Successfully opened Service Portal page";
var MESSAGE_KEY_FAILED_TO_OPEN = "FAILURE: Failed to open Service Portal page";
var MESSAGE_KEY_FAILED_NOT_OPENED = "FAILURE: Elements required on the page could not be found wuring {0} sec";
var messageMap = new GwtMessage().getMessages([
MESSAGE_KEY_OPENING,
MESSAGE_KEY_SUCCESSFULY_OPENED,
MESSAGE_KEY_FAILED_TO_OPEN,
MESSAGE_KEY_FAILED_NOT_OPENED
]);
var gFormCheckCount = 0;
var iterationStepsCount = parseInt(inputs.u_iteration_steps_count, 10) || 10;
var minOfSelectedElements = parseInt(inputs.u_min_of_selected_elements, 10) || 1;
var iterationStepTime = parseInt(inputs.u_iteration_step_time, 10) || 2000;
var secs = iterationStepsCount * iterationStepTime / 1000;
var msgTimeout = new GwtMessage().format(messageMap[MESSAGE_KEY_FAILED_NOT_OPENED], secs);
function passStep () {
g_ui_testing_util.setTestStepStatusMessage(messageMap[MESSAGE_KEY_SUCCESSFULY_OPENED]);
stepResult.success = true;
stepResult.message = messageMap[MESSAGE_KEY_SUCCESSFULY_OPENED];
step.defer.resolve();
}
function failStep (msg) {
var message = msg || messageMap[MESSAGE_KEY_FAILED_TO_OPEN];
g_ui_testing_util.setTestStepStatusMessage(message);
stepResult.success = false;
stepResult.message = message;
step.defer.reject();
}
function ensurePageIsOpened () {
if (gFormCheckCount === iterationStepsCount) {
return failStep(msgTimeout);
}
gFormCheckCount++;
if (inputs.u_selector_to_test) {
var win = g_ui_testing_util.getTestIFrameWindow();
if (win != null) {
var $selectedElements = win.$(inputs.u_selector_to_test);
stepResult.outputs.u_elements_found = $selectedElements.length;
if ($selectedElements.length >= minOfSelectedElements) {
return passStep();
}
}
} else {
return passStep();
}
setTimeout(ensurePageIsOpened, iterationStepTime);
}
g_ui_testing_util.setTestStepStatusMessage(messageMap[MESSAGE_KEY_OPENING]);
var query_params = JSON.parse(inputs.u_query_params || "{}");
var wait_timeout = parseInt(inputs.u_wait_timeout, 10) || 5000;
g_ui_testing_util.openPortalPage(
inputs.u_portal_url_suffix,
inputs.u_page_id,
query_params,
wait_timeout
).then(ensurePageIsOpened, failStep);
};
assertionObject.canMutatePage = step.can_mutate_page;
})(step, stepResult, assertionObject);
where I use the following 8 input variables
Column name | Label | Default value | Type | Order | Mandatory | Max Length |
u_portal_url_suffix | Portal URL Suffix | sp | String | 100 | true | 40 |
u_page_id | Page ID | index | String | 110 | true | 40 |
u_query_params | Query parameters | Name-Value Pairs | 120 | 4000 | ||
u_selector_to_test | Selector to test | String | 130 | 128 | ||
u_min_of_selected_elements | Min of selected elements | 1 | Integer | 140 | ||
u_wait_timeout | Wait Timeout (in ms) | 5000 | Integer | 150 | ||
u_iteration_step_time | Iteration step time (ms) | 2000 | Integer | 160 | ||
u_iteration_steps_count | Iteration steps count | 10 | Integer | 170 |
and one output variable:
Column name | Label | Default value | Type | Order |
u_elements_found | Elements found | 0 | Integer | 100 |
The parameter u_selector_to_test isn't mandatory. If you don't specify it then the script wait for open the main page only. On the other side if your widget has for example one element with CSS class my-custom-widget and you expect to load the page with 3 such widgets then you can specify u_selector_to_test=.my-custom-widget and u_min_of_selected_elements=3.
I hope the information will be enough to create custom Test Step. If you would still have problems, then I could post full XML of the Step, which I use.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 12:44 PM
Thank you very much. I will test this on my developer instans.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2020 05:05 AM
Hello Tommy,
I am facing the same issue. Did you find a solution to this problem?
Regards,
Vedha

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2020 11:36 PM
Unfortunately not.