File Upload with button in Katalon Studio

I want to load a file through a button that is contains an icon as an image on top of it. When it runs the test it stops just in the attempt to load as if it had clicked on the object and opens the file browser. It is worth mentioning that I have Katalon installed on Linux. I share my script

The variable “file” was where I introduced the path of the file to load

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys

WebUI.openBrowser(‘https://pru-sedesu.elmarquesdigital.com/sedesu/’)

WebUI.maximizeWindow(FailureHandling.STOP_ON_FAILURE)

WebUI.setText(findTestObject(‘Object Repository/Page_Inicia sesin en sedesu-pru/input_Usuario o email_username’), ‘user-ventanilla’)

WebUI.setText(findTestObject(‘Object Repository/Page_Inicia sesin en sedesu-pru/input_Contrasea_password’), ‘Biaani01’)

WebUI.click(findTestObject(‘Page_Inicia sesin en sedesu-pru/input_Has olvidado tu contrasea_login’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/a_Licencias_side-nav-toggle’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/a_Licencias_side-nav-toggle’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/i_Pase de Caja_bx bx-edit bx-sm bx-fw’))

WebUI.setText(findTestObject(‘Object Repository/Page_SedesuDigital/input_Pase de caja_form-control custom-inpu_12e579’),
pase_caja)

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/button_Buscar’))

WebUI.setText(findTestObject(‘Page_SedesuDigital/input_nombre_trmite’), ‘FUSIÓN DE PREDIOS’)

WebUI.sendKeys(findTestObject(‘Page_SedesuDigital/input_nombre_trmite’), Keys.chord(Keys.ENTER))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/label_Acepto el aviso de privacidad’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/button_Comenzar registro’))

WebUI.setText(findTestObject(‘Object Repository/Page_SedesuDigital/input__form-control custom-input-form ng-un_5b4895’),
‘juan.angeles@biaani.com’)

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/button_Continuar’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/div_Adjuntar trmite llenado a mano’))

WebUI.uploadFile(findTestObject(‘Page_SedesuDigital/button_carga_1’), file)

WebUI.delay(10)

WebUI.doubleClick(findTestObject(‘Object Repository/Page_SedesuDigital/div_FUSIN DE PREDIOS DOCUMENTOS DIGITALIZAD_01389b’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/div_notificar’))

WebUI.closeBrowser()

These are the buttons I refer to where I want to load the file

The result of the test shows that the file is being sent but when I run the test it stops showing the linux file browser and does not load the file in the application.

Please don’t be offended, but what you just did was take a photo of your car, drew a red box around the hood, took it to a mechanic and said, “it’s making a weird noise somewhere in there”.

We need to see under the hood!

I’m not offended but attach the code above. What do I need to attach more?

You say the variable “file” is where you introduce the path of the file, but I don’t see it, such as:

file = "G:\\Katalon Studio\\Data\\MyFile.txt"

Do you do it somewhere else not in the code? (Perhaps do a test and put the definition of “file” in the code to see what happens?)

1 Like

I defined it within the test case

Can you do a test and copy the file’s path that you have and use some type of file explorer (not sure what it’s called in Linux) and see if it actually makes it to your file’s location? If it doesn’t make it to the actual file’s location, change the pathway so it does. In my example, (I’m on Windows) I have the full pathway including directory etc.

And, you may try to have double slashes in your file pathway, as well, like I have above.

If the path I am configuring is within a Linux file directory. When I run the test it stops right when it tries to do the file upload and opens the file explorer right at the path I configured but does not do the upload action. In the results it marks me that if it sends the file to the object but it is not reflected when it runs the test.

Maybe try:

1 Like

I will try and notify you if it runs correctly

I ran the test and it stayed the same just open the browser and it doesn’t go from there

How about try with a simpler file name, or remove the “(5)” from the file you have chosen? If the uploadFile statement uses RegEx, the parenthesis would cause a concern.

An alternative is to use the Robot to upload a file.

Something like:
import java.awt.Robot
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import java.awt.event.KeyEvent

"set document"
StringSelection ss = new StringSelection(gImportFileName);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);

WebUI.waitForPageLoad(10)
WebUI.delay(2)
1 Like

image

Make sure you capture all the HTML devoted to presenting that upload button.

This is the object

I’m posting your other discussion to this thread - please don’t post the same question to two topics, it causes much confusion and divides our resources. Thanks.

I tested the code but when I run the test if it is locating each of the test objects but it does not load the file.

I’M USING LINUX.IT MUST BE BECAUSE OF THAT?

I share my script

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys

WebUI.openBrowser(‘https://pru-sedesu.elmarquesdigital.com/sedesu/’)

WebUI.maximizeWindow(FailureHandling.STOP_ON_FAILURE)

WebUI.setText(findTestObject(‘Object Repository/Page_Inicia sesin en sedesu-pru/input_Usuario o email_username’), ‘user-ventanilla’)

WebUI.setText(findTestObject(‘Object Repository/Page_Inicia sesin en sedesu-pru/input_Contrasea_password’), ‘Biaani01’)

WebUI.click(findTestObject(‘Page_Inicia sesin en sedesu-pru/input_Has olvidado tu contrasea_login’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/a_Licencias_side-nav-toggle’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/a_Licencias_side-nav-toggle’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/i_Pase de Caja_bx bx-edit bx-sm bx-fw’))

WebUI.setText(findTestObject(‘Object Repository/Page_SedesuDigital/input_Pase de caja_form-control custom-inpu_12e579’),
pase_caja)

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/button_Buscar’))

WebUI.setText(findTestObject(‘Page_SedesuDigital/input_nombre_trmite’), ‘FUSIÓN DE PREDIOS’)

WebUI.sendKeys(findTestObject(‘Page_SedesuDigital/input_nombre_trmite’), Keys.chord(Keys.ENTER))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/label_Acepto el aviso de privacidad’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/button_Comenzar registro’))

WebUI.setText(findTestObject(‘Object Repository/Page_SedesuDigital/input__form-control custom-input-form ng-un_5b4895’),
‘juan.angeles@biaani.com’)

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/button_Continuar’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/div_Adjuntar trmite llenado a mano’))

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/i_carga_1’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/button_carga_2’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/button_carga_3’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/button_carga_4’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/button_carga_5’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/button_carga_6’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/button_carga_7’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/button_carga_8’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/button_carga_9’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/button_carga_10’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

CustomKeywords.‘cargar_archivo.carga_archivo.uploadFile’(findTestObject(‘Page_SedesuDigital/button_carga_11’),’/home/bcs-ope-018/Documentos/Archivo Carga SEDESU/EUR140901TD0.pdf’)
Thread.sleep(2500) //Millisecond 2.5 second delay only if needed

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/div_FUSIN DE PREDIOS DOCUMENTOS DIGITALIZAD_01389b’))

WebUI.click(findTestObject(‘Object Repository/Page_SedesuDigital/div_notificar’))

WebUI.closeBrowser()

@juan.angeles. Try this alternative solution: How-to use ‘sendKeys’ or 'File Upload' to upload files

Try the way you indicated but the object appears as a button and does not show the type = file

@juan.angeles you want to use sendKeys on the type=‘file’ object, read what I said in my post above regarding must be type=‘file’. As Russ pointed out it’s highlighted in green.

The object you need to deal with is highlighted in green: