Katalon TestCloud - uploadFile Fails on Windows Chrome When Using Paths to Create the Absolute File Path

ENVIRONMENT
Katalon TestOps with Git Integration

FUNCTION / AREA
Schedule Test Run > TestCloud
WebUI.uploadFileWithDragAndDrop

ISSUE
Given I have can manage Katalon TestOps Scheduled Test Runs and created a run with a Git project and a test suite/test collection is selected with file uploads and the absolute file path is generated using Paths lib and the environment is Windows Chrome (latest)
When I run the Scheduled Test Run and it completes
Then the Test Result involving a test with file uploads fail because the file cannot be found

I did some investigation into this after finding no solutions from the following topics:

The file can be located when executed from the local machine using the Paths lib.

The following error occurred when executing the test from a TestCloud instance using a Windwos Chrome browser

invalid argument: File not found : /katalon-agent/tmp/2023.09.21-23.55--38-hbh6P1tYn5dK-1903675/test.git/fixtures/sample/document/sample.docx (Session info: chrome=110.0.5481.78) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' System info: host: '1112896winchrome110-1903675-katalon-agent-kzdw5', ip: '172.48.19.4', os.name: 'Linux', os.arch: 'amd64', os.version: '5.10.96', java.version: '1.8.0_312' Driver info: com.kms.katalon.selenium.driver.CRemoteWebDriver Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 110.0, chrome: {chromedriverVersion: 110.0, userDataDir: "C:\\Windows\\proxy\\scoped...}, goog:chromeOptions: {debuggerAddress: }, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: UNIX, platformName: UNIX, proxy: Proxy(), se:bidiEnabled: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true, webdriver.remote.sessionid: QN0UY-QRLD3-ZJPMY-7TZFY} Session ID: QN0UY-QRLD3-ZJPMY-7TZFY %

The file exists, but the file cannot be uploaded

10/06/2023 04:50:43 +00:00 - [TEST_STEP][NOT_RUN] - comment("Fixture Sample File Exists? " + Files.exists(fixtureFilePath)): Fixture Sample File Exists? true
10/06/2023 04:50:43 +00:00 - [MESSAGE][INFO] - Fixture Sample File Exists? true

I noticed the Operating System is Linux: os.name: 'Linux'

The failure is caused by the path returned is in the Linux file path format, when the expectation is the file path of Windows should be used locate the file to upload in a Windows Chrome browser.

WORKAROUND: Switching the Schedule Test Run tests to execute on a Linux Chrome browser solves this problem and the file is uploaded successfully.

STEPS TO REPRODUCE

  1. Create a Schedule Test Run using TestCloud with Windows Chrome as the browser. Include a Test Suite with file uploads using Paths to retrieve the absolute file path.
  2. Run the tests and wait until the results are generated
  3. Review the upload file test result
  4. Observe the file cannot be located

EXPECTED OUTCOME
When executing the project on Windows Chrome the expectation is that the Paths lib when used generates a Windows File Path

2 Likes

Hi Jason,

I ran into the same problem. I created a case with katalon support and got the following workaround.
Hope it also works for you:

Blockquote
Regarding your issue, please help me to add an additional piece of code that identifies the web driver and creates a Local File Detector.

import org.openqa.selenium.WebDriver
import org.openqa.selenium.remote.LocalFileDetector
import org.openqa.selenium.support.events.EventFiringWebDriver
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.selenium.driver.CRemoteWebDriver

WebUI.openBrowser('')

​// This code must be executed AFTER the browser is opened.
EventFiringWebDriver driver = DriverFactory.getWebDriver()
WebDriver wrappedDriver = driver.getWrappedDriver()
if (wrappedDriver.class == CRemoteWebDriver) {
wrappedDriver.setFileDetector(new LocalFileDetector())
}

​Once the required code has been established, the following code can be used as the commands to upload the actual file (the path in this example expects the file “uploadSample.txt” to be located in the “Data Files” folder of the project, and uses an example Object (Page_File Upload) as the upload pointer).

String filePath = new File(RunConfiguration.getProjectDir() + '/' + 'Data Files/uploadSample.txt').getCanonicalPath()
WebUI.uploadFile(findTestObject('Page_File Upload/input_File to uploadNotes about the file to_4f2f05'), filePath)

Once this code is implemented, the file upload will work correctly whether executed locally on Katalon Studio / KRE or remotely with a KRE / Agent or TestCloud.

Blockquote

I tested it with our code and it works for us.
I made it into a keyword so it keeps my testcase cleaner

public class FilePath {

	private EventFiringWebDriver driver;
	private WebDriver wrappedDriver;

	public FilePath() {
		driver = (EventFiringWebDriver) DriverFactory.getWebDriver();
		wrappedDriver = driver.getWrappedDriver();

		if (wrappedDriver.getClass() == CRemoteWebDriver.class) {
			((CRemoteWebDriver) wrappedDriver).setFileDetector(new LocalFileDetector());
		}
	}

	/*
	 * Filepath maken
	 */
	@Keyword
	public String LegitFilepath(String Bestandslocatie) {
		String LegitFilepath = new File((RunConfiguration.getProjectDir() + File.separator) + Bestandslocatie).getCanonicalPath()
		return LegitFilepath
	}
}

Good luck with this “workaround”

Kind regards,
Nikki

1 Like

Thank you @nikki.buijs for the solution

Hi there,

Thank you very much for your topic. Please note that it may take a little while before a member of our community or from Katalon team responds to you.

Thanks!