Selenium + Python · Lesson 35 of 43

0/43 done

Module 35: Test Data

35. Data-Driven Testing with JSON, CSV & pytest Parameters

16 minlesson

Your task

Implement make_user(prefix):

  1. Return {"email": f"{prefix}_{int(time.time())}@targetqa.com"}

Write it in the editor, then press Check answer (Ctrl + Enter).

Data-Driven Testing in Python

python
import json
import time

def load_test_credentials(file_path: str):
    with open(file_path, "r", encoding="utf-8") as f:
        return json.load(f)

def generate_random_user():
    return {
        "username": f"user_{int(time.time())}@targetqa.com",
        "role": "STANDARD"
    }

Key Takeaways & Walkthrough Summary

Hardcoding test data leads to brittle tests and limited coverage. In this lesson, you will master loading test datasets from JSON and CSV files and generating dynamic test users. Let's master test data!

Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why use dynamic timestamps in user emails?

Static emails trigger 'Email already registered' errors on subsequent test runs. Dynamic timestamps guarantee unique records.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip