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