karatelabs / karate

Test Automation Made Simple

Home Page:https://karatelabs.github.io/karate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File upload is not working when using Web driver when running test on Sauce Lab or Remote Grid

djasani opened this issue · comments

We can use input method on file input element and set file path as value. This approach works fine If you are running browser locally as it can find the file but when running same tests it does not work.

This is done in Selenium Web Driver using http Rest call. We can use similar implementation on Karate side to support this feature.

We can have something like,

driver.upload(input element, filePath) and implemented this.

I am able to make this work using workaround but this will be great if file upload on remote execution host is supported out of the box in Karate framework

tagging this as help wanted. personally I feel workarounds are fine, refer: https://stackoverflow.com/a/61393515/143475

Thanks @ptrthomas for the response. The problem with Robot workaround is, it only works if file exists on the host where tests are executing. We execute our test suite on Saucelab from the pipeline. Currently as a workaround, we are using RemoteWebDriver's hidden API to post attachement to the remote host and then upload file from remote host location. I did cloned Karate code today and was able to make file upload working for both WebDriver and DevToolsDriver.

@djasani yes if you can submit a PR, that would be the best option

@ptrthomas After finishing my implementation I realized that you have already implemented this feature for DevToolsDriver. It's has been implemented in the method "inputFile". I did not find similar method for WebDriver and PlaywrightDriver so I will implement and create PR after that.

Somehow I am not able to run using PlaywrightDriver from Karate-Core. It opens Chromium but just keeps waiting after WebSocket connection is established. However I am able to make it work for Playwright Driver in Karate-Playwright module.

@ptrthomas I have executed LocalParallelRunner, PlaywrightRunner and LocalSingleRunner (chromedriver) after my changes. Previously we were only performing file upload when browserType was only Chrome. I have commented following line in the feature file 08.feature so file upload occurs for all different browserType.

#* if (driverType != 'chrome') karate.abort()

I also had to refactor 09.feature file to make this run in playwright. I believe playwright is handling frames differently.

Please find attached here are the results for karate-e2e-tests
karate-reports-LocalParallelRunner.zip
karate-reports-PlaywrightRunner.zip
karate-reports-chromedriver-LocalSingleRunner.zip

@djasani thanks ! I'm a little extra busy at the moment so will request if @f-delahaye can take a look

@ptrthomas Will do.
@djasani out of curiosity, any idea what was not working/was changed in 09.feature for Playwright?