Local File Detector to handle file uploads on remote execution

Hello, I’m running the scripts I’ve created through Katalon remotely through the CrossBrowserTesting (CBT) application, and the UploadFile steps are failing with a “cannot find file” error. When I run the same scripts locally, they work just fine, and the file is uploaded without any errors. The support engineer at CBT mentioned “Selenium
needs a local file detector in order to handle the file uploads”, can someone please help me with this issue? I have tried the file path with the escape backslashes and without the extra backslash. This is the error: (Root cause: org.openqa.selenium.WebDriverException: invalid argument: File not found : C:\\TestDocuments\\Thisisatestdoc.docx

Please help…

Is anyone uploading files through a remote execution successfully? If so, I would love to hear how you are doing so. Thank you.

Upload file issue on remote execution.png

Hi Tammy

I don’t know if this will help,but it seems relevant:

Here is the page it came from:

Hope it helps. Let me know.

image.png

Thanks so much for your reply, Russ. I actually found this page as well, but wasnt sure how to implement the RemoteWebElement part (I’m new to automation testing, still learning…). I have this line and it does work just fine when running locally but fails with “cant find file” when running remotely with CBT:
WebUI.sendKeys(findTestObject(‘Regression Test parameters/input_UploadnewFile’), ‘C:\\TestDocuments\\Thisisatestdoc.docx’)

Try using the code something like this:

WebDriver driver = DriverFactory.getWebDriver()

WebElement El = driver.findElement(By.id("ID_OF_YOUR_FILE_FIELD"))

((RemoteWebElement) El ).setFileDetector(new LocalFileDetector())

El.sendKeys("C:\\TestDocuments\\Thisisatestdoc.docx")

NOTE: I’m not using your Test Object – you’ll need to dig out the HTML id of your file input element.

You may need to add these imports:

import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import org.openqa.selenium.WebElement
import org.openqa.selenium.remote.RemoteWebElement
import org.openqa.selenium.remote.LocalFileDetector as LocalFileDetector


Also, give it no excuse to fail – check you are matching the case of your testdoc correctly.

Reminder: I’ve never done this. The code above has NOT been tested.

Let me know how it goes…

Again, thank you so much for your help, Russ. I just tried the code you pasted above and updated the ID to the ID of the file input element and got a couple of errors about “unable to resolve class LocalFileDetector” and “unable to resolve class RemoteWebElement”. I’m sure it’s something simple that I have not setup correctly on my end… Sorry to continue to bother you with this, but I sincerely appreciate your help!

Read my previous message again, Tammy. I’ve edited it – seems I screwed up the imports.

FYI: I’m working from this reference:

https://seleniumhq.github.io/selenium/docs/api/java/index.html?org/openqa/selenium/remote/LocalFileDetector.html

Hi Russ,
So I have gotten further this time! It gave an error but a different error… It said “file type not supported”, which is not true, but at least it attempted the upload (and saw the file)… :slight_smile:

It said “file type not supported” …

It?

My application returned that error when it got to that step, but when not running it through the remote execution, it works fine, so I reached out to the CBT (crossbrowsertesting) people to see what the issue may be. I tried 3 files, .jpg, .docx, and .rtf (all of which are supported files that the application should except). You have been SO helpful!! I sincerely appreciate it!!!

Good. But Tammy, please post back what the issue was when you find out – there’s a “Tips and Tricks” article waiting for this.

And thanks for the BA! B)

Definitely will let you know when I find out and will post it. :slight_smile:

Hi Russ,

I used your script to upload a file, but it fails on groovy.lang.MissingPropertyException: No such property: By for class: Script1561469478327 and I have By.id underlined in my script: https://monosnap.com/file/cWLIQObYktmSbdremDYAy9sWRXoyyZ I can’t figure it out. Can you please help me?

Probably a silly question, I know. Sorry, I am a noob…

The whole stacktrace:

06-25-2019 04:24:27 odp. Test Cases/Create Job - Select file for upload

Elapsed time: 1,614s

Test Cases/Create Job - Select file for upload FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: By for class: Script1561469478327
	at Create Job - Select file for upload.run(Create Job - Select file for upload:44)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:59)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.call(CallTestCaseKeyword.groovy)
	at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.callTestCase(CallTestCaseKeyword.groovy:81)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.execute(CallTestCaseKeyword.groovy:44)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
	at com.kms.katalon.core.keyword.BuiltinKeywords.callTestCase(BuiltinKeywords.groovy:334)
	at Create Job - Copy.run(Create Job - Copy:25)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:133)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:116)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:83)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1561472592156.run(TempTestSuite1561472592156.groovy:35)
```

Add this to your imports:

import org.openqa.selenium.By

I knew it would be something this simple :slight_smile: Thanks a million!

Hi, @Russ_Thomas,
I was using the same code for file upload but now I get error:

Reason:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[[CChromeDriver: chrome on WINDOWS (da503e012bc2fba97018c6b8377972c4)] -> xpath: id('app_slide_translations_ru_images_0_file')]' with class 'org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement' to class 'org.openqa.selenium.remote.RemoteWebElement'

Something had been changed in Katalon?

It’s hard to say from just the error message, but it looks like you are using this…

import org.openqa.selenium.remote.RemoteWebElement

but you need to use this, maybe:

import org.openqa.selenium.support.events.EventFiringWebDriver

Hi Edita,

Did you find out the solution for the given error? I am getting the same error while uploading file from remote.

Try this