如何断言在柏树中分开的数字
在应用程序上编写测试时,我遇到了一个问题。
我需要从DOM的跨度内获取一个数字,然后断言数字是否在特定范围之间。 我可以通过使用
cy.get('#my_selector').invoke('text').should('be.gt',lower_bound).and('be.lt',upper_bound)
,但问题是逗号分隔的数字像5,000一样分开。我会遇到一个错误,因为“预期的5,000'为数字或日期”
是否有任何简单的简短方法将其转换为纯数字
While writing tests on an application I have came across a problem.
I need to fetch a number inside a span from the DOM and then assert if the number is between a specific range.
I can do it by using
cy.get('#my_selector').invoke('text').should('be.gt',lower_bound).and('be.lt',upper_bound)
But the issue is the number is comma separated like 5,000. and I'm getting an error as "expected '5,000' to be a number or a date"
Is there any simple short way to convert it into pure numeric
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
string.replaceall()
删除“”,然后parseint()
You can use
string.replaceAll()
to remove the "," thenparseInt()
您可以使用javascript
替换
方法来删除逗号,然后添加+
将其转换为数字,例如:You can use the javascript
replace
method to remove the comma and then add a+
to convert it into a number, like: