【发布时间】:2019-10-25 09:04:50
【问题描述】:
我需要帮忙。我有控制某个值是否大于其他值的代码。
看起来像这样:
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č”)吗?
我试图将文本解析为浮动,但结果不佳。
感谢您的所有帮助。
【问题讨论】:
-
也许最简单的是
$span.text().slice(0, -3),见JavaScript chop/slice/trim off last character in string。
标签: automation automated-tests cypress