how to use embedded expressions for multipart file

2019-07-13 17:40发布

问题:

I need to replace dynamic value 'tenantID' for multipart data input json file. I need to a way to replace a value for multipart input json file. Below code shows the details:

    * def tenantID = '2345'; 
* configure charset = null
Given multipart file properties = { read: 'classpath:ic/feature/REST/TestData/linkedInOauth2RESTInput.json', filename: 'blob', contentType: 'application/json' }
Given multipart file appIcon = { read: 'classpath:ic/feature/REST/TestDataGlobal_Weather.png', filename: 'Global_Weather.png', contentType: 'image/png' }


When method post

In the above code I need to replace the 'tenantID' in the 'linkedInOauth2RESTInput.json' file . Since this is multipart input i am not understanding how to replace its content.

Waiting for response. Thanks in Advance

回答1:

Write a Java utility to modify the file linkedInOauth2RESTInput.json before you do the upload. You can use the file: prefix instead of classpath:, so I recommend you save the temp file into the target folder, then you can do this:

Given multipart file properties = { read: 'file:target/linkedInOauth2RESTInput.json', filename: 'blob', contentType: 'application/json' }

But I agree that this is complicated, so I'm making a change to Karate so that you can instead of read, pass a value.

EDIT: this might also work depending on the server in this case:

* def tenantID = '2345';
* def json = read('classpath:ic/feature/REST/TestData/linkedInOauth2RESTInput.json')
* multipart field properties = json


标签: karate