Playwright + Python · Lesson 11 of 37

0/37 done

Module 11: Python for Automation

11. Reusable Utilities, Type-Safe Enums & Configuration Handlers

16 minlesson

Your task

Implement get_env_url(env_name: str) -> str:

  1. Accept env_name string.
  2. If env_name.lower() == "dev", return "https://dev.targetqa.com".
  3. If env_name.lower() == "staging", return "https://staging.targetqa.com".
  4. Default to "https://targetqa.com".

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

Enums & Config Models in Python

python
from enum import Enum

class Environment(str, Enum):
    DEV = "https://dev.targetqa.com"
    STAGING = "https://staging.targetqa.com"
    PROD = "https://targetqa.com"

class BrowserType(str, Enum):
    CHROME = "chrome"
    FIREFOX = "firefox"
    EDGE = "edge"

class TestConfig:
    DEFAULT_TIMEOUT: int = 30
    DEFAULT_ENV: Environment = Environment.STAGING

Key Takeaways & Walkthrough Summary

Welcome to Phase 2! In this module, we connect Python directly to test automation architecture. You will learn to build reusable helper functions, type-safe enums for browsers and environments, and structured configuration handlers. Let's design maintainable automation code!

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.

Common Doubts & Lesson Q&A

Why inherit from (str, Enum) in Python enums?

Inheriting from both str and Enum allows the enum to be compared directly with strings and easily serialized into JSON configurations.

Ready? Solve the task in the editor

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

Python
Skip