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
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’)
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!
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)…
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!!!
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)
```
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'
This is what I came up with from the comments here that is working for me within Katalon:
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.remote.LocalFileDetector as LocalFileDetector
import org.openqa.selenium.remote.RemoteWebDriver
import org.openqa.selenium.support.events.EventFiringWebDriver
filePath = System.getProperty("user.dir") + File.separator + "myfile.txt" // finds the directory that katalon is running in and grabs myfile.txt
EventFiringWebDriver driver = DriverFactory.getWebDriver() // get the event driver (aka the katalon smartwait driver)
RemoteWebDriver wrappedDriver = driver.getWrappedDriver() // get the driver inside the smart wait driver (remote,chrome, firefox,etc)
wrappedDriver.setFileDetector(new LocalFileDetector()) //points your remote,chrome,firefox,etc driver to the local files in the run.
WebElement fileInput = wrappedDriver.findElement(By.cssSelector('input[type=file]')) // specify your selector (I'm using CSS) and create fileInput as the object that is found by your selector
fileInput.sendKeys(filePath) //Send the fileInput object your filepath, which is a directory. It will begin the upload at this point.
This works for remote executions only. You’ll have to add additional code to have it work on both local runs and remote runs if needed.