Need help with Catalog Client Script validation in Automated Test Framework (ATF) for Attachment

Amber8
Tera Contributor

Hello,

I am currently facing an issue with the validation of a Catalog Client Script in the Automated Test Framework (ATF) for a catalog item. I have a catalog script that checks if an attachment is added, but when I add a step to "Add Attachments to Form (SP)" and submit it, the validation returns error message from script that attachment not added (I see in test runner that it is added). The Catalog Client Script is unable to find the attachment.

My goal is to find a solution to either fix this validation issue or bypass it altogether in ATF. 

 

Could someone please provide guidance on how to solve this issue? Specifically, I would like to know how to:

  1. Modify the Catalog Client Script to successfully validate attachments added through ATF.
function onSubmit() {
    try {
      // Check if running in Automated Test Framework
 
        if (window.g_atf) {  //not working still asks for attachment
            return true;
        }
        //Works in non-portal ui
        var attach = document.getElementsByClassName('attachment_list_items');
        if (attach.length > 0) {
            return true;
        }
        g_form.addErrorMessage("Require attachment/upload of form questionnaire to submit.");
        return false;
    } catch (e) {
        //For Service Portal
        var length = this.document.getElementsByClassName('get-attachment').length;
        if (length > 0) {
            return true;
        }
        g_form.addErrorMessage("Require attachment/upload of form questionnaire to submit..");
        return false;
    }
 
}

OR

     2. Determine if the script is running within ATF and conditionally disable or bypass the validation.

Any assistance or insights would be greatly appreciated.

Thank you in advance for your help!

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Amber8 

within ATF you cannot conditionally disable or bypass the validation. I won't recommend that.

Why not have 2 different test cases?

1) when user adds file and it submits

2) when no file and it stops submission

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hello,

When the user adds a file and submits, I am getting an error that the file is missing. This error is returned from the Catalog Client Ccript, which is not capturing that the file has been added. I'm not sure how to check if a file is attached when ATF (Automated Test Framework) is running. Could you please provide me with the script what would work for the attachment in ATF?

 

function onSubmit() {
    try {
        //Works in non-portal ui
        var attach = document.getElementsByClassName('attachment_list_items');
        if (attach.length > 0) {
            return true;
        }
        g_form.addErrorMessage("Require attachment/upload of form questionnaire to submit.");
        return false;
    } catch (e) {
        //For Service Portal
        var length = this.document.getElementsByClassName('get-attachment').length;
        if (length > 0) {
            return true;
        }
        g_form.addErrorMessage("Require attachment/upload of form questionnaire to submit..");
        return false;
    }
 
}