Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
Cypress: elija el nombre de usuario y el entorno de una lista

Tengo el siguiente código e idea y quiero hacerlo funcional para poder iniciar sesión en la prueba con la función como cy.login (en vivo, nombre de usuario):

 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() })

Ciertamente mi código no es funcional, pero quiero entender la idea y cómo escribirlo para poder usar una variable varias veces.

Y en cypress.json

 {"env": { "staging": "https://staginglink", "live": "https://livelink" }} {"username": { "username1": "username": "username1", "password" : "password1" , "username2": "username": "username2", "password" : "password2" , }}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Comience con una solución para cypress.json

 { "env": { "links": { "staging": "https://staginglink", "live": "https://livelink" } "users": { "user1": {"username": "username1", "password" : "password1"}, "user2": {"username": "username2", "password" : "password2"}, } }

Llamar con parámetros de cadena:

 cy.login('live', 'user2')

Dominio:

 Cypress.Commands.add("login", (requiredEnv, requiredUser) => { const links = Cypress.env('links'); // links section above const link = links[requiredEnv]; // if passed "live" or "staging", gives the // correct property of links section cy.visit(link) const users = Cypress.env('users'); // users section above const user = users[requiredUser]; const username = user.username; // "user1" -> gives "username1" // "user2" -> gives "username2" const password = user.password; // "user1" -> gives "password1" // "user2" -> gives "password2" cy.get('input[name="Parameter.UserName"]').type(username) // don't put quotes around variable cy.get('input[name="Parameter.Password"]').type(password) // don't put quotes around variable cy.contains('Login').click() })
about 4 years ago · Juan Pablo Isaza Report

0

En su Cypress.json puede organizar sus datos de esta manera:

 { "env":{ "staging":"https://staginglink", "live":"https://livelink" }, "users":{ "user1":{ "username":"username1", "password":"password1" }, "user2":{ "username":"username2", "password":"password2" } } }

Luego, en su prueba, puede acceder a los datos como:

 Cypress.config('users').user1.username. //gets username1 Cypress.env('staging'). //gets staging link

Su comando personalizado se verá así:

 Cypress.Commands.add('login', (user, env) => { cy.visit(env) cy.get('input[name="Parameter.UserName"]').type(user.username) cy.get('input[name="Parameter.Password"]').type(user.password) cy.contains('Login').click() })

Desde tu prueba puedes escribir:

 cy.login(Cypress.config('users').user1, Cypress.env('staging')) cy.login(Cypress.config('users').user2, Cypress.env('live'))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!