testcafe中的自定义功能

时间:2018-11-13 08:19:07

标签: javascript automated-tests e2e-testing testcafe

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

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

1 个答案:

答案 0 :(得分:7)

断言消息将仅显示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');

希望这会有所帮助。

相关问题