如何在测试中更详细?

时间:2019-07-08 09:59:03

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

我希望每个测试步骤都有更多详细的输出;
在每个步骤之后不添加console.log的情况下,如何最好地实现这一点的任何想法?

我试图重载t对象,如下所示,但在输出中不能使其多次工作。

在mylib.js中

exports.init = function(t) {
    t.oTypeText = t.typeText;

    t.typeText = function fn(selector, data, opts) {
        console.log('typing text in '+selector+': '+data);
        return t.oTypeText(selector, data, opts);
    };

    return;
};

在test.js中

import { Selector } from 'testcafe';
const mylib = require('./mylib');


fixture("Getting Started")
    .page("https://devexpress.github.io/testcafe/example");


test('My first test', async t => {
    mylib.init(t);
    await t.typeText('#developer-name', 'John Smith')
           .selectText('#developer-name').pressKey('delete')
           .typeText('#developer-name', 'new name')
           .selectText('#developer-name').pressKey('delete')
           .typeText('#developer-name', 'another name');
    await t.click('#submit-button');

});

结果是:

Using locally installed version of TestCafe.
 Running tests in:
 - Firefox 68.0.0 / Mac OS X 10.14.0

 Getting Started
(node:62978) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
typing text in #developer-name: John Smith
 ✓ My first test


 1 passed (4s)

1 个答案:

答案 0 :(得分:1)

TestCafe不支持此功能。我已经为您的用例(TestCafe存储库)中的https://github.com/DevExpress/testcafe/issues/4001创建了建议。我们现在可以使用具有操作覆盖功能的方法,但是从理论上讲它可以破坏某些功能。