Upload File works in Chrome but not in Firefox

Hello,
I’ve using this code to upload files (i need it to upload files from within project directory).
Chrome works fine, but it throws error whenever i use Firefox. Any ideas?

 'Upload file attachment'
def fileDir = RunConfiguration.getProjectDir()+"/Sample File/Book1.xlsx"
fileDir.replace("/", "\\")
WebUI.uploadFile(findTestObject('Page_Pricing (GWP) Setup - MAA/button_Add Attachment'), fileDir)

Error log:
019-11-14 15:21:16.198 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to upload file ‘C:/Project/ir2—automation-testing/Sample File/Book1.xlsx’ to object ‘Object Repository/Page_Pricing (GWP) Setup - MAA/button_Add Attachment’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to upload file ‘C:/Project/ir2—automation-testing/Sample File/Book1.xlsx’ to object ‘Object Repository/Page_Pricing (GWP) Setup - MAA/button_Add Attachment’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.UploadFileKeyword.uploadFile(UploadFileKeyword.groovy:87)
at com.kms.katalon.core.webui.keyword.builtin.UploadFileKeyword.execute(UploadFileKeyword.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.uploadFile(WebUiBuiltInKeywords.groovy:2945)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$uploadFile.call(Unknown Source)
at TC1_GWP Create Request.run(TC1_GWP Create Request:69)
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.RawTestScriptExecutor.runScript(RawTestScriptExecutor.java:34)
at com.kms.katalon.core.main.RawTestScriptExecutor.doExecute(RawTestScriptExecutor.java:29)
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.runTestCaseRawScript(TestCaseMain.java:151)
at com.kms.katalon.core.main.TestCaseMain$runTestCaseRawScript$0.call(Unknown Source)
at TempTestCase1573719667796.run(TempTestCase1573719667796.groovy:114)
Caused by: org.openqa.selenium.InvalidArgumentException: File not found: C:/Project/ir2—automation-testing/Sample File/Book1.xlsx
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘MTNB240’, ip: ‘10.206.40.89’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: com.kms.katalon.core.webui.driver.ExistingRemoteWebDriver
Capabilities {javascriptEnabled: true, platform: ANY, platformName: ANY}
Session ID: 5e1d9542-88e6-437a-b622-d68ce0f43370
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at com.kms.katalon.core.webui.driver.ExistingRemoteWebDriver.execute(ExistingRemoteWebDriver.java:108)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:106)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.lambda$new$0(EventFiringWebDriver.java:404)
at com.sun.proxy.$Proxy10.sendKeys(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.sendKeys(EventFiringWebDriver.java:429)
at com.kms.katalon.core.webui.keyword.builtin.UploadFileKeyword$_uploadFile_closure1.doCall(UploadFileKeyword.groovy:80)
at com.kms.katalon.core.webui.keyword.builtin.UploadFileKeyword$_uploadFile_closure1.call(UploadFileKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.UploadFileKeyword.uploadFile(UploadFileKeyword.groovy:87)
at com.kms.katalon.core.webui.keyword.builtin.UploadFileKeyword.execute(UploadFileKeyword.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.uploadFile(WebUiBuiltInKeywords.groovy:2945)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$uploadFile.call(Unknown Source)
at Script1573626498259.run(Script1573626498259.groovy:69)
… 10 more
)
2019-11-14 15:21:16.214 ERROR c.k.k.core.main.RawTestScriptExecutor - :x: Test Cases/GWP/TC1_GWP Create Request FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to upload file ‘C:/Project/ir2—automation-testing/Sample File/Book1.xlsx’ to object ‘Object Repository/Page_Pricing (GWP) Setup - MAA/button_Add Attachment’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.UploadFileKeyword.uploadFile(UploadFileKeyword.groovy:87)
at com.kms.katalon.core.webui.keyword.builtin.UploadFileKeyword.execute(UploadFileKeyword.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.uploadFile(WebUiBuiltInKeywords.groovy:2945)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$uploadFile.call(Unknown Source)
at TC1_GWP Create Request.run(TC1_GWP Create Request:69)
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.RawTestScriptExecutor.runScript(RawTestScriptExecutor.java:34)
at com.kms.katalon.core.main.RawTestScriptExecutor.doExecute(RawTestScriptExecutor.java:29)
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.runTestCaseRawScript(TestCaseMain.java:151)
at com.kms.katalon.core.main.TestCaseMain$runTestCaseRawScript$0.call(Unknown Source)
at TempTestCase1573719667796.run(TempTestCase1573719667796.groovy:114)
Caused by: org.openqa.selenium.InvalidArgumentException: File not found: C:/Project/ir2—automation-testing/Sample File/Book1.xlsx
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘MTNB240’, ip: ‘10.206.40.89’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: com.kms.katalon.core.webui.driver.ExistingRemoteWebDriver
Capabilities {javascriptEnabled: true, platform: ANY, platformName: ANY}
Session ID: 5e1d9542-88e6-437a-b622-d68ce0f43370
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at com.kms.katalon.core.webui.driver.ExistingRemoteWebDriver.execute(ExistingRemoteWebDriver.java:108)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:106)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.lambda$new$0(EventFiringWebDriver.java:404)
at com.sun.proxy.$Proxy10.sendKeys(Unknown Source)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement.sendKeys(EventFiringWebDriver.java:429)
at com.kms.katalon.core.webui.keyword.builtin.UploadFileKeyword$_uploadFile_closure1.doCall(UploadFileKeyword.groovy:80)
at com.kms.katalon.core.webui.keyword.builtin.UploadFileKeyword$_uploadFile_closure1.call(UploadFileKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
… 16 more

Its failing because it cant find the file - Make sure that the location is correct, it has access to the location of the file and that the file is there.

To me the location doesnt look correct- ‘/’ should be \ in a path

That’s the problem. Using chrome it works fine. Only firefox that returns the error

*i tried your suggestion, but no luck

I doubt it’s the slashes, Harry. I have a sloppy mixture of them and they work without issue.

Plus, FYI:

image

But just in case I’m wrong for @DimasAryo.Nugroho environment:

This is wrong:

 'Upload file attachment'
def fileDir = RunConfiguration.getProjectDir()+"/Sample File/Book1.xlsx"
fileDir.replace("/", "\\")

you want
image

Interesting - learn something new everyday

1 Like

it’s not working either.
I found workaround for this using System.getProperty
with this, works properly using Chrome and Firefox

I’m also having this problem with Firefox… man, it was confusing to figure out so I’m glad I found this forum post.
I filed an issue here: https://github.com/katalon-studio/katalon-studio-uploadfile-plugin/issues/1

I will answer it by myself. I use the solution of Kazurayam :+1: :

Hello guys got the sale problem with Firefox. What’s the solution in the end ?

@luc.namur

What kind of error do you see with Firefox? Is it something like this?

Caused by: org.openqa.selenium.InvalidArgumentException: 
    Cannot click <input type=file> elements

If so, the following post might be informative.

Nop, I was talking about the previous error of can’t find the folder of the screenshot. But with your solution of using Path, it works great !

Hi,

I still run into this problem tha I cannot upload a file via Firefox, but is works with Chrome.
I have this piece of code:

def file_basepath = RunConfiguration.getProjectDir()

WebUI.uploadFile(findTestObject('01 Browserkoppelvlak/inp-json-file'), (file_basepath + GlobalVariable.Browsertestdata) + 
    json, FailureHandling.STOP_ON_FAILURE)

This is the error I get:

Unable to upload file ‘C:/Users//Testdata/BrowserData/JSONupload.json’ to object ‘Object Repository/01 Browserkoppelvlak/inp-json-file’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to upload file ‘C:/Users//Testdata/BrowserData/JSONupload.json’ to object ‘Object Repository/01 Browserkoppelvlak/inp-json-file’