Multiple Files upload

How to upload multiple files? I want to write a test case to upload multiple files. Kindly help me with this…

Thank you.

1 Like

How to upload multiple files? I want to write a test case to upload multiple files. Kindly help me with this…

Thank you.

Hi there,

Your scenario is you want to select multiple files at once or select one file to upload then another file?

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

In my case, I have to select multiple files at once.

Thanks for your fast reply.

Hi there,

You can’t select multiple files at once, but you can loop through a list of your desired files and execute multiple ‘Select Upload’ file. It’s the same way to achieve your same scenario, is it ok so that I will write you a sample script?

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

Okay. Kindly send me the script, so that I will check and let you know.

Hi there,

1. This script will loop through all current files (NOT recursive) in the folder, e.g C:\SampleFolder

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import groovy.io.FileType

def list = []

def dir = new File(“C:\\SampleFolder”)
dir.eachFile (FileType.FILES) { file ->
list << file
}

for (item in list) {
WebUI.uploadFile(findTestObject(‘SamplePage/btn_UploadFile’), item)
}

2. This script will loop through all current files (RECURSIVE) in the folder, e.g C:\SampleFolder

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import groovy.io.FileType

def list = []

def dir = new File(“C:\\SampleFolder”)
dir.eachFileRecurse (FileType.FILES) { file ->
list << file
}

for (item in list) {
WebUI.uploadFile(findTestObject(‘SamplePage/btn_UploadFile’), item)
}

3. This script will loop through only the files you want in the list to upload in the folder, e.g C:\SampleFolder

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import groovy.io.FileType

def list = [“C:\\SampleFolder\\1.jpg” , “C:\\SampleFolder\\3.jpg”]

for (item in list) {
WebUI.uploadFile(findTestObject(‘SamplePage/btn_UploadFile’), item)
}

Hope one of them will help you.

Thanks

____________________
Thank you for choosing Katalon Studio as your automation solution.
Your feedback is needed to make Katalon Studio a better tool, take the survey at: https://goo.gl/S25NVO

Okay Thank you.

Will try and let you know.

Thanks, everyone. I’m gonna close this discussion now. If you have any question, don’t hesitate to start a new one. We always appreciate your feedback and suggestions.

How should this script been modified to upload more than files simultaneously?

String finalPath = path1 + “\n” + path2;
WebUI.uploadFile(findTestObject(“path/to/my/object”), finalPath);

I get error message in this case:

Caused by: org.openqa.selenium.InvalidArgumentException: invalid argument: File not found

Hi Oliver,

could you please clarify what is a data type of ‘item’ ?
script does not work because WebUI.uploadFile expects String as the 2nd (fileAbsolutePath) parameter.

When I copy the script to my machine and hover over “item”, Intellisense gives me its data type as String and the variable, “list”, as List<String>. If you are having issues, then how about replacing “def” with List<String>.

List<String> list = ["C:\\SampleFolder\\1.jpg" , "C:\\SampleFolder\\3.jpg"]
	
for (item in list) {
    WebUI.uploadFile(findTestObject('SamplePage/btn_UploadFile'), item)
}

Edit: another option would be to leave the def in place and change the variable, item, to: item.toString()

This should define the data type of the variable as a String, in case KS “thinks” it might be “just” an Object–and not a String object.

1 Like