0

I am following POM model in cypress where I have a use case to tick checkboxes in page from json file. My files are as below: homePageTest.cy.js

it("some test", () => {
        cy.fixture("jsonValues").then((data) => {
        homePage.populateDataBasedOnJsonValues(data)
        });
    });

homepage.js

class HomePage{

_getcheckBox(question) {
        this.get("div[class$='checkbox-component-" + question + "'] > label > input");
    }

 populateDataBasedOnJsonValues(answers) {
        for (let key in answers) {
            const question = _getcheckBox(answers[key]);
            question.click()
        }
    }
}
export default HomePage;

On running the code I am getting following error: TypeError _homePage.default.populateDataBasedOnJsonValues is not a function

All other methods without parameter (e.g answers) are working fine. But this one with parameter is not working well. I have tried to move the method in commands file and it is working, but I can't move it in commands file as that is not where it belongs to. I am not sure mistake I am making, have tried adding this. before _getcheckBox(answers[key]); but that also doesnt work. Can someone please help, new to cypress and JS. TIA `

1 Answers1

3

The error message indicates you are not creating an instance of the class, but are just using the imported class definition directly.

This is the general pattern to follow, you will need to adjust paths etc.

import HomePage from '../Hompage.js'  

const homePage = new HomePage()

it("some test", () => {
  cy.fixture("jsonValues").then((data) => {
    homePage.populateDataBasedOnJsonValues(data)