Fernando G
Fernando G

Reputation: 21

How show time for each test with casperjs

I have a "launcher" script with one array, with all names and routes of many tests. When I run all tests, casper only shows the total time of run all tests. I need show how much time needs each test script, does casperjs have any method for do this?

When param 'all' is used, I run all tests.

var testsPaneles = [
    ["Panel1", "./Paneles/testPanel1.js"],
    ["Panel2", "./Paneles/testPanel2.js"]
]

if (casper.cli.get('arg') == 'all') {
    casper.start()
        .then(function() {
        casper.test.begin('Bateria de pruebas ', function suite(test) {
            for (i = 0; i < testsPaneles.length; i++) {
                var prueba = require(testsPaneles[i][1]);
                prueba();
            }
        });
    }).run(function() {
        this.test.done();
    });
}

Result:

# Bateria de pruebas Panel Operador
# Test Panel Oper - Clientes
PASS Input Usuario
PASS Input Password
# Test Panel-Oper - Portfolio
PASS Input nombre usuario
PASS Input pass usuario
PASS 4 tests executed in 4.23s, 4 passed, 0 failed, 0 dubious, 0 skipped.

And i want, something like this:

# Bateria de pruebas Panel Operador
# Test Panel Oper - Clientes
PASS Input Usuario
PASS Input Password
**Time: 1.59s**
# Test Panel-Oper - Portfolio
PASS Input nombre usuario
PASS Input pass usuario
**Time: 2.24s**
PASS 4 tests executed in 4.23s, 4 passed, 0 failed, 0 dubious, 0 skipped.

Upvotes: 0

Views: 909

Answers (1)

Fernando G
Fernando G

Reputation: 21

Finally i solved this using this function in launcher.js

var start = Date.now();
casper.test.on('success', function tiempo() {
    casper.echo(Date.now()-start + "ms");
    start = Date.now();
});

This function is started when each test run the event "success".

Upvotes: 2

Related Questions