Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Collection to use data files specified at Folder level #1529

Closed
CharlieSnowCode opened this issue Apr 24, 2024 · 8 comments
Closed

Run Collection to use data files specified at Folder level #1529

CharlieSnowCode opened this issue Apr 24, 2024 · 8 comments
Labels
feature request New feature or request

Comments

@CharlieSnowCode
Copy link

I'm testing an API that has about a dozen unique Requests. I would like each of those Request types to be tested using their own data file, so I assume each would need its own folder. The Collection would have positive and negative cases and might look like:

Data Driven (Collection)

  • Positive Cases (Folder)
    • Create (Folder, uses PositiveCreate.csv)
      • CreateObject (Request)
    • Locate (Folder, uses PositiveLocate.csv)
      • LocateObject (Request)

...
Setting different test data files at each folder is persisted, but when I Run All at the Collection level - none of the specified data files are used. Is there a way to do this? If not I would like to request it as a new feature. Thank you!

We are using the paid version.

@CharlieSnowCode CharlieSnowCode added the feature request New feature or request label Apr 24, 2024
@rangav
Copy link
Collaborator

rangav commented Apr 24, 2024

@CharlieSnowCode Thanks for the feedback. Currently, it's not possible. I will review it.

Alternatively, you can use scripting to read custom data files at the request level and set variable values.

Could you please try the scripting option and let me know your feedback?

@CharlieSnowCode
Copy link
Author

I'll give it a try, could you help me get started? If each data file has 5 rows of values, how would I iterate through them? Where would the script be, in the PreRun Scripting or a custom filter file? If the file would be loaded by a custom filter, same question - how to iterate over the sets of values?

@rangav
Copy link
Collaborator

rangav commented Apr 24, 2024

  • Copy the below script to your folder settings - PreRun Scripting and modify as needed
  • change the filepath and the variable name to your defined name
var fileData = await tc.readFile("thunder-tests/test.csv");
var papaparse = require('papaparse');

var options = { delimiter: ',', quoteChar: '"', escapeChar: '"', header: true };
let csv = papaparse.parse(fileData, options).data;
console.log(csv);

var iteration = tc.info.currentIteration;

var iterationCsvData = csv[iteration];
if(iterationCsvData){
  console.log(iterationCsvData);
  var name = iterationCsvData["name"];
  console.log("name", name);

  // set variable using request scope so the value is not saved to active env file
  tc.setVar("name", name, "request");
}

sample csv file - test.csv

name,score
mike,444
john,555

@CharlieSnowCode
Copy link
Author

I've attached the (Pre run) script and the .csv I'm using, a snapshot of the (Restful Booker) Request and of the output. It seems like the script sees the file, but the Request is only executed once and none of the values are populated.
preRunScript.txt
BookerDataGood.csv
Booking
Output.txt

@rangav
Copy link
Collaborator

rangav commented Apr 25, 2024

I just now tested the using the same request body and it worked for me

  • used the same script and csv file
  • script is used in collection settings pre-run scripting
Screenshot 2024-04-25 at 09 55 32

You need to increase the iterations count in run collection view
Screenshot 2024-04-25 at 10 04 13

@CharlieSnowCode
Copy link
Author

Very interesting, I created a Collection and copied the script to it (I was using a folder inside an existing Collection which still doesn't work). Then increased the Iterations to 3 and it worked. Many thinks for your reply.
I would however still request the original feature be implemented, as this solution will have us creating 2 dozen Collections - which can't be executed from the UI all at once. I'm sure they can be from the CLI, but the command would be a large paragraph.

@rangav
Copy link
Collaborator

rangav commented Apr 25, 2024

For advanced use cases we recommend using scriping or cli is the best solution currently.

@rangav
Copy link
Collaborator

rangav commented Apr 30, 2024

Closing this issue as you can achieve the functionality using scripting

@rangav rangav closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants