Automating CSV Data for Reliable API Testing

Automating CSV Data for Reliable API Testing

Recently, I tackled a practical challenge in my API automation work and wanted to share both the problem and my solution — in case it helps someone out there in a similar boat!

🚧 The Problem

In my current project, one of our APIs is responsible for onboarding users through the upload of CSV files. This API checks the uploaded data against existing backend records and rejects the entire upload if it detects any duplicates

Now, here comes the tricky part: My test needs to run repeatedly (automated), but each time it runs with the same CSV file, the API fails because duplicate entries already exist in the system.

Two workarounds were initially proposed:

  1. Manually upload a new CSV file every time (not scalable)
  2. Reset the database daily (risky and not practical for CI/CD)

I knew we could do better.

💡 My Thought Process

Instead of changing the whole database or managing tons of files manually… Why not generate unique data programmatically for every test run?

That way:

  • The API sees fresh data every time
  • The test runs on schedule (hands-free!)
  • No need to reset the DB or manage uploads manually


🛠️ The Solution I Built

I created an R&D project to build an automated solution that:

  1. Create a dummy API locally that mimics the real endpoint behavior (CSV upload, duplicate checks). Later, I deployed it on a dummy server to test the flow in a CI/CD environment.
  2. Used faker.js to dynamically generate unique user data (ID, Name, etc..)
  3. Write that data into a temp.csv file using Node.js
  4. Use Postman to send a form-data request with the CSV
  5. Executed the API request via Newman to upload the CSV file.
  6. Runs in GitHub Actions every 30 minutes or is triggered manually as needed.
  7. Sends me the test result report in Telegram, with a full HTML report with pass/fail status


⚙️ Technologies Used:

  • Node.js for scripting
  • faker.js for generating fake (but unique) data
  • Newman to run Postman tests in CI
  • GitHub Actions for automation
  • Telegram Bot API for real-time notifications


The Result

  • ✅ Fully automated test
  • 📂 Always fresh and valid data
  • 🧪 No duplicates = no failed tests due to data
  • 📲 Real-time result delivery
  • 💥 100% hands-off CI/CD experience


My Key Learnings

  • Automating dynamic test data prevents flaky API test failures due to duplicates
  • Manual work, like resetting databases or uploading new files daily, isn't scalable
  • Real-time Telegram alerts provide quick visibility into test outcomes [you can use Gmail, Slack, or any other platform to get the real-time update]
  • A simple R&D initiative can lead to valuable production-ready solutions


What’s Next?

This R&D setup is now complete and validated. I’ll be integrating it into our production test automation pipeline soon.


LIVE API + Repository Link

☑️API Endpoint: https://playing-with-api.onrender.com/docs/

📂Github Repo: https://github.com/Sisadia/playing-with-api


Why I'm Sharing

This might seem like a small challenge, but it's a real-world pain point in test automation — and solving it with code gave me the flexibility to focus on testing logic rather than data cleanup.

Happy testing! ✨

My two cents: if I understand the code correctly, you save the data to the database during each test run and delete it in the teardown process. Therefore, using Faker.js to generate fresh data each time seems unnecessary to me. Reimporting the same CSV/data already gives you a unique dataset for every test execution.

Like
Reply

To view or add a comment, sign in

More articles by Sadia Islam

  • Why Your API Call is Hitting Twice: Understanding Preflight & XHR

    প্রায় সময়েই ডেভ টুলসের নেটওয়ার্ক ট্যাবে আমি একই এপিআই দুইবার কল যাচ্ছে দেখতে পাই। একই API দুইবার কল হলেও এদের টাইপ…

    4 Comments
  • Host your Allure Report on GitHub Pages with GitHub Actions

    আমরা সবাই শুনেছি বা আমাদের দৈনন্দিন জীবনে Allure Report ব্যবহার করেছি। এছাড়াও, গিটহাব অ্যাকশন এবং গিটহাব পেজ সাধারণত…

    2 Comments
  • Improving Your Software Testing Workflow with Chrome Dev Tools: Learn Essential Features

    আমরা সবাই কমবেশি DevTool এই শব্দটার সাথে পরিচিত। সব ব্রাউজারেই Dev Tool রয়েছে। এর মধ্যে Chrome DevTools সবথেকে বেশি…

    5 Comments
  • Dynamic data for Test Automation

    টেস্ট অটোমেশনের অনেক বড় একটা পার্ট হচ্ছে ফেক ডেটা জেনারেট করে সেটাকে ব্যবহার করা। অনেকই আমরা এক্সেল ফাইল ব্যবহার করি…

  • findElement() and findElements() in Selenium WebDriver

    আমরা যদি কোন ওয়েব পেইজের সাথে ইন্টারেক্ট করতে চাই তাহলে ওয়েব পেইজের ওয়েব এলিমেন্ট গুলো কোথায় আছে সেটা সবার আগে বের…

    2 Comments

Others also viewed

Explore content categories