简体   繁体   English

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

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

I would like to check the value which appears in below selector if it is greater than or equal to 1我想检查下面选择器中出现的值是否大于或等于 1

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

(In steps, the value "0" should change into "1" or "2"..) (在步骤中,值“0”应更改为“1”或“2”..)

I defined this selector in common.js我在 common.js 中定义了这个选择器

this.pill = Selector('[class*=badge-white]');

and wrote the following assertion:并写了以下断言:

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

I received the following error: " AssertionError: expected '1' to be a number or a date'. I do not know how to convert ((common.pill).innerText) to number? I tried sth like this:我收到以下错误:“AssertionError: expected '1' to be a number or a date'。我不知道如何将 ((common.pill).innerText) 转换为数字?我试过这样的东西:

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

But it does not work.但它不起作用。 When I check if the value is deep equal eg."3"i write:当我检查该值是否深度等于例如“3”时,我写道:

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

And it works.它有效。 Could anybody help me how to check value greater than or equal?谁能帮助我如何检查大于或等于的值? I studied it thoroughly but I can't find a solution https://devexpress.github.io/testcafe/documentation/guides/basic-guides/assert.html :(我彻底研究了它,但找不到解决方案https://devexpress.github.io/testcafe/documentation/guides/basic-guides/assert.html :(

I found a solution when created const我在创建 const 时找到了解决方案

const number = await common.pill.innerText;

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

It works!!!!!!!!!!!!!!!!!!有用!!!!!!!!!!!!!!!!!!

so my question is why below code did not work所以我的问题是为什么下面的代码不起作用

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

Your code你的代码

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

does not work because 'Number' does not expect unresolved promises, so yes, you need to do this as follows:不起作用,因为“数字”不期望未解决的承诺,所以是的,您需要按如下方式执行此操作:

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

This code这段代码

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

works because 'expect' supports awaiting promises automatically.之所以有效,是因为“expect”支持自动等待承诺。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM