Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
Cypress hoverover GUI effect test

I started using cypress nowadays to learn better and deeper. I am faced with a problem that I can't handle. The problem is some kind of GUI effect working with mouse hover. While hovering my mouse on the element I can't see any information change into DOM. There are just ::before and ::after words appearing. I think I have to solve that problem with some javascript tricks. unfortunately, I am new to javascript and I don't have any idea if you help me I would be very happy. Thank you! (I want to assert in some way that grey background and plus icon is shown or not)

generically look like that

enter image description here

after the mouse hovers this grey background and plus icon comes

enter image description here

you can see elements DOM here

enter image description here

you can see the changes after the mouse hovers element

enter image description here

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can use the cypress-real-events plugin. To install use the command:

npm i cypress-real-events

Then inside your cypress/support/e2e.{js,ts}, write:

import "cypress-real-events/support";

And in your code you can directly write:

cy.get("selector").realHover('mouse')
//Add assertions

Note: Since the above plugin uses Chrome DevTools Protocols to simulate native events, hence this will only work with Chromium-based browsers, so no firefox.

about 4 years ago · Juan Pablo Isaza Relatório

0

Into cypress' test try to use the method cy.wait("time here") following hover command. This is very simple but for visual test this is so useful.

about 4 years ago · Juan Pablo Isaza Relatório

0

In order to access the :before or :after of an element, we have to do a little Cypress and JavaScript magic. This is answer is mostly from this link.

cy.get('.myClass')
.then($els => {
  // get Window reference from element
  const win = $els[0].ownerDocument.defaultView
  // use getComputedStyle to read the pseudo selector
  const before = win.getComputedStyle($els[0], ':before')
  // read the value of the `content` CSS property
  const contentValue = before.getPropertyValue('content')
  
  // The above lines are just how we tell Cypress to get the `:before` value. 
  // There isn't a ton to understand outside of really diving into how elements and windows work together

  expect(content).to.equal('foo');
})

So, using that same example, we can check for any CSS property on the element. For example, font-size:

cy.get('.myClass')
.then($els => {
  const win = $els[0].ownerDocument.defaultView
  const before = win.getComputedStyle($els[0], ':before')
  const fontSize = before.getPropertyValue('font-size') // instead of `'font-size'`, you can substitute any CSS property
  expect(fontSize).to.equal('20');
})

This can also be applied to :after, changing out ($els[0], ':before') with ($els[0], ':after').

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda