How to test mat-stepper with Cypress

Simone Brognoli

I want to test mat-stepper with Cypress.

In particular I want to verify that a particular step is currently selected or not.

I have tried to put a data-cy attribute on the mat-step tag, but this is not rendered on HTML, so I can not access directly to the current selected step.

Example of stepper I want to test

Is there a way in Cypress where I can verify which is the selected header?

Simone Brognoli

I've tried a different approach.

Instead of using an attribute on the tag, I try to interact with the Angular module

it('Check selected step', () => {
cy.visit(pageToVisit);
let angular: any;
cy.window()
  .then((win) => angular = win.ng)
  .then(() => cy.document()
    .then((doc) => {
      const componentInstance = angular.getComponent(doc.querySelector('mat-stepper'));
      expect(componentInstance._selectedIndex).to.equal(wantedIndex);
    }));
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to hide mat-stepper header in my mat-stepper?

Check mat-checkbox within cypress test

How to show that the last mat-step is complete in mat-stepper?

How to test an Alert with Cypress

How to change the angular material mat stepper label color?

How to replace next button with mat-chip in Angular Material stepper?

How to Disable/Stop HostListener if any document is opened before mat stepper?

Angular Material: How to set each mat-horizontal-stepper stepper icon with different background color in TS

Cypress test seems to 'ignore' mat-paginator pageSize

Cypress test is not working for focus state for mat-checkbox in Angular

How to test file inputs with Cypress?

How to test the children of an element in cypress?

How to test if there is a word in the sentence with cypress?

How to test for access prohibited in Cypress?

How to test a bad request in cypress

How to test for a broken image in Cypress

mat stepper bar is not in the npm registry

How to stub contentwindow.print with cypress/test printJS with cypress

How to dynamically generate test cases in Cypress?

How to access getbbox on a svg element in a cypress test

How to send an email with test report in Cypress

How to switch Angular Tab in a Cypress Test

How to repeat a test in Cypress multiple times?

How to reload the first test case if it fails in cypress

How to set an environment variable during a Cypress test?

Using Cypress, how to test for an element not existing?

How to automatically delete every failing Cypress test?

How to run the same test with different fixtures in Cypress?

How to test the text of the second element in cypress?