【发布时间】:2019-04-30 12:42:49
【问题描述】:
我想用
cy.getByTestId(testId)
.should('have.attr', 'data-testStatus', 'OK')
.and('have.attr', 'opacity', '0');
和
cy.getByTestId(testId) 给我这个:
<circle class="js-components-SvgFiles-SvgBearingBlock-___SvgBearingBlock__featureSelected___RhROg"
cx="66.5" cy="66.5" r="29.925" stroke-width="0" opacity="0" data-testStatus="OK" data-testid="fixedBearing_Circle"></circle>
但我总是收到此错误消息:
expected <circle.js-components-SvgFiles-SvgBearingBlock-___SvgBearingBlock__featureSelected___RhROg> to have attribute data-testStatus
为什么.should(不使用外层html?
我已经测试了您的所有建议。不幸的是总是得到相同的结果:
[1]: https://i.stack.imgur.com/yhUlu.png
这是用 React 编写的代码:
return (
<svg className={cn(style.svg, className)} width={size} height={size}
data-testid={blockType+'_'+( isLeftSide?'Left':'Right')} data-testStatus={testIdPlane}>
{feature}
{/* id of the bearing*/}
<text
className={colorText}
x={textPos}
y={size * 0.85}
textAnchor="middle"
fontSize={fontSize}
fontWeight="bold"
>
{text}
</text>
{dummyText}
</svg>
);
那就是 React Code
我刚刚意识到这样的事情:
cy.getByTestId('slidingBearing_Line')
.should('have.attr', 'opacity', '1')
.and('have.attr', 'y')
.should('gt', y);
工作中
【问题讨论】:
-
是否可以使用 cypress 直接测试数据属性的存在?喜欢
.should('have.data', 'testStatus', 'OK')?
标签: javascript jquery reactjs redux cypress