Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test form using a ng5-slider with cypress?

Has anyone an idea how to test a ng5-slider (e.g. changing the value) with cypress. I tried the suggestions from the documentation(like using trigger) but I couldn't make it work.

like image 495
rogergl Avatar asked Sep 06 '25 03:09

rogergl


1 Answers

You can try with type('{rightarrow} {rightarrow}') to move the slider towards right and test for the new value obtained. The below sample test that I have tried in ng5-slider sample site and it works fine. Identify the slider and move with type() method. The default slider value is 100 and after moving the slider the changed value is `103'

describe('Try an Ng Slider test ', function () {
  it('Check the slider and test the new slider value', function () {
    cy.visit('https://angular-slider.github.io/ng5-slider/')
    cy.get('a:contains("Go to demo")').parents('.mt-4').find('a').contains("Go to demo").click()
    cy.wait(1000)
    cy.get('#simple-slider').find('ng5-slider').find('span[aria-valuetext="100"]').type('{rightarrow}{rightarrow}{rightarrow}')
    cy.get('#simple-slider').find('ng5-slider').find('span[aria-valuemax="250"]').invoke('attr', 'aria-valuetext', "103")
      .should('have.attr', 'aria-valuetext', '103')
    cy.scrollTo('top');
    })
  })

enter image description here

like image 197
soccerway Avatar answered Sep 08 '25 00:09

soccerway