简体   繁体   中英

Karate UI Automation - driver.inputFile not working with ChromeWebDriver

I am working on an automation project that requires a file upload using Karate UI. Me and my team tried a few alternatives and using driver.inputFile() seemed to work just fine. However, we also run tests on headless mode with Browserstack, where we noticed the same line would not work, giving the following error:

js failed:
>>>>
01: driver.inputFile(cleoPortal.inputBox, "C:\\Users\\hello\\Documents\\documents\\text-sample1.txt")
<<<<
org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (inputFile) on com.intuit.karate.driver.chrome.ChromeWebDriver@4cfcac13 failed due to: Unknown identifier: inputFile
- <js>.:program(Unnamed:1)

After looking at the trace, it looks to me that, for some reason, when running headless, the driver does not have this method defined. When investigating, I also confirmed that the 2 ways of running initialize different driver objects, com.intuit.karate.driver.chrome.Chrome for the local run and com.intuit.karate.driver.chrome.ChromeWebDriver for the headless.

Headless: Headless run report img

Local: Local run report img

After digging a little into the karate source code, I found that ChromeWebDriver.java extends the WebDriver class, while Chrome.java extends DevToolsDriver, and that the former does not have the method inputFile() that we're trying to use.

Considering this, my question is: Would it be possible to implement this method in WebDriver? Or are there any alternatives we can try? I would also like to point out that I tried regular input() but it didn't work.

I did not setup any demo project since I am not really sure how to reproduce the issue without heavy configuration and the aid of other tools, but I'm open to suggestions in case it helps solving the problem. Sorry about that!

Thanks in advance for the help!

That is correct, WebDriver and the Chrome DevTools (which we recommend) are fundamentally different. The last time I checked, file-upload was a known limitation in the WebDriver spec and each browser driver (Firefox, Safari etc.) does not support or has different behavior.

And yes headless browsers have limitations as well.

So my advice is to change your testing strategy so that file-upload is tested only on one browser. Also refer: https://stackoverflow.com/a/61393515/143475

But you are welcome to do some research and contribute code to the Karate project. We will be happy to accept any PR that improves the state of things.

In case Playwright supports cross-browser file-upload that is also an option to investigate, since we have an experimental adapter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM