Automation 将alias设置为出现两次的元素会在alias值中添加一个空格
我正在设置别名值,然后比较它们,但我遇到了一个问题,因为元素在同一顶级类中列出了两次。这会导致别名值为“最新”,Cypress会自动添加一个空格。我想我可以先说.first(),然后给它加上别名,但它仍然增加了一个空格 这是我的密码:Automation 将alias设置为出现两次的元素会在alias值中添加一个空格,automation,cypress,Automation,Cypress,我正在设置别名值,然后比较它们,但我遇到了一个问题,因为元素在同一顶级类中列出了两次。这会导致别名值为“最新”,Cypress会自动添加一个空格。我想我可以先说.first(),然后给它加上别名,但它仍然增加了一个空格 这是我的密码: cy.get('[data-automation="data-row-value-currentVersion"]') .first() // using first() b/c UpdatedBy nested b
cy.get('[data-automation="data-row-value-currentVersion"]')
.first() // using first() b/c UpdatedBy nested block repeats the current version value
.invoke('text').then(currentVersion => {
cy.wrap(currentVersion).as('currentVersion');
});
cy.get('[data-automation="active-version"]')
.invoke('text').then(activeVersion => {
cy.wrap(activeVersion).as('activeVersion');
});
cy.get('@activeVersion').then(activeVersion => {
cy.get('@currentVersion').then(currentVersion => {
cy.log(`-${activeVersion}-`);
cy.log(`--${currentVersion}--`);
expect(activeVersion).to.eq(currentVersion);
});
});
});
断言失败是因为Cypress自动添加了空间。cy.logs只是为了让我真正看到别名是什么值
有什么想法吗?怎么样
cy.wrap(currentVersion.trim())
我试过了,但没有成功:(更新:我将其更改为字符串文字格式,然后使用.trim(),效果良好!expect(${activeVersion.trim()}
).to.eq(${currentVersion.trim()}
);