5. Reusable Automation Functions, *args, **kwargs & Lambdas

Designing Automation Helper Functions

# Default arguments & type hints:
def wait_and_click(locator: str, timeout: int = 10, check_visible: bool = True):
    print(f"Waiting up to {timeout}s for {locator}")

# Variable keyword arguments (kwargs) for flexible parameters:
def create_test_user(username: str,
kwargs):
user = {"username": username, "role": kwargs.get("role", "STANDARD")}
return user

Task

  • Implement build_api_url(endpoint, base_url="https://targetqa.com", **params):
  • 1. Strip leading slash from endpoint.
  • 2. If params are provided, append "?param=val&..." to the URL.
  • 3. Return the full URL string.
πŸ’‘Common doubts
Did you like the problem?
Lesson 5 of 37
Python
Loading code editor…
Next