簡體   English   中英

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);

不起作用,因為“數字”不期望未解決的承諾,所以是的,您需要按如下方式執行此操作:

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

這段代碼

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

之所以有效,是因為“expect”支持自動等待承諾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM