本文介绍了关于Karate UI测试自动化,当我使用karate-chrome时如何上传文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行docker(ptrthomas/karate-chrome).而且我已经配置了驱动程序

I've got docker(ptrthomas/karate-chrome) running.And I have configurated the driver

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

现在一切似乎都还可以,UI测试可以在docker ptrthomas/karate-chrome中运行.但是当我上传文件时,在Docker容器中找不到该文件.

Everything seems ok now, the UI test can run in the docker ptrthomas/karate-chrome.But when I upload the file, the file can not be found in the docker container.

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

所以问题是当我使用ptrthomas/karate-chrome时如何上传本地文件以测试UI?

So the question is how can I upload the local files to test the UI when I use ptrthomas/karate-chrome?

推荐答案

您需要将文件放置在docker容器上.这确实不容易,但是当您想在云中进行CI时,事情就变得很困难.因此,您可以自定义Docker容器开始以挂载本地文件夹,然后可以在测试中引用该文件,然后一切正常.

You'll need to place the files on the docker container. This is indeed not easy, but the moment you want to do CI in the cloud, things become hard. 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.

也许对于测试的这一步,您应该尝试使用空手道API测试/HTTP客户端执行文件上传: https://github.com/intuit/karate/tree/master/karate-core#using-multipart-file

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调用中复制浏览器安全令牌(通常为cookie).

So the trick is to replicate the browser security tokens (typically cookies) in the API call.

您可以尝试使用分布式测试选项,该选项会将您的测试源上载到Docker容器中: https://github.com/intuit/karate/wiki/Distributed-Testing -虽然尚未经过全面测试,但也许您的团队可以提供帮助.

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.

这篇关于关于Karate UI测试自动化,当我使用karate-chrome时如何上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 18:37