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

Tommy Jensen
Giga Guru

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.

23 REPLIES 23

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 🙂

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 nameLabelDefault valueTypeOrderMandatoryMax Length
u_portal_url_suffixPortal URL SuffixspString100true40
u_page_idPage IDindexString110true40
u_query_paramsQuery parameters Name-Value Pairs120 4000
u_selector_to_testSelector to test String130 128
u_min_of_selected_elementsMin of selected elements1Integer140  
u_wait_timeoutWait Timeout (in ms)5000Integer150  
u_iteration_step_timeIteration step time (ms)2000Integer160  
u_iteration_steps_countIteration steps count10Integer170  

and one output variable:

Column nameLabelDefault valueTypeOrder
u_elements_foundElements found0Integer100

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.

Thank you very much. I will test this on my developer instans.

vedha1
Tera Contributor

Hello Tommy,

I am facing the same issue. Did you find a solution to this problem?

 

Regards,

Vedha

Unfortunately not.