简体   繁体   中英

About Karate UI Test Automation, How can I upload files when I use 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' }

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()

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

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.

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

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

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.

I am a little bit late, sorry. I faced the problem to upload EXCEL file and want to share example.

To upload Excel with Chrome->

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')

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