Playwright + Python · Lesson 6 of 37
Module 6: Object-Oriented Programming
Your task
Create a TestUser class:
Write it in the editor, then press Check answer (Ctrl + Enter).
class BasePage:
def __init__(self, driver):
self.driver = driver
def navigate(self, url: str):
self.driver.get(url)
class LoginPage(BasePage):
def __init__(self, driver):
super().__init__(driver)
self.username_input = "#username"
self.password_input = "#password"
def login(self, username, password):
self.navigate("https://targetqa.com/login")
print(f"Typing {username} into {self.username_input}")Object-Oriented Programming is the foundation of the Page Object Model in Python. In this lesson, you will master classes, __init__ constructors, instance methods, and class inheritance with super() to build clean BasePage abstractions. Let's design scalable classes!
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.
self represents the specific instance of the class, allowing access to instance attributes and methods.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___