g_form setVisible() or setDisplay() not working with Automated Testing on record producer

brianmelvin
Tera Contributor

When using automated testing framework to validate that a field is visible or not, neither g_form setVisible() or setDisplay() are working as expected. 

Testing the form manually, the field is being hidden as expected. However the automated test fails, claiming either 1) the field is visible (when using g_form.setVisible) or 2) Cannot read property 'display' of undefined (when using g_form.setDisplay).

The test step to validate the field's visibility is defined as shown below. 

find_real_file.png

 

The field is hidden or displayed using a client script. In this case a client script was necessary as the simple condition builder used in UI policies was not sufficient. I need to call a script include and return if a user is a member of a group. 

The client script is written as follows:

function onLoad() {
	//call script include to determine if user is a member of group: GTS VM Request Approvers
	var ga = new GlideAjax('GroupUtils'); // name of script include
	ga.addParam('sysparm_name', 'isUserInGroup'); // name of method
	ga.addParam('sysparm_userSys', g_user.userID); // pass current user
	ga.addParam('sysparm_groupSys', 'cca494251b9cf748a36d8661cd4bcb31'); //pass sys_id of GTS VM Request Approvers group
	ga.getXML(hideIfMember); // run callback function once response is received
}

// callback function assesses response from script include
// If user is not a member of the group, hide the field 'gts_pre_approved_project_request'
function hideIfMember(response) {
	// get the 'answer' attribute from the XML
	var answer = response.responseXML.documentElement.getAttribute('answer');
	// The answer returned is a string true/false, so we need to convert to boolean
	var userIsMember = (answer == 'true');
	if (!userIsMember) {
		//g_form.setDisplay('gts_pre_approved_project_request', false);
		g_form.setVisible('gts_pre_approved_project_request', false);
	}
}

At first I was using g_form setDisplay, but ATF actually errors out (rather than simply failing the test), claiming "Step execution failed with error: Cannot read property 'display' of undefined"

find_real_file.png

Using g_form.setVisible, the test fails claiming the field is indeed visible. 

find_real_file.png

The "failure" screenshot ATF attaches to the test result is circling where the field would be if it were visible. 

find_real_file.png

Anyone run into this, or any other suggestions? 

2 REPLIES 2

Ahmmed Ali
Mega Sage

Hello,

 

Yes. I suppose that is because of the delay the Ajax call will introduce.

 

can you try below solution. 

* add one extra field state value step in the ATF. remove the field from existing step (4 as per above image) and add the same field state validation in newly created step.

 

I am not sure if that works. but this worked for in my case where I was setting some drop down values in client script returned from an Ajax call. When I tried to assign the drop down values, it used to fail saying invalid choice value because it was taking some time to load the choice values from script. Then I just created different steps which in background introduced some delay. same delay compensated my client script delay.

 

Hope this helps you.

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Thanks for your suggestion. I tried creating another step before the one that validates the field visibility and still get the same results.