- 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 11:56 PM
what's ur result bro ? mine is false

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 12:44 AM
Yes, it will be false as I purposefully added a negative scenario: test2#email.co
If you use the following line as the test data, the test will pass:
var testEmails = ['test@email.com', 'fn.ln@test2.com'];
Also, you can add another set to test for the negative scenario i.e. where the test returns false
function(outputs, steps, stepResult, assertEqual) {
// add test data in the array testEmails
var testEmailsToBeTrue = ['test@email.com', 'fn.ln@test.com'];
var testEmailsToBeFalse = ['test#email.com', 'fn.ln@blah'];
var emailValid = new EmailValid();
describe('my suite of script tests', function() {
//Iterate over each data and verify
testEmailsToBeTrue.forEach(function(email) {
it('should be valid emails', function() {
//optional line to print the test data
gs.info(email);
expect(emailValid.isEmailValid(email)).toBe(true);
});
}, this);
testEmailsToBeFalse.forEach(function(email) {
it('should be invalid emails', function() {
//optional line to print the test data
gs.info(email);
expect(emailValid.isEmailValid(email)).toBe(false);
});
}, this);
});
})(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-26-2018 01:17 AM
i did like us said but i realized that there is error that in Global application there is no EmailValid function of mine. But describe function just support Global app. What should i do now bro ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 02:41 AM
I understand your Script Include is in some scope (say x_snc_email) and the test you are creating is in global scope. You should be able to fix it in either of 2 ways:
- Create test cases in the same scope (e.g: x_snc_email). Then the above script will work.
- If cross scope access is enabled and you want to create the test in global scope, please access the script include with the scope prefix, e.g:
instead of
var emailValid = new EmailValid();
please use
var emailValid = new x_snc_email.EmailValid();
Please replace x_snc_email with the appropriate scope prefix.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2018 10:31 PM
hi bro,
i did it and it's worked. but it throw a result like this below
Why 2 valid email still be failed ? "Expected false to be true"
(function(outputs, steps, stepResult, assertEqual) {
// add test script here
var testEmailTrue = ['test1@email.com', 'test2@gmail.com'];
var testEmailFalse = ['test#email.com', 'fn.ln@blah'];
var emailValid = new x_230904_example1.EmailValid();
describe('my suit test for my script include', function(){
testEmailTrue.forEach(function(email){
it('should be an valid email', function(){
gs.info(email);
expect(emailValid.isEmailValid(email)).toBe(true);
});
}, this);
testEmailFalse.forEach(function(email){
it('should be an invalid email', function(){
gs.info(email);
expect(emailValid.isEmailValid(email)).not.toBe(true);
});
}, this);
});
})(outputs, steps, stepResult, assertEqual);
// uncomment the next line to execute this script as a jasmine test
jasmine.getEnv().execute();