TestCafe - 如何检查断言中的值是否大于或等于

TestCafe - How to check if the value is greater than or equal in the assertion

我想检查出现在下方选择器中的值是否大于或等于 1

<span class="badge badge-pill badge-white"> 0 </span>

(在步骤中,值“0”应该变为“1”或“2”..)

我在 common.js

中定义了这个选择器
this.pill = Selector('[class*=badge-white]');

并写下以下断言:

await t.expect((common.pill).innerText).gte(1);

我收到以下错误:“AssertionError: expected '1' to be a number or a date'。我不知道如何将 ((common.pill).innerText) 转换为数字?我试过了像这样的东西:

await t.expect(Number((common.pill).innerText)).gte(1);

但是不行。 当我检查该值是否深度等于例如“3”时,我写道:

await t.expect((common.pill).innerText).eql('3');

并且有效。 谁能帮助我如何检查大于或等于的值? 我仔细研究了但找不到解决方案https://devexpress.github.io/testcafe/documentation/guides/basic-guides/assert.html :(

我在创建const时找到了解决方案

const number = await common.pill.innerText;

await t.expect(Number(number)).gte(1);

有效!!!!!!!!!!!!!!!!!!!!

所以我的问题是为什么下面的代码不起作用

await t.expect(Number((common.pill).innerText)).gte(1);

您的代码

await t.expect(Number((common.pill).innerText)).gte(1);

不起作用,因为“Number”不期望未解决的承诺,所以是的,您需要按以下方式执行此操作:

const number = await common.pill.innerText;
await t.expect(Number(number)).gte(1);

这段代码

await t.expect((common.pill).innerText).eql('3');

之所以有效,是因为“expect”支持自动等待承诺。