question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clicks handled differently in headless vs. headed (React + Material UI use case)

See original GitHub issue

Current behavior:

I have test cases that click on a styled select and then click on an item in the resulting menu. When I run my tests headed, using npx cypress open, with either Chrome or Electron, the click events happen almost instantly, as expected. However, when I run the same tests headlessly, with npx cypress run, each select item click takes “timeout” seconds to complete the click. This leads to a very slow test suite when timeout is a few seconds and I have hundreds of such clicks.

Here is a video showing the headless run and unexpected behavior:

https://youtu.be/MCbIhEoN7Is

You will see the down click seems to be initiated immediately (the ripple is triggered), but it takes “timeout” ms to complete the click. (I set the defaultCommandTimeout config option to 10,000 to exaggerate the problem.)

Desired behavior:

Here is a video showing the headed run and expected behavior: https://youtu.be/vVzrdBvhnlg

Steps to reproduce:

I’m using React with Material UI. Here is the component under test in the videos:

import React, { Component } from 'react';
import TextField from '@material-ui/core/TextField';
import MenuItem from '@material-ui/core/MenuItem';

const items = ['Item 1', 'Item 2', 'Item 3'];

class App extends Component {
  state = { item: null };

  handleChange = e => this.setState({ item: e.target.value });

  render() {
    return (
      <div>
        <TextField
          select
          label="Item"
          value={this.state.item}
          onChange={this.handleChange}
          data-cy="select"
        >
          {items.map(item => (
            <MenuItem value={item} key={item} data-cy="menu-item">
              {item}
            </MenuItem>
          ))}
        </TextField>
        <p data-cy="selected-item-label">Selected: {this.state.item || 'None'}</p>
      </div>
    );
  }
}

export default App;

And here is the spec:

describe('Material UI Component Tests', () => {
  beforeEach(() => cy.visit('http://localhost:3001'));
  [0, 1, 2, 1, 0].forEach((i) => {
    it(`should select item ${i} quickly`, () => {
      cy.get('[data-cy="select"]').click()
      cy.get('[data-cy="menu-item"]').eq(i).click()
      cy.get('[data-cy="selected-item-label"]')
        .contains(`Selected: Item ${i + 1}`)
    })
  })
})

Versions

Cypress 3.0.1 Electron 59

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kucebcommented, Jun 11, 2018

@harvitronix can you see if this is an active window issue, by running cypress run --browser chrome and then quickly clicking on a different window to take focus away from cypress? We’ve seen some specs fail in this case

0reactions
jennifer-shehanecommented, Jul 2, 2019

Hey @medric, please create a new issue detailing exactly how to reproduce the issue and we can look at it. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Autocomplete component - Material UI - MUI
For advanced customization use cases, a headless useAutocomplete() hook is exposed. It accepts almost the same options as the Autocomplete component minus ...
Read more >
Headless components in React and why I stopped using a UI ...
In this blog post I'll focus on what I learned when building Gloat's design system and how I moved from using UI libraries...
Read more >
Your First App using Material UI - Refine Dev
Alternatively, you may use the create-react-app tool to create an empty React ... to consume different API's and data services conveniently.
Read more >
What I wish I had known about single page applications
I settled on JHipster, a development platform for building web applications using modern technology: Angular, React or Vue for the client side, ...
Read more >
How to create a multilevel dropdown menu in React
Multilevel menus are designed to reveal the deeply nested navigations when we click or hover over the submenu items, as shown in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found