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

376
Visualizações
Can't take screenshot of hovered element in Cypress

I'm trying to take a screenshot of an element with the hover effect, but the screenshots always come out without the hover effect.

    tableListMaps.lineWithText('Hello world', 'myLine');
    cy.get('@myLine').realHover().within(() => {
      highlightElement(commonMaps.BUTTON_DOWNLOAD_INLINE);
    });
    cy.screenshot('downloadScreenshot');

If I later on come back and hover over this element, I can see what I was trying to highlight was highlighted successfully, but it wasn't captured by the screenshot.

Is there a way I could "fixate" the hover effect?

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

0

Known limitation. See dmtrKovalenko/cypress-real-events docs:

  1. Why cy.realHover hovering state does not show in the visual regression services?

Unfortunately, visual regression services like Happo and Percy do not solve this issue. Their architecture is based on saving dom snapshot, not the screenshot, and then rendering the snapshot on their machines. It means that the hover and focus state will be lost if it won't be serialized manually.

It means that if you will use plain cy.screenshot it will take a screenshot with a hovering state because using the browser itself to make a screenshot. Testing hovering state is possible with, for example, Visual Regression Tracker and cypress-image-snapshot.

about 4 years ago · Juan Pablo Isaza Relatório

0

As pointed out by dmtrKovalenko in here:

Yeah this is likely impossible :) Cypress is doing some work in preparation between screenshot that will break hover

But I managed to do a workaround. The solution was to manually set the CSS expected in hovering state. Example:

    tableListMaps.lineWithText('Hello world', 'myLine');
    cy.get('@myLine').within(() => { 
      cy.get(commonMaps.BUTTON_DOWNLOAD_INLINE).then(($element) => {
        $element.css('visibility', 'visible');
      });
      highlightElement(commonMaps.BUTTON_DOWNLOAD_INLINE);
    });
    cy.screenshot('downloadScreenshot');

Since hovering over myLine would set the button visibility to "visible", what I did was just set it myself via CSS.

This way, I can take the screenshot as if the element was actually hovered. Then I set visibility to hidden again and background color to the original as well.

TL;DR: just simulate a hovering effect with CSS and take the screenshot.

cy.get(myElement).then(($element) => {
  $element.css('visibility', 'visible');
  $element.css('background-color', '#F2F2F2');
});
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