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

206
Views
Valide el clic del botón hasta que se deshabilite usando Cypress

Estoy tratando de validar un clic de botón usando Cypress. Debería poder hacer clic en un botón cuando haya diapositivas disponibles. Si no hay diapositivas, no se debe hacer clic en el botón y se deshabilita agregando una clase deshabilitada al botón. ¿Alguien puede sugerir una mejor solución para validar este escenario?

A continuación se muestra el código HTML cuando la próxima diapositiva esté disponible:

 <button class="arrow"><span class="screen-reader-only">Previous slide</span></button>

Código HTML cuando la siguiente diapositiva no está disponible y se agrega una clase deshabilitada:

 <button class="arrow disabled"><span class="screen-reader-only">Previous slide</span></button>

Código Cypress que estoy tratando de validar:

 it('Validate the button is clickable',()=> { cy.get('.arrow') .then(($btn) => { if($btn.is(":disabled")){ $btn.should('have.class','disabled') .and('have.css','background-color','rgb(62, 64, 69)') cy.log('Arrow is disabled and not clickable') } else { cy.wrap($btn).click() expect($btn).to.have.css('background-color','rgb(172, 42, 0)') } })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

También puede usar .hasClass('disabled') ya que se agregó una clase deshabilitada. Además, dado que habría varios botones de flecha, use each en lugar de then .

 it('Validate the button is clickable', () => { cy.get('.arrow') .should('be.visible') .each(($btn) => { if ($btn.hasClass('disabled')) { cy.wrap($btn) .should('have.class', 'disabled') .and('have.css', 'background-color', 'rgb(62, 64, 69)') cy.log('Arrow is disabled and not clickable') } else { expect($btn).to.have.css('background-color', 'rgb(172, 42, 0)') cy.wrap($btn).click() } }) })
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!