Middle
What design patterns do you use in your automation framework?
sobes.tech AI
Answer from AI
The following design patterns are often used in test automation:
- Page Object Pattern — for encapsulating the logic of interacting with UI elements into separate classes, which facilitates maintenance and reuse of code.
- Singleton — for creating a single instance of a driver or configuration manager.
- Factory Pattern — for creating test data objects or framework components, allowing easy changes of implementations.
- Strategy Pattern — for selecting different algorithms or methods of executing tests (e.g., different login methods).
- Observer Pattern — for implementing events and logging in tests.
Example of using Page Object in Python with Selenium:
class LoginPage:
def __init__(self, driver):
self.driver = driver
self.username_input = driver.find_element_by_id('username')
self.password_input = driver.find_element_by_id('password')
self.login_button = driver.find_element_by_id('login')
def login(self, username, password):
self.username_input.send_keys(username)
self.password_input.send_keys(password)
self.login_button.click()