I want to create a function in cypress in which I can call as appropriate the environment on which to login and username. For example I want to append cy.login (live, username1)
I don't know exactly how to write to be correct in the code
Cypress.Commands.add('Login', (env,username) => {
env(staging) = cy.visit('https://staginglink')
env(live) = cy.visit('https://livelink')
username(username1) = {
cy.get('input[name="Parameter.UserName"]').type('username1')
cy.get('input[name="Parameter.Password"]').type('password1')
}
cy.contains('Login').click()
})
So your custom command will be like:
Cypress.Commands.add('Login', (env, username) => {
cy.visit(env)
cy.get('input[name="Parameter.UserName"]').type(username)
cy.get('input[name="Parameter.Password"]').type('password1')
cy.contains('Login').click()
})
Then in your test you can just write:
cy.Login('https://staginglink','someusername1')
cy.Login('https://livelink','someusername2')