Methods Parametrization | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Page Objects
Instructor: Artem Bondar
Lesson Summary
In this lesson, we focus on creating a parameterized page object method to enhance reusability in our testing framework. We will work specifically on the Form Layouts page and implement methods to submit two different forms: the grid form and the inline form. Creating the Page Object First, we create a new page object class named FormLayoutsPage.ts . The class will include: A constructor to initialize the page field. Methods to handle form submissions. Implementing the Grid Form Submission We define a method called asyncSubmitUsingGridForm that takes three parameters: email : string password : string optionText : string This method fills out the grid form using the provided parameters instead of hardcoded values, improving flexibility and reusability. Implementing the Inline Form Submission Next, we create a method called asyncSubmitInlineForm with the following parameters: fullName : string email : string rememberMe : boolean This method also utilizes the parameters to fill out the inline form, allowing for dynamic test scenarios. Enhancing Method Clarity To improve understanding, we can add annotations to our methods. For example: /** * Submits inline form with user details. * @param fullName - Valid test user full name. * @param email - Valid test user email. * @param rememberMe - Pass true to select remember me checkbox. */ This documentation makes it clear what each method does and what parameters are expected, enhancing code readability and maintainability. By parameterizing page object methods, we significantly improve their reusability, allowing for varied test scenarios without modifying the underlying method logic.