Automation Cypress-从常量中删除文本

Automation Cypress-从常量中删除文本,automation,automated-tests,cypress,Automation,Automated Tests,Cypress,我需要帮忙。我有一个控制某个值是否大于另一个值的代码 看起来是这样的: cy.get(':nth-child(1) > .offer-block > :nth-child(1) > .flex-col > .offer-price').then(($span) => { // capture what num is right now const num1 = $span.text(); cy.get(':nth-c

我需要帮忙。我有一个控制某个值是否大于另一个值的代码

看起来是这样的:

cy.get(':nth-child(1) > .offer-block > :nth-child(1) > .flex-col > .offer-price').then(($span) => {
        // capture what num is right now
        const num1 = $span.text();

        cy.get(':nth-child(2) > .flex-column').click();
        cy.wait(5000);
        cy.get(':nth-child(1) > .offer-block > :nth-child(1) > .flex-col > .offer-price').then(($span) => {
          // now capture it again
          const num2 = $span.text();

          // make sure it's what we expected
          expect(num1).to.be.greaterThan(num2);
        });
    });
问题是,保存的文本不仅仅是简单的数字,而且总是以“Kč”结尾。有没有办法删除这段文字(“Kč”)

我试图将文本解析为float,但结果不太好


感谢您的帮助。

这里有一个快速破解程序,可以解析字符串中的数字:

description('test',()=>{
它('test',()=>{
cy.document().然后(doc=>{
doc.body.innerHTML=`
7 201 Kč
7. 201 Kč
`;
});
cy.get('.test')。每个($el=>{
const number=parseInt(
$el.text()
//匹配编号,包括空格作为编号
//分离器
.match(/([\d\s]+|$)/)[1]
//删除非数字字符
.替换(/[^\d]/g',),
//解释为base-10
10
);
预计(数量)为5000总吨;
});
});
});

最简单的可能是
$span.text().slice(0,-3)
,请参阅。