Closed faelin closed 2 weeks ago
Thanks for the suggestion! I’ve decided not to add a parameterized variables feature because it can already be done with scripts, providing more flexibility. Here's how you can do it:
{
testData: [
{
testVariable: 'test1'
},
{
testVariable: 'test2'
}
]
}
setUpVariables = (variables) => {
Object.entries(variables).forEach(([key, value]) => jc.variables.set(key, value))
}
const testData = jc.testSuiteVariables.get("testData")
for (let data of testData) { setUpVariables(data) // Execute your tests here }
If you prefer using CSV files, define a helper function to read them
```js
readCsvAsJson = (filePath) => {
const fileContent = jc.readFile(filePath)
const csvParse = require('csv-parse/lib/sync')
return csvParse.parse(fileContent, {
columns: true,
skip_empty_lines: true
})
}
Then use it like this:
const testData = readCsvAsJson("test.csv")
Is your feature request related to a problem?
In order to test API endpoints that have multiple possible values, I have created test-suites that run through many possible combinations of variables. However, if I were to make a change to the API schema, I would need to update dozens or hundreds of requests to accommodate the new schema requirements. This is a huge pain!
Describe the solution you'd like
It would greatly reduce the number of requests that I need to define if I could create "parameterized" variables for a collection, so that the collection could be automatically run with a "matrix" of combinations automatically generated by the runner, instead of having to re-run multiple times with different variables.
Additional context
Many test-frameworks for code development have parameterized "matrix" solutions that automatically calculate combinations of parameters, running the same tests over and over with different combinations.