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.
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.
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)
WebUI.click(findTestObject(âObject Repository/PAVE Upload/Page_Qualtrics Survey Qualtrics Experience_67a1ad/div_Drop files or click here to upload (2)â))
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:
You donât do a click on the object. Just a sendKeys.
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.