请参阅以下代码。我正在尝试断言价值2,但我的代码不起作用。
Please see the below code.I am trying to assert value 2 but my code is not working.
你做这样的事情:
cy.get('#_evidon_message').should('contain.text', '2')
You do something like this:
基于您提供的信息,尚不清楚您是否要检查div中的整个文本,还是仅在Partners之前为数字检查。
div
Partners
如果您只想验证整个字符串中有一个2,那么:
2
cy.get('#_evidon_message') .invoke('text') .should('include.text', '2')
您也可以在字符串上使用Regex。
cy.get('#_evidon_message') .invoke('text') .then(text => { const regexMatcher = /(\d+) months with (?<numPartners>(\d+)) partners/i const numPartners = text.match(regexMatcher)?.group?.numPartners expect(numPartners).to.eq(2) })
Based on the information you provided, it isn't clear if you want to check the entire text within the div or just for the number before partners.
partners
If you only want to validate there is a 2 within the entire string, then:
You can use also use regex on the string as well.
粗体标签&lt; b&gt;正在干扰您的文本评估。实际上是内部的HTML,
&lt; b&gt;
cy.get('#_evidon_message').then($el => { const html = $el.html() console.log(html) // yields same as screenshot })
可以访问内部&lt; b&gt;使用其他命令,例如
cy.get('#_evidon_message') .find('b') .eq(2) .should('contain', '2')
The bold tags <b> are interfering with your text evaluation. It's actually HTML inside
<b>
To access the inner <b> use additional commands, for example
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(3)
你做这样的事情:
You do something like this:
基于您提供的信息,尚不清楚您是否要检查
div
中的整个文本,还是仅在Partners
之前为数字检查。如果您只想验证整个字符串中有一个
2
,那么:您也可以在字符串上使用Regex。
Based on the information you provided, it isn't clear if you want to check the entire text within the
div
or just for the number beforepartners
.If you only want to validate there is a
2
within the entire string, then:You can use also use regex on the string as well.
粗体标签
&lt; b&gt;
正在干扰您的文本评估。实际上是内部的HTML,可以访问内部
&lt; b&gt;
使用其他命令,例如The bold tags
<b>
are interfering with your text evaluation. It's actually HTML insideTo access the inner
<b>
use additional commands, for example