- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 07:26 PM
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 !
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 08:03 PM
Hi
Please follow the below steps:
- Go to Automated Test --> Test
- Create a Test
- Add a step to 'Run Server Side Script'
- 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:
- 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.
-
- Pros: Clean code
- Cons: Test result count will show only 1 test is executed. Not a clear report.
- Create multiple tests to assert different email. The report will clearly say which tests passed and which failed.
-
- Pros: Clean report
- Cons: Duplication of code
- Use Jasmine to validate multiple emails.
-
- Pros: Clean report as test count will cover all the test emails. No code redundancy.
- 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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 08:03 PM
Hi
Please follow the below steps:
- Go to Automated Test --> Test
- Create a Test
- Add a step to 'Run Server Side Script'
- 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:
- 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.
-
- Pros: Clean code
- Cons: Test result count will show only 1 test is executed. Not a clear report.
- Create multiple tests to assert different email. The report will clearly say which tests passed and which failed.
-
- Pros: Clean report
- Cons: Duplication of code
- Use Jasmine to validate multiple emails.
-
- Pros: Clean report as test count will cover all the test emails. No code redundancy.
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 09:17 PM
i add this describe function like example above of jasmine
(function(outputs, steps, stepResult, assertEqual) {
// add test script here
var email = 'test@email.com';
var emailValid = new EmailValid();
return emailValid().isEmailValid(email);
describe('my suite of script tests', function() {
it('should meet expectations', function() {
expect(true).not.toBe(false);
});
});
})(outputs, steps, stepResult, assertEqual);
// uncomment the next line to execute this script as a jasmine test
jasmine.getEnv().execute();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 09:18 PM
can you show me more detail if i choose jasmine way

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2018 10:44 PM
Here you go
(function(outputs, steps, stepResult, assertEqual) {
// add test data in the array testEmails
var testEmails = ['test@email.com', 'test2#email.co'];
var emailValid = new EmailValid();
describe('my suite of script tests', function() {
//Iterate over each data and verify
testEmails.forEach(function(email) {
it('should meet expectations', function() {
//optional line to print the test data
gs.info(email);
expect(emailValid.isEmailValid(email)).toBe(true);
});
}, this);
});
})(outputs, steps, stepResult, assertEqual);
// uncomment the next line to execute this script as a jasmine test
jasmine.getEnv().execute();