英文:
How to test mat-stepper with Cypress
问题
我想使用Cypress测试mat-stepper
。
特别是我想验证特定的步骤是否当前已选择。
我尝试在mat-step
标记上放置了一个data-cy
属性,但这不会呈现在HTML上,因此我无法直接访问当前选择的步骤。
在Cypress中有没有一种方法可以验证哪个是当前选择的标头?
英文:
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?
答案1
得分: 0
我尝试了一种不同的方法。
而不是在标签上使用属性,我尝试与Angular模块进行交互。
it('检查选择的步骤', () => {
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);
}));
});
英文:
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);
}));
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论