javascriptnode.jsjsoncypressobject-model

Error in cypress object model : Cannot find module '../ObjectModel/LoginPage'


I tried to write object model in vscode, to create an object.

This is login2 :

/// <reference types="Cypress" />
          
import LoginPage from "../../integration/ObjectModel/LoginPage"

describe('home page', () => {
    it('loginPage', function () {
        const lp = new LoginPage()
    })
})

This is object page :

class LoginPage {
    visit(){
        cy.visit('https://facebook.com');
    }

    fillEmail(value){
        const feild = cy.get('#email')
        feild.clear()
        feild.type(value)
        return this
    }
    
    fillPassword(value){
        const feild = cy.get('#pass')
        feild.clear()
        feild.type(value)
        return this
    }
    
    submit(){
        const button = cy.get('#u_0_b')
        button.click()
    }
}

export default LoginPage;

This is the path of files: enter image description here and this the error enter image description here

How I can solve it? I tried to change the path as I read, also it does not solved.


Solution

  • Seems like the file login2.js is in the same directory as ObjectModel. Thus you only need to import file like this:

    import LoginPage from "./ObjectModel/LoginPage"