Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CasperJs + jenkins : when a test fails, how to retrieve all information on this test

Well , I would like to know how to get back the information of a test failed in jenkins.

Here the result of my folder (fr) (it displays 22 min. but in parallel it's 3min) :

jenkinsResult

Here the description of the test failed -jenkins- :

jenkins-casperJs test failed-

Here the description of the test failed -casper- :

casperjs test failed

So my problem is jenkins displays only the message of the test failed, and I would like to have also useful information as line and code (in fact there is the console output but it's not convenient-> I've changed my mine, it is, see xUnit with Jenkins: how to display colors in the Build Console Output?, but I still want the information in the 'Pile d'exécution'/execution stack).

like image 250
Fanch Avatar asked May 05 '14 09:05

Fanch


1 Answers

I found a solution, just change the message ... :

casper.test.on("fail", function(failure) {
    failure.message = "Message : " + failure.message + "\nLine : "+ failure.line + "\nCode : " + failure.lineContents;
});

The error resume stack (with test.begin) is also modified though. But I don't care in jenkins, so we can use a condition like if casper.cli.get('xunit') { casper.test.on('fail'){...} ;}.

And so :

Solution Rather simple actually ... I should have better search.

For Artjom :

In fact for errors it's quite verbose so I don't think there are changes to do, see : error Casper

But you can still customize it the same way and it could be something like that :

casper.test.on("fail", function(failure) {
    //if error type undefined function
    if(failure.message.message){//or failure.message.stack.TypeError
        failure.message.message = "Message : " + failure.message.message + "\nLine : "+ failure.message.line;//in jenkins -> title
    }
    //else assert error
    else{failure.message = "Message : " + failure.message + "\nLine : "+ failure.line + "\nCode : " + failure.lineContents;}
    
    //console.log(JSON.stringify(failure,4,'\t')); //see parameters you can modify in the failure object
});

There isn't an error event, but different objects-properties- (compared to the type of error) in this fail event. So you can manipulate them in the way you want. But personally I'm interested by the message, the code and the line (and by default jenkins manages them with undefined error).

Now I'm working on a way to display also the screenshot path, to have something like that :

Message : No notice on the page
Line : 83
Code : this.test.assertTextDoesntExists('Notice', 'No notice on the page');
Screenshot : http://-jenkins-/job/-myJob-//lastFailedBuild/artifact/screenshots/fail0.png/

Well, I did it: https://github.com/n1k0/casperjs/pull/920

The aim is to click on the link in jenkins and display screen directly using the browser :)

like image 85
Fanch Avatar answered Oct 13 '22 20:10

Fanch