Adding a file location from test data file

Hello I am trying to fill out a web form using variable data file. One of the tasks is to upload a PDF file. I have the file path stored in the test data file. I have the click step for the button that opens the file explorer on my pc but after that I can not figure out how to point that to the file in my data file.

Any help would be greatly appreciated

are you trying the value from pdf and enter in web form?

Hi

You will need a sendKeys call wich point to your testObject that identifies the input field.
Here is an example testObject common/area_fileUploadxpath is identified by xpath //input[@type=‘file’], which points to this.
image

Second argument is then the actual full path to your file (as a String). This is best done relatively to your project folder, so it can run also outside your local environment. The path must include the actual file name and extension.

Then in your code

import java.nio.file.Path
import java.nio.file.Paths
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.configuration.RunConfiguration
//example of file is in this case a "1.pdf"
String attachmentFileInFolder = "1.pdf"
String projectDir = RunConfiguration.getProjectDir()
Path projectPath = Paths.get(projectDir)
Path uploadPath = projectPath.resolve(TestDataFactory.getProjectDir() + "/Data Files/i18n/$attachmentFileInFolder")
File fileToUpload = uploadPath.toFile()
String fileToUploadPath = (fileToUpload.getAbsolutePath())

WebUI.waitForElementPresent(findTestObject('common/area_fileUpload'), 2)
WebUI.sendKeys(findTestObject('common/area_fileUpload'), fileToUploadPath)

Here is how I put it in the code

WebUI.click(findTestObject(‘Object Repository/PAVE Upload/Page_Qualtrics Survey Qualtrics Experience_67a1ad/div_Drop files or click here to upload (2)’))

String attachmentFileInFolder = ‘1.pdf’

String projectDir = RunConfiguration.getProjectDir()

Path projectPath = Paths.get(projectDir)

Path uploadPath = projectPath.resolve(TestDataFactory.getProjectDir() + “/Data Files/i18n/$attachmentFileInFolder”)

File fileToUpload = uploadPath.toFile()

String fileToUploadPath = fileToUpload.getAbsolutePath()

WebUI.waitForElementPresent(findTestObject(‘common/area_fileUpload’), 2)

WebUI.sendKeys(findTestObject(‘common/area_fileUpload’), GTForm)

1 Like

I cant seem to get it to work. here are the two objects in my script where each one will need the file entered. The object on the page is a drag in drop box or if it is clicked on it will open the explorer window to select the file to upload.

WebUI.click(findTestObject(‘Object Repository/PAVE Upload/Page_Qualtrics Survey Qualtrics Experience_67a1ad/div_Drop files or click here to upload (2)’))

WebUI.click(findTestObject(‘Object Repository/PAVE Upload/Page_Qualtrics Survey Qualtrics Experience_67a1ad/div_Drop files or click here to upload (2)’))

The test object needs to be an input tag, the method won’t work on anything else, like div, button etc. Have you got that part? There’s some documentation with two approaches here:

1 Like
  1. You don’t do a click on the object. Just a sendKeys.
  2. The object needs to be, like Dan_Bown mentions an input tag. In my example the test object common/area_fileUpload is identified by xpath //input[@type=‘file’].

So your example should not first do the WebUI.click(findTestObject(‘Object Repository/PAVE Upload/Page_Qualtrics Survey Qualtrics Experience_67a1ad/div_Drop files or click here to upload (2)’))

Also: Looks like you just copy paste my example, but you have to modify it to match your setup of course.
a) you must have in your Katalon folder a folder called i18n with in that folder a file “1.pdf”.
b) you must have a test object in your object repository in folder “common” called “area_fileUpload” which identifies your specific object in your application.
c) I don’t see how you identified the String “GTForm”. But, as in my example, that must lead to the file you want to upload.

2 Likes