简体   繁体   English

关于空手道 UI 测试自动化,我如何在使用 karate-chrome 时上传文件?

[英]About Karate UI Test Automation, How can I upload files when I use karate-chrome?

I've got docker(ptrthomas/karate-chrome) running.我有 docker(ptrthomas/karate-chrome) 正在运行。 And I have configurated the driver我已经配置了驱动程序

* configure driver = { type: 'chrome', start: false, showDriverLog: true, host:'192.168.56.122' }

Everything seems ok now, the UI test can run in the docker ptrthomas/karate-chrome.现在一切正常,UI 测试可以在 docker ptrthomas/karate-chrome 中运行。 But when I upload the file, the file can not be found in the docker container.但是当我上传文件时,在 docker 容器中找不到该文件。

* driver.inputFile('#uploadfile', '../catalogFiles/BaseTemplate_SetupData.zip')
* submit().mouse('{^div}Upload').click()

So the question is how can I upload the local files to test the UI when I use ptrthomas/karate-chrome?所以问题是当我使用 ptrthomas/karate-chrome 时如何上传本地文件来测试 UI?

You'll need to place the files on the docker container.您需要将文件放在 docker 容器上。 This is indeed not easy, but the moment you want to do CI in the cloud, things become hard.这确实不容易,但是当你想在云端做 CI 的时候,事情就变得困难了。 So you can customize the Docker container start to mount a local folder and then you can refer to the file in your test and things will work.因此,您可以自定义 Docker 容器启动以挂载本地文件夹,然后您可以在测试中引用该文件,一切都会起作用。

Maybe for this step in your test you should try to perform a file-upload using the Karate API testing / HTTP client: https://github.com/intuit/karate/tree/master/karate-core#using-multipart-file也许对于测试中的这一步,您应该尝试使用空手道 API 测试/HTTP 客户端执行文件上传: https : //github.com/intuit/karate/tree/master/karate-core#using-multipart-file

So the trick is to replicate the browser security tokens (typically cookies) in the API call.所以诀窍是在 API 调用中复制浏览器安全令牌(通常是 cookie)。

You can try the distributed testing option, which will upload your test source into the docker container: https://github.com/intuit/karate/wiki/Distributed-Testing - this is not fully tested though, but maybe your team can help contribute.您可以尝试分布式测试选项,它将您的测试源上传到 docker 容器: https : //github.com/intuit/karate/wiki/Distributed-Testing - 虽然这没有经过全面测试,但也许您的团队可以提供帮助贡献。

I am a little bit late, sorry.我有点晚了,对不起。 I faced the problem to upload EXCEL file and want to share example.我遇到了上传 EXCEL 文件并想分享示例的问题。

To upload Excel with Chrome->用 Chrome 上传 Excel->

Feature: test

   Background:
    * configure driver = { type: 'chrome', executable: 'chrome' }

   Scenario: upload Excel

     Given driver 'URL'
     * driver.inputFile('xpath', 'file:src/main/resources/features/MyFolder/MyExcelFile.xlsx')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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