How to create Pre- request script for post request

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:
I want to create pre-request script to test different variable using data from CSV file for POST
Is it possible to write test cases to validate premium amount from CSV file?
PaymodeFrequency TermPeriod " ExpectedPremiumAmount"
1 10 12762
1 15 18801
1 20 null
1 25 null
1 30 null
2 10 6508.62
2 15 9588.51
2 20 null
2 25 null
2 30 null
3 10 3318.12
3 15 4888.26
3 20 null
3 25 null
3 30 null
4 10 1116.68
4 15 1645.09
4 20 null
4 25 null
4 30 null

Details (like screenshots):
I want to test different PlanOptionId, TermPeriod and PayModeFrequency. I want to use CSV to change data inputs and validate the test result is correct

This is the body
{
“TransactionGUID”: “654e785a-df57-418a-b474-12b6eafe4eb5”,
“SourceName”: “Acme”,
“Gender”: 1,
“Birthdate”: “1954-05-30”,
“NicotineId”: 1,
“RateClass”: 1,
“Product”: “LP”,
“CoverageAmount”: 1000000,
“TableRating”: 1,
“FlatExtraAmount”: 0,
“FlatExtraDuration”: 0,
“PlanOptions”: [
{

  "PlanOptionId": "cms-int-lp-1-10",

“TermPeriod”: 10,
“PayModeFrequency”: 1
}
]
}

This is the body results
{
“TransactionGUID”: “654e785a-df57-418a-b474-12b6eafe4eb5”,
“PlanOptions”: [
{
“PlanOptionId”: “cms-int-lp-1-10”,
“Premium”: 12762
}
]
}
How I found the problem:
I don’t know how to create Pre-request script or test cases

I’ve already tried:

Hi @dinaazsalem

The information that you need should all be here;


You would need to build your CSV file,
Run your collection using collection runner (so you can import the CSV file)
And to use values from the data file in your Tests or Pre-request Script code you would need

pm.iterationData.get("value")

It should all be covered in that link.