Hi Community member,
Continue our KShare series, this episode is to focus on how to automate uploading Files on TestCloud with KS v10 and Selenium v4. Check it out!
Prior to the release of Katalon Studio version 10, uploading files to TestCloud was typically accomplished using the EventFiringWebDriver
, a feature supported in Selenium version 3, as depicted in this Article.
However, with the advent of Selenium version 4 and the release of Katalon Studio version 10, the EventFiringWebDriver
was deprecated and subsequently removed. As a result, automation engineers needed to adopt updated methods aligned with the latest Selenium architecture. Katalon Studio v10 introduces new capabilities that support file upload automation on TestCloud without relying on legacy components, ensuring compatibility with modern testing frameworks and enhanced cloud integration.
Therefore, to upload files on TestCloud using Katalon Studio version 10, you can use the following approach, which leverages the updated Selenium 4 framework and Katalon’s latest capabilities:
New Logic to upload the files on TestCloud:
import org.openqa.selenium.WebDriver
import org.openqa.selenium.remote.LocalFileDetector
import org.openqa.selenium.remote.RemoteWebDriver
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import org.openqa.selenium.chrome.ChromeDriver
// Logic to upload the files on testcloud
WebDriver driver = DriverFactory.getWebDriver()
if (driver instanceof RemoteWebDriver && !(driver instanceof ChromeDriver)) {
try {
((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector())
} catch (Exception e) {
WebUI.comment("Failed to set file detector for remote WebDriver: " + e.getMessage())
}
} else {
WebUI.comment("Local WebDriver detected or driver is ChromeDriver. No need to set file detector.")
}
String filePath = new File(RunConfiguration.getProjectDir() + '/' + 'Data Files/download.png').getCanonicalPath()
WebUI.uploadFile(findTestObject('Object Repository/Page_File Upload Test/input_Send this file_userfile'), filePath)
Please refer to the following video for a visual walkthrough of the updated process:
A complete test case should be structured as follows:
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.testng.keyword.TestNGBuiltinKeywords as TestNGKW
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
import org.openqa.selenium.WebDriver
import org.openqa.selenium.remote.LocalFileDetector
import org.openqa.selenium.remote.RemoteWebDriver
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import org.openqa.selenium.chrome.ChromeDriver
WebUI.openBrowser('')
// Logic to upload the files on testcloud
WebDriver driver = DriverFactory.getWebDriver()
if (driver instanceof RemoteWebDriver && !(driver instanceof ChromeDriver)) {
try {
((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector())
} catch (Exception e) {
WebUI.comment("Failed to set file detector for remote WebDriver: " + e.getMessage())
}
} else {
WebUI.comment("Local WebDriver detected or driver is ChromeDriver. No need to set file detector.")
}
// define your folder path to replace with your file path
String filePath = new File(RunConfiguration.getProjectDir() + '/' + 'Data Files/download.png').getCanonicalPath()
println(filePath)
WebUI.navigateToUrl('https://ps.uci.edu/~franklin/doc/file_upload.html')
WebUI.uploadFile(findTestObject('Object Repository/Page_File Upload Test/input_Send this file_userfile'), filePath)
WebUI.delay(2)
WebUI.takeScreenshot()
WebUI.closeBrowser()
Sample Project and References:
- GitHub - bhavya0327/-KSEv10-UploadFilesOnTestCloud: Upload files on TestCloud using Katalon Studio version 10.
- Migrate Katalon Studio from 9.x to 10.0.0 | Katalon Docs
If you find this article helpful, then don’t forget to leave us a like or a heart
and share this article with your colleagues and teammates!
To see more KShare articles, simply navigate to the support tag.