【问题标题】:Custom function in testcafetestcafe 中的自定义函数
【发布时间】:2018-11-13 08:19:07
【问题描述】:

所以,我正在尝试创建一个自定义函数,允许我检查字段是否包含数字或文本,但为了进一步测试,我需要检查更复杂的内容,例如某个表的总和是否等于东西之类的 我找不到自定义函数的示例,例如:

function isNumber(n) {
  let a = parseInt(n);
  if (a > 0 || a < 0) {
    return true
  } 
  return false
}
test('Test example', async t => {
  await t
      .expect(isNumber(Selector('#thisNum').innerText)).ok('This is a number' );
    
});

【问题讨论】:

    标签: javascript testing automated-tests e2e-testing testcafe


    【解决方案1】:

    断言消息只会显示when the assertion fails(参考message参数)。例如,

    await t
      .expect(failingValue).ok('failingValue is not a number');
    

    在测试失败时会显示如下内容:

    1) AssertionError: failingValue is not a number: expected false to be truthy
    

    因此,我从没想过会看到“这是一个数字”消息。

    至于函数,我遇到过几次承诺尚未解决的情况,因此请尝试等待数字选择器:

    await t
      .expect(isNumber(await Selector('#thisNum').innerText)).ok('This is a number');
    

    希望这会有所帮助。

    【讨论】:

    • 谢谢亚历克斯!最后我决定使用 cypress.js 但你的解决方案似乎很有魅力
    猜你喜欢
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多