I have the following code and idea and I want to make it functional so that I can log in to the test with the function as cy.login (live, username):
Cypress.Commands.add("login", (env,username) => {
env = Cypress.env('staging')
env = Cypress.env('live')
username = Cypress.username('username1')
username = Cypress.username('username2')
cy.get('input[name="Parameter.UserName"]').type('username')
cy.get('input[name="Parameter.Password"]').type('password1')
cy.contains('Login').click()
})
Certainly my code is not a functional one, but I want to understand the idea and how to write it in order to be able to use a variable several times.
And in cypress.json
{"env": {
"staging": "https://staginglink",
"live": "https://livelink"
}}
{"username": {
"username1": "username": "username1", "password" : "password1" ,
"username2": "username": "username2", "password" : "password2" ,
}}