Senior
What design patterns have you used besides Page Object?
sobes.tech AI
Answer from AI
In addition to the Page Object pattern, I often use the following patterns in test automation:
- Factory — for creating page or element objects with different configurations, which simplifies test scaling.
- Singleton — for managing a single instance of the browser driver to avoid conflicts and redundant resource creation.
- Facade — for creating a simplified interface for interacting with complex subsystems, such as APIs or databases.
- Builder — for step-by-step creation of complex test data or objects.
Example of using Factory to create pages:
public class PageFactory {
public static BasePage getPage(String pageName, WebDriver driver) {
switch(pageName) {
case "Login":
return new LoginPage(driver);
case "Dashboard":
return new DashboardPage(driver);
default:
throw new IllegalArgumentException("Unknown page: " + pageName);
}
}
}