Parametrized Object Method | Bondar Academy
Course: Cypress UI Testing with JavaScript
Module: Page Object Design Pattern
Instructor: Artem Bondar
Lesson Summary
In this lesson, we learn how to create parameterized page object methods to enhance reusability in test automation. The focus is on automating interactions with forms using the Cypress framework. Creating Page Objects We start by creating a new page object file named FormLayoutsPage.js and define a class FormLayoutsPage . We then export an instance of this class: export const onFormLayoutsPage = new FormLayoutsPage(); Submitting Forms We create a method called submitUsingGridForm that accepts parameters for email , password , and option index . This method encapsulates the logic for form submission: Type email and password using placeholders. Select a radio button based on the provided index. Click the Sign In button. In the test, we call this method and pass actual values: onFormLayoutsPage.submitUsingGridForm('[email protected]', 'welcome', 0); Using Booleans for Checkboxes A similar method, submitBasicForm , is created for a basic form that includes a checkbox. A Boolean flag determines if the checkbox should be selected: if (isCheckboxSelected) { /* select checkbox */ } Implementing Date Pickers We also create a DatePickerPage.js for handling date selections with two methods: selectCommonDatePickerDateFromToday selectRangePickerDateFromToday Both methods utilize parameters to select dates, allowing for flexible test scenarios. Conclusion To improve reusability, parameterize methods with meaningful names and limit to three parameters for clarity. This approach allows for versatile test implementations without code duplication.