赛普拉斯断言.should()失败了

问题描述 投票:0回答:2

我想用

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);

工作中

javascript jquery reactjs redux cypress
2个回答
0
投票

无法重现以下内容:

describe('test', () => {
    it('test', () => {
        cy.document().then( doc => {
            doc.body.innerHTML = `<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>`;
        });

        cy.get('[data-testid="fixedBearing_Circle"]')
            .should('have.attr', 'data-testStatus', 'OK')
            .and('have.attr', 'opacity', '0');
    });
});

你能分享更多代码吗?


0
投票

请尝试以下代码。

cy.get('[data-testid="fixedBearing_Circle"]')
    .should('have.attr', 'data-testStatus', 'OK')
    .and('have.attr', 'opacity', '0');

截图:Screenshot of the result

© www.soinside.com 2019 - 2024. All rights reserved.