ATF - How access hamburger options or templates in automated test framework?

ruthmosman
Kilo Contributor

Does anyone have input as to how to use the ATF for applying templates to a form?

Manual action requires that the user click on the hamburger and from the options selects "Templates" and then "Apply Template" and then selecting the specific template.

find_real_file.png

I'm looking to write automated tests that use templates for testing different forms and application areas (screenshot above is for Project) and need help to know how to apply templates to an automated test.

Has anyone tried this or know if this is functionality is available and I'm just missing it, or if it is absent, when it might be available?

Thanks in advance for the input!

1 ACCEPTED SOLUTION

1. Go to 'Step Configurations'. New. Fill out the form as follows:


find_real_file.png



Description generation script:


(function generateDescription(step) {


  var descriptionGenerator = new ATFStepDescriptionGenerator();


  var description = gs.getMessage("Insert a record into '{0}' and apply template", step.inputs.u_table);


  description += descriptionGenerator.getConditionDescription(step.inputs.u_table);


  return description;


})(step);


Step execution script:


(function executeStep(inputs, outputs, stepResult) {


  //check template and get template name


  var template_name = '-';


  var t = new GlideRecord('sys_template');


  if(t.get(inputs.u_template)){


  template_name=t.name;


  //check if template exists for the selected table


  if(t.table != inputs.u_table){


  stepResult.setOutputMessage("Template: "+template_name+" doesn't exist for this table: "+inputs.u_table);


  stepResult.setFailed();


  }


  else{


  //Create record and apply template.


  var inc = new GlideRecord(inputs.u_table);


  inc.initialize();


  inc.applyTemplate(template_name);


  var id = inc.insert();


  outputs.u_record_id = id;


  stepResult.setOutputMessage("Record Created: "+id);


  stepResult.setSuccess();


  }


  }


  else{


  stepResult.setOutputMessage("Could not find name of the template with sys_id: "+inputs.u_template);


  stepResult.setFailed();


  }


}(inputs, outputs, stepResult));



2. Save.



3. Add Input Variables on the Step Configuration form:


find_real_file.png



find_real_file.png



4. Add Output Variables on the Step Configuration form:


find_real_file.png



5. Test it.



Let me know if you have any questions.


View solution in original post

14 REPLIES 14

Masha
Kilo Guru

I don't believe this functionality is currently available. I have gotten around this issue by creating a reusable custom Test Step Config that creates a record on a given table and applies the selected template. Let me know if you are still working on this and I will share my code with you.


ruthmosman
Kilo Contributor

I've been blocked on this so anything that you can share would be much appreciated! Thank you!


1. Go to 'Step Configurations'. New. Fill out the form as follows:


find_real_file.png



Description generation script:


(function generateDescription(step) {


  var descriptionGenerator = new ATFStepDescriptionGenerator();


  var description = gs.getMessage("Insert a record into '{0}' and apply template", step.inputs.u_table);


  description += descriptionGenerator.getConditionDescription(step.inputs.u_table);


  return description;


})(step);


Step execution script:


(function executeStep(inputs, outputs, stepResult) {


  //check template and get template name


  var template_name = '-';


  var t = new GlideRecord('sys_template');


  if(t.get(inputs.u_template)){


  template_name=t.name;


  //check if template exists for the selected table


  if(t.table != inputs.u_table){


  stepResult.setOutputMessage("Template: "+template_name+" doesn't exist for this table: "+inputs.u_table);


  stepResult.setFailed();


  }


  else{


  //Create record and apply template.


  var inc = new GlideRecord(inputs.u_table);


  inc.initialize();


  inc.applyTemplate(template_name);


  var id = inc.insert();


  outputs.u_record_id = id;


  stepResult.setOutputMessage("Record Created: "+id);


  stepResult.setSuccess();


  }


  }


  else{


  stepResult.setOutputMessage("Could not find name of the template with sys_id: "+inputs.u_template);


  stepResult.setFailed();


  }


}(inputs, outputs, stepResult));



2. Save.



3. Add Input Variables on the Step Configuration form:


find_real_file.png



find_real_file.png



4. Add Output Variables on the Step Configuration form:


find_real_file.png



5. Test it.



Let me know if you have any questions.


ruthmosman
Kilo Contributor

Thank you so much for sharing! Much appreciated!!!!!



~ Ruth