[WebUI] Upload File


#1

This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/webui-upload-file.html

#2

this is not working.
image

My script:

Any other alternative?? Im not a coder Im pretty new in katalon


#3

hello. i have a problem the same. do you have any solutions ?


#4

having the same issue


#5

yeah that code is not working


#6

Hello
You can look below link , please…
Regards


#7

package uploadfile

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 com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.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
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import java.awt.Robot
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import java.awt.event.KeyEvent
import internal.GlobalVariable

public class cn {

@Keyword
def uploadFile (TestObject to, String filePath) {
	WebUI.click(to)
	StringSelection ss = new StringSelection(filePath);
	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);
}

}

Encapsulate such a keyword and call it at execution time,you can try it.


#8

Both solutions don’t work for me
it is opening upload windows dialog box, but then it is not inserting path of the file. When I make CTRL+click on upload file like here:

then some errors are shown:

“unable to resolve the class WebUICustomKeyword”