Adding attachment to record producer in ATF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 02:49 PM
I am trying to attach to a Record Producer, but when running the test I am getting an error message that says "invalida table". I am using steps Add Attachments to Form (SP) and Add Attachments to Form .
What can I perform attachments?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 11:44 PM
That "Add Attachments to Form (SP)" step is for adding attachments when you're on the form page (ie: id=form in the URL), not when you're on a record producer.
I personally haven't found an OOTB step that adds an attachment to the paperclip icon on a record producer/cat item (which to me is quite surprising that one doesn't exist OOTB, maybe it does and I'm just not seeing it). So instead, you can create a custom UI Step. There are various approaches to get this to work, but the one below doesn't involve the server and will just add a text file using client-side browser APIs so keeps things simple. It does rely on the DOM, so keep that in mind. You can use this script in the "Step execution script" for your custom UI test step config:
(function (step, stepResult, assertionObject) {
assertionObject.executeStep = function(step, stepResult) {
var MSG_SUCCESSFULLY_ADDED_ATTACHMENT = "Successfully added attachment to form";
var MSG_NO_PAPERCLIP = "FAILURE: Unable to find attachment paperclip";
var MSG_NO_INPUT = "FAILURE: Unable to find file input";
var MSG_RUNTIME_ERR = "FAILURE: An unexpected runtime error occured in the script execution script for this step:\n{0}";
var translator = new GwtMessage();
var msgMap = translator.getMessages([
MSG_SUCCESSFULLY_ADDED_ATTACHMENT,
MSG_NO_PAPERCLIP,
MSG_NO_INPUT,
MSG_RUNTIME_ERR
]);
function appendFileToInput(fileInput) {
// Create a dummy text file to attach
var file = new File(["Hello world"], "example.txt", {
type: "text/plain"
});
// Add existing files to the data transfer items array:
var dataTransfer = new DataTransfer();
for(var i = 0; i < fileInput.files.length; i++) {
var currentFile = fileInput.files[i];
dataTransfer.items.add(currentFile);
}
// Add new file to the data transfer items array
dataTransfer.items.add(file);
fileInput.files = dataTransfer.files;
fileInput.dispatchEvent(new Event("change", {bubbles: true}));
}
function elementExists(elem, errorMsg) {
if (!elem) {
stepResult.success = false;
stepResult.message = msgMap[errorMsg];
step.defer.reject();
return false;
}
return true;
}
try {
var innerWindow = g_ui_testing_util.getTestIFrameWindow();
var innerDoc = innerWindow.document;
var paperClipBtn = innerDoc.querySelector(".sp-attachment-add");
if (!elementExists(paperClipBtn, MSG_NO_PAPERCLIP))
return;
paperClipBtn.click();
var fileInput = innerDoc.querySelector(".modal-content .sp-attachments-input");
if (!elementExists(paperClipBtn, MSG_NO_INPUT))
return;
appendFileToInput(fileInput);
stepResult.message = msgMap[MSG_SUCCESSFULLY_ADDED_ATTACHMENT];
stepResult.success = true;
step.defer.resolve();
} catch (exception) {
stepResult.success = false;
stepResult.message = formatMessage(msgMap[MSG_RUNTIME_ERR], exception.message);
step.defer.reject();
}
};
assertionObject.canMutatePage = step.can_mutate_page;
})(step, stepResult, assertionObject);