how to upload a file with karate?

Viewed 379

I know the question has already been asked, but I’m having trouble uploading a file with karate. I have a file called "example.pdf" in my project. I put this document in a "assets" folder

I tried to build on the example of the documentation here. https://github.com/karatelabs/karate/tree/master/karate-core#file-upload

and here’s my code:

* configure driver = { type: '#(driverType)', executable: '#(driverExecutable)', addOptions: #(driverOptions), headless: #(driverHeadless), webDriverSession: #(webDriverSession), showDriverLog: true }
    Given waitFor('#upload)
    And driver.inputFile('#upload', '../assets/pdf-exemple.pdf')

My browser is chrome what am I missing ?

Thanks for your help

EDIT: Thank you for your feedback, I’ll try to clarify. Meanwhile I have some details. In fact the browser is chromedriver and geckodriver

const drivers = {
    path: "./src/test/java/drivers/",
    chromedriver: "95.0.4638.69",
    geckodriver: "0.30.0",
};

So I think I have to use the approach "multipart file". I tried this code, and my test passes without error, but does not handle the expected functionality (uploading an attachment)

And url 'https://url file file to upload/test'  //page where is the area to upload a file
And waitFor(data.inputPJ).click() //area where you click on the application to upload a file
And multipart file file = { read: '../../assets/pdf-exemple.pdf', filename: '../../assets/pdf-exemple.pdf' }
And method post

But in my application this code has no effect, in the application I should have : enter image description here

But the uploaded file doesn't appear, and I have:

enter image description here

The difficulty here is that I have no mistake. I will continue to try to understand the doc

I am at your disposal to provide more information

0 Answers
Related