this is my code
/// \<reference types = "cypress" /\>
class LoginPage
{
visit()
{
cy.visit("https://ec2-35-179-99-242.eu-west-2.compute.amazonaws.com:2021/")
}
username(name)
{
const field = cy.get('[id=UserName]')
field.clear()
field.type(name)
return this
}
Password(pwd)
{
const pass = cy.get('[id=Password]')
pass.clear()
pass.type(pwd)
return this
}
Submit()
{
const button = cy.get('[type=submit]')
button.click()
}
}
export default LoginPage
/// \<reference types = "cypress" /\>
import LoginPage from './PageObject/LoginPage'
it('valid test', function()
{
const Login = new LoginPage()
Login.visit()
Login.username('arslan')
Login.Password('123')
Login.Submit()
})
i make object of Login class
const Login = new LoginPage()
but getting error getting error _LoginPage.default is not a constructor
Try using a named export
export class LoginPage {
visit() {
cy.visit("https://ec2-35-179-99-242.eu-west-2.compute.amazonaws.com:2021/")
}
...
}
and import like this
import { LoginPage } from './PageObject/LoginPage'
You need to use function reserved name before all your functions names or declare the functions like a const using an arrow function like:
function visit()
{
cy.visit("https://ec2-35-179-99-242.eu-west-2.compute.amazonaws.com:2021/")
}
or
const visit = () =>
{
cy.visit("https://ec2-35-179-99-242.eu-west-2.compute.amazonaws.com:2021/")
}