Testcafe: Test doesn't trigger hover with styled components

Created on 26 May 2019  路  11Comments  路  Source: DevExpress/testcafe

What is your Test Scenario?

I'm trying to hover an element (which uses styled components) and trigger a hover effect.

What is the Current behavior?

The virtual mouse is hovering the element but no hover effect has triggered.
(The element remains red)

What is the Expected behavior?

The virtual mouse should trigger a hover effect.
(The test should change the element from a red background to a blue background)

What is聽your web application and聽your TestCafe聽test code?

Component File

 const Demo = styled.span`
   width: 100px;
   height: 100px;
   background-color: red;
   &:hover{
      background-color: blue;
   }
`

Test File

const s = Selector("span")
await t.hover(s)

Note: When I extract the styling to a css file the test triggers the hover effect.

Your Environment details:

  • testcafe version: 1.1.0
  • node.js version: 10.13.0
  • command-line arguments: testcafe \"chrome --disable-background-timer-throttling\" e2e/{//,*/,}.e2e.js -S -s e2e/screenshots
  • browser name and version: Chrome 74
  • platform and version: Windows 10
level 2 automations bug

Most helpful comment

I'm seeing the same thing. I just switched from using Emotion to Styled-Components and one my E2E tests stopped working b/c of this.

All 11 comments

Even am looking for same thing. 馃憤

Hi @nir-welldone

Thank you for the provided detail. I've reproduced the problem.

For the team: to create a full example to reproduce, I used this tutorial;

I'm seeing the same thing. I just switched from using Emotion to Styled-Components and one my E2E tests stopped working b/c of this.

Same problem. Is it possible to find out whether the fix?

@abnorman23 , the fix is not available yet and we cannot provide any estimates on this issue. We keep it in mind and will update this thread as soon as the issue is solved.

Same issue :(

Same issue here.

+1

After upgrading to styled-components 5.1.0, everything worked ... before I was using 4.3.2

@TeaBough, thank you for sharing your findings with us.

To the team.
I researched the issue. It is caused by the fact that the styled-components module uses the window.CharacterData.prototype.appendData method to inject styles into the page. testcafe-hammerhead does not override this method, so the element[data-hammerhead-hovered] style is not injected into the page.
I overrode the appendData method in the testcafe-hammerhead module as follows:

            appendData (...args) {
                var textNode = document.createTextNode(args[0]);

                return sandbox._addNodeCore({
                    parentNode: this.parentNode,
                    nativeFn:   nativeMethods.appendChild,
                    checkBody:  true,

                    args: [textNode]
                });
            },

After that, the test behaves as expected.

Was this page helpful?
0 / 5 - 0 ratings