Uploaded February 2024 | Updated November 2026, 2 hours ago
This video shows how to randomly pick two elements and then remove class "Secret" from them using jQuery method "$.removeClass". We are going to use cy.sample command from github.com/bahmutov/cypress-map plugin. Full source code is at glebbahmutov.com/cypress-examples
// cy.sample commands comes from the cypress-map
cy.get('#names li').sample(2).invoke('removeClass', 'secret')
// verify the the result
cy.get('#names li.secret').should('have.length', 2)
cy.get('#names li:not(.secret)').should('have.length', 2)
This video shows how to randomly pick two elements and then remove class "Secret" from them using jQuery method "$.removeClass". We are going to use cy.sample command from github.com/bahmutov/cypress-map plugin. Full source code is at glebbahmutov.com/cypress-examples
// cy.sample commands comes from the cypress-map
cy.get('#names li').sample(2).invoke('removeClass', 'secret')
// verify the the result
cy.get('#names li.secret').should('have.length', 2)
cy.get('#names li:not(.secret)').should('have.length', 2)


