Playwright + Python · Lesson 10 of 37
Module 10: Python Features for Automation
Your task
Implement generate_unique_email(prefix: str = "test") -> str:
Write it in the editor, then press Check answer (Ctrl + Enter).
from pathlib import Path
from datetime import datetime, timedelta
# Pathlib for cross-platform file paths (no Windows backslash bugs):
report_path = Path("reports") / "test_summary.html"
# Generating unique test email:
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
user_email = f"test_{timestamp}@targetqa.com"
# List comprehension to clean extracted table values:
raw_cells = [" Row 1 ", " Row 2 ", " "]
clean_cells = [c.strip() for c in raw_cells if c.strip()]Modern Python features make test automation elegant and concise. In this lesson, you will master list comprehensions, dictionary comprehensions, pathlib for cross-platform file paths, and datetime for timestamp generation. Let's explore modern Python features!
Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
pathlib is object-oriented, uses the clean '/' operator on all operating systems (Windows, macOS, Linux), and eliminates path string formatting mistakes.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___