admin管理员组文章数量:1391975
During test execution, the Excel file is updated using Apache POI. However, when I attempt to pass the updated file as multipart in the request, the API consistently picks up the old file instead of the modified version. Can anyone provide assistance with this? My code is as follows:
Background: Pre-Requisites
* def reachServicesUrl = karate.get('reachApiBaseUrl')
* def envJwtToken = Java.type('listingsmanagement.fixtures.EnvConfig')
* def jwtToken = envJwtToken.get('JWT_TOKEN')
* def triggerMarketableLocationIdToExcelWritterClass = Java.type(
"listingsmanagement.fixtures.MLocationCreateFileWritter")
* def writeMarketableLocationIdToExcel = triggerMarketableLocationIdToExcelWritterClass
.writeMarketableLocationToExcel(
"src/test/java/listingsmanagement/utilities/marketable-location-to-create.xlsx", "LC001")
* java.lang.Thread.sleep(10000)
* def parsingMarketableLocationIds = Java.type(
"listingsmanagement.fixtures.MLocationCreateSheetParser")
* def getMarketableLocationIds = parsingMarketableLocationIds.convertExcelToJson(
"src/test/java/listingsmanagement/utilities/marketable-location-to-create.xlsx")
* def filepath =
'file:/Users/palanisankar/listings-management-projects/listings-management/automation/target/test-classes/listingsmanagement/utilities/marketable-location-to-create.xlsx'
@Test11
Scenario: Listing successfully created for an available marketable location
Given url reachServicesUrl
And path 'marketable-location', 'create'
And header Content-Type = 'multipart/form-data'
And cookie dev-authorization = jwtToken
* karate.log('Marketable Location Ids: ', getMarketableLocationIds)
* def fileUpload =
"""
{
"read": '#(filepath)',
"filename": "marketable-location-to-create",
"contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}
"""
And multipart file locationCreateFile = fileUpload
When method Post
Then status 200
* def marketableLocationIdsArray = $getMarketableLocationIds[*].['Marketable Location Id']
* print 'Marketable Location Ids Array: ', marketableLocationIdsArray
I need to update an Excel sheet and then pass it in as multipart in the request.
During test execution, the Excel file is updated using Apache POI. However, when I attempt to pass the updated file as multipart in the request, the API consistently picks up the old file instead of the modified version. Can anyone provide assistance with this? My code is as follows:
Background: Pre-Requisites
* def reachServicesUrl = karate.get('reachApiBaseUrl')
* def envJwtToken = Java.type('listingsmanagement.fixtures.EnvConfig')
* def jwtToken = envJwtToken.get('JWT_TOKEN')
* def triggerMarketableLocationIdToExcelWritterClass = Java.type(
"listingsmanagement.fixtures.MLocationCreateFileWritter")
* def writeMarketableLocationIdToExcel = triggerMarketableLocationIdToExcelWritterClass
.writeMarketableLocationToExcel(
"src/test/java/listingsmanagement/utilities/marketable-location-to-create.xlsx", "LC001")
* java.lang.Thread.sleep(10000)
* def parsingMarketableLocationIds = Java.type(
"listingsmanagement.fixtures.MLocationCreateSheetParser")
* def getMarketableLocationIds = parsingMarketableLocationIds.convertExcelToJson(
"src/test/java/listingsmanagement/utilities/marketable-location-to-create.xlsx")
* def filepath =
'file:/Users/palanisankar/listings-management-projects/listings-management/automation/target/test-classes/listingsmanagement/utilities/marketable-location-to-create.xlsx'
@Test11
Scenario: Listing successfully created for an available marketable location
Given url reachServicesUrl
And path 'marketable-location', 'create'
And header Content-Type = 'multipart/form-data'
And cookie dev-authorization = jwtToken
* karate.log('Marketable Location Ids: ', getMarketableLocationIds)
* def fileUpload =
"""
{
"read": '#(filepath)',
"filename": "marketable-location-to-create",
"contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}
"""
And multipart file locationCreateFile = fileUpload
When method Post
Then status 200
* def marketableLocationIdsArray = $getMarketableLocationIds[*].['Marketable Location Id']
* print 'Marketable Location Ids Array: ', marketableLocationIdsArray
I need to update an Excel sheet and then pass it in as multipart in the request.
Share Improve this question edited Mar 16 at 7:22 tucuxi 18k2 gold badges47 silver badges80 bronze badges asked Mar 14 at 9:13 Kash SkKash Sk 311 silver badge2 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 1Fixed Code:
`
Background: Pre-Requisites
* def ServicesBaseUrl = karate.get('BaseUrl')
* def envJwtToken = Java.type('fixtures.EnvConfig')
* def jwtToken = envJwtToken.get('JWT_TOKEN')
* def parsingMarketableLocationIds = Java.type("fixtures.MLocationCreateSheetParser")
* def getMarketableLocationIds = parsingMarketableLocationIds.convertExcelToJson("target/test-classes/location-to-create.xlsx")
* def filepath = 'file:<absolute Path(target)>'
@Test11
Scenario: Listing successfully created for an available location
Given url ServicesBaseUrl
And path 'location', 'create'
And header Content-Type = 'multipart/form-data'
And cookie dev-authorization = jwtToken
* karate.log('Location Ids: ', getLocationIds)
* def fileUpload =
"""
{
"read": '#(filepath)',
"filename": "marketable-location-to-create",
"contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}
"""
And multipart file locationCreateFile = fileUpload
When method Post
Then status 200
本文标签: javaHandling File Uploads with Dynamic Excel File in Karate Test FrameworkStack Overflow
版权声明:本文标题:java - Handling File Uploads with Dynamic Excel File in Karate Test Framework - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744665796a2618524.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
test-classes
folder (or the target directory). This ensures that the latest version of the sheet is used during test execution or runtime. – Kash Sk Commented Mar 16 at 18:38