Is it possible to upload data like this?

Hey everyone! Recently, I have been trying to make testing uploading easier and I have been having some problems. I’ll illustrate what I am trying to do, and maybe some of you know if this is possible or not.

Or maybe some of you have set-up something similar to this, in which case, great! I’d love to hear what you did.

Here it goes:

I need to automatically test uploading files here. I select a file and it gets displayed in the black box.

Now in my case, I constantly need to upload different files, sometimes I need to upload PNG images, sometimse I need to upload PDF files. I could constantly go to Katalon manually and change the file type every single time, but that costs time and effort.

So what I’d like to do is the following:

As you can see, I have this excel sheet with multiple filenames, all the files are in the same folder. I’d like to make sure that every file gets uploaded after each other.

(So in this case it’s upload Test_image.jpg first then upload Test_image3,jpg)
image

Is it possible to do this? if so, how did you manage to do it? I already know what datadriven testing is, I use it for all of my other tests. I just need to know how to do this with images.

Tanks in advance!

Sure, just do a for loop to iterate your data file:

TestData data = findTestData("path/to/test/data");
for(int rowIndex = 1; rowIndex <= data.getRowNumbers(); rowIndex++) {
    String imagePath = data.getValue("ImagePath", rowIndex);
    // code to upload file using imagePath...
}

If you need help with the actual upload part, I’ve written a topic about how to do it without the WebUI API that may be helpful:

1 Like

Wow, @Brandon_Hein, thank you SO much! This is really helpful, still got a quick question though.

Am I doing the string imagepath correctly? Was just wondering. I replaced “ImagePath” with the path to the folder where all the images are.

No, the code:

String imagePath = data.getValue("ImagePath", rowIndex);

is grabbing a record from your data file, where “ImagePath” is the name of the column:

image

and rowIndex should be self-explanatory. Your data file should have the path to the image file you are trying to upload in each row, like so:

image

1 Like

Hey thanks! Everything is fixed now, sorry for the simple error I made. I am quite new to Katalon, I really appreciate this forum and the people who anwser it’s questions! Thanks.

EDIT:

I thought things were fixed but I ran into another issue.I found out that with each image that I upload, the xpath increaes by one

Image 1 xpath: image

Image 2 xpath: image

Is there a way to make sure the second file gets uploaded to the second xpath and so on? Thanks in advance!

There are a few ways you could approach it. Since you are using the object repository, I would just parameterize the xpath in your test object, like this:

//input[@id='ctl00_ctl00_IFCJIMMain_viewerPLH_RadAsyncUpload1file${index}']

Then, when you do your WebUI.sendKeys() call, you can pass the rowIndex parameter to the test object:

TestData data = findTestData("path/to/test/data");
for(int rowIndex = 1; rowIndex <= data.getRowNumbers(); rowIndex++) {
    String imagePath = data.getValue("ImagePath", rowIndex);
    WebUI.sendKeys(findTestObject('path/to/your/object', ['index' : rowIndex]), imagePath);
}
1 Like

Wow thanks! That fixed everything for me. You’re a lifesaver! I had been struggling with this for like a week now xD

Thank you so much! I really appreciate it!!!

1 Like

My pleasure :smile:

1 Like