空手道UI自动化-Driver.InputFile不与ChromeWebDriver合作
我正在研究一个自动化项目,该项目需要使用空手道UI上传文件。我和我的团队尝试了一些替代方案,并使用driver.inputfile()
似乎可以正常工作。但是,我们还使用Browserstack在无头模式下进行测试,我们注意到同一条线无法正常工作,给出了以下错误:
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)
看着跟踪后,出于某种原因,在我看来,当运行无头时,驾驶员确实会没有定义此方法。调查时,我还确认了运行不同驱动程序对象的两种方法,com.intuit.karate.karate.driver.chrome.chrome.chrome.chrome
用于本地运行和com.intuit.karate.karate.driver 。
无头: headless run Run Report img
本地: 本地运行报告img
在将少量挖掘到空下源源代码之后,我发现Chromewebriver.java.java扩展了WebDriver类,而Chrome.java扩展了DevToolSdriver,并且前者没有我们要使用的方法InputFile()。
考虑到这一点,我的问题是:可以在WebDriver中实现此方法吗?还是我们可以尝试任何替代方案?我还想指出,我尝试了常规输入(),但它不起作用。
我没有设置任何演示项目,因为我不确定如果没有重型配置和其他工具的帮助,我不确定如何重现该问题,但是如果它有助于解决问题,我就愿意接受建议。对不起!
事先感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正确的,Web Driver和Chrome DevTools(我们建议)在根本上是不同的。我上次检查时,文件upload是WebDriver规格中的已知限制,每个浏览器驱动程序(Firefox,Safari等)不支持或具有不同的行为。
是的,无头浏览器也有局限性。
因此,我的建议是更改您的测试策略,以便仅在一个浏览器上测试File-Upload。另请参阅: https://stackoverflow.com/a/61393515/143475
,但您欢迎您做一些研究并贡献一些研究并贡献为空手道项目代码。我们将很乐意接受任何改善事物状态的公关。
如果剧作家支持跨浏览器文件upload,这也是调查的选项,因为我们有一个实验适配器。
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.