Unable to Select Menu Item in Cypress Test
# i-need-help
a
Description: When attempting to select the menu item 'Admin' using the Cypress test, the following error occurs: Error: Timed out retrying after 10000ms: Cannot read properties of undefined (reading 'toLowerCase') Steps to Reproduce: 1. Run the Cypress test with the scenario 'When I select the "Admin" Menu'. 2. Observe the Cypress Test Runner GUI. Expected Result: The menu item 'Admin' should be successfully selected without any errors. Actual Result: The test fails with a timeout error, indicating that properties of undefined cannot be read. This issue occurs when trying to locate the menu item element using the
[label="Admin"]
selector. Additional Information: - The relevant code snippet used to select the menu item is as follows: testFile.js
Copy code
javascript
import { When } from 'cypress-cucumber-preprocessor/steps';
import { adminPageDefinitions } from './adminPageDefinitions';

When('I select the {string} Menu', (sideMenu) => {
  adminPageDefinitions.selectMenu(sideMenu);
});
adminPageDefinitions.js
Copy code
javascript
import adminPage from './adminPage';

export const adminPageDefinitions = {
  selectMenu(sideMenu) {
    cy.get(adminPage.pageElements.sideMenu(sideMenu))
      .should('be.visible')
      .click();
  },
};
adminPage.js
Copy code
javascript
const adminPage = {
  pageElements: {
    sideMenu(sideMenu) {
      return cy.get(`[label="${sideMenu}"]`);
    },
  },
};

export default adminPage;
- The error occurs at the line
cy.get(adminPage.pageElements.sideMenu(sideMenu)).should('be.visible').click();
in the
adminPageDefinitions.js
file. - The error suggests that the
sideMenu
parameter is undefined or does not match any elements on the page. - Manually inspecting the page confirms that the menu item with the label "Admin" exists and is visible. - The timeout error indicates that the menu item is not being located within the specified timeframe.