【问题标题】:Assertion always return err (expected 'a' to deeply equal 'a')断言总是返回 err(期望 'a' 完全等于 'a')
【发布时间】:2018-10-18 15:19:24
【问题描述】:

我在这里做一个简单的测试,但是我看到很多人偶然发现了这个问题,但不幸的是,我无法找到解决方案,因此,我征求您的意见. 现在,我有这个字符串对象,在一个链接中:

...
<div class="price">12,45&nbsp;€</div>
...

我创建了这个小测试,检查字符串值:

import { t, Selector } from 'testcafe';
fixture `OfferPage`.page `https://www.verivox.de/applications/broadband/#/offer?i=eyJmaWx0ZXIiOltudWxsLDE2MDAwLDEsbnVsbCwiMDIyMSIsMSwxLDEsbnVsbCwxLDEsbnVsbCwtMSxudWxsLG51bGwsInByaWNlLWFzYyIsMixudWxsLG51bGwsbnVsbCxudWxsLG51bGwsbnVsbCxudWxsLG51bGwsNl0sImRpYWxvZyI6W251bGxdLCJvZmZlckNyaXRlcmlhIjpbIjYxMzQ0NyIsIjE4MjkyIixudWxsLCIyNCIsMywyLCI1MDAwMCIsIjEwMDAwIixudWxsLG51bGwsMSxudWxsLG51bGwsbnVsbCwiMiIsMSxudWxsLCIwMjIxIixudWxsLG51bGwsbnVsbCxudWxsLG51bGwsMSw2LG51bGwsbnVsbCxudWxsXX0%3D`;
test('1', async () => {
    const string = Selector('div.price');
    await t.expect(string.innerText).eql('12,45 €');
});

我在终端中遇到的错误是这个:

AssertionError: expected '12,45 €' to deeply equal '12,45 €'

我真的试图找到一个解决方案,但是要么我将 const 的定义更改为 let 并尝试应用其他方法,但最终都会出现失败错误,并显示不同的错误消息。 那么,在上述情况下,我该如何解决? 谢谢!

编辑:感谢您的提示!我编辑了这篇文章,因为我意识到我没有提到我已经尝试过你的建议......

let price = Selector('div').withAttribute('class', 'price');
const result = price.parent('div.centered-content effective-price-wrapper');
console.log(result);
await t.expect(result.innerText).eql('12,45 €');

错误:

Cannot obtain information about the node because the specified selector does not match any node in the DOM tree.

再试一次:

const string = await Selector('div.price')();
let pret = await Selector(string).innerText;
const rgx = /&nbsp;/gi;
await t.expect(pret.replace(rgx, '')).eql('12,45 €'.replace(rgx, ''));

错误

 AssertionError: expected '12,45 €' to deeply equal '12,45 €'

我的想法已经用完了:)

【问题讨论】:

  • 不间断空格 (&amp;nbsp;) 与“普通”空格不同
  • 谢谢,我已经编辑了帖子,因为我也处理过这个案例,但没有成功。

标签: typescript automated-tests assert e2e-testing testcafe


【解决方案1】:

这个问题与nonbreaking space有关。

以下eql assertion 应该在您的场景中正常工作:

await t.expect(string.innerText).eql('12,45\xa0€');

【讨论】:

    【解决方案2】:

    您的特定测试用例的问题是 &amp;nbsp; 未被 Testcafe 解释为常规空间。

    如果您从收到的错误消息中复制12,45 €,然后将其作为预期值粘贴到代码中,就可以了。

    【讨论】:

    • '不知何故',因为它们不是一回事。
    • 谢谢,我已经编辑了帖子,因为我也处理过这个案例,但没有成功。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 2021-09-10
    • 1970-01-01
    相关资源
    最近更新 更多