Write ATF test for Script Include

escanor
Giga Contributor

Hi,

I'm trying to write a run server script test for my script include below

var EmailValid = Class.create();
EmailValid.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
	isEmailValid: function(email){
			var getEmail = this.getParameter('sysparm_id') || email;	
			var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}/; 
			return regex.test(getEmail);
	},
    type: 'EmailValid'
});

Pls help me !

1 ACCEPTED SOLUTION

Ankush Agrawal
ServiceNow Employee
ServiceNow Employee

Hi

Please follow the below steps:

  1. Go to Automated Test --> Test
  2. Create a Test 
  3. Add a step to 'Run Server Side Script'
  4. Write the following lines
var emailToTest = 'test@amIValid.com';
var emailValid = new EmailValid();
return emailValid.isEmailValid(emailToTest);

You can use any one of the strategies as per your preference:

  1. Create an array having different emails. Set a boolean flag 'result' to true. Iterate over each element and set the boolean to false if any of the verification fails. Return this boolean flag outside the iteration. 
    1. Pros: Clean code
    2. Cons: Test result count will show only 1 test is executed. Not a clear report.
  2. Create multiple tests to assert different email. The report will clearly say which tests passed and which failed.
    1. Pros: Clean report
    2. Cons: Duplication of code
  3. Use Jasmine to validate multiple emails.
    1. Pros: Clean report as test count will cover all the test emails. No code redundancy.
    2. Cons: Need knowledge of Jamsine.

Please let me know if you need any further information. 

 

--
Best regards

Ankush

P.S.: Please mark helpful/correct as appropriate to help others in identifying correct solution.

View solution in original post

11 REPLIES 11

The function in the script includes EmailValid returns false for those emails. I will suggest checking the regular expression there.

ty bro finally i got it