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

徘徊边缘 提交于 2019-12-21 12:39:03

问题


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) :

Here the description of the test failed -jenkins- :

Here the description of the test failed -casper- :

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).


回答1:


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 :

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 :

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 :)



来源:https://stackoverflow.com/questions/23468626/casperjs-jenkins-when-a-test-fails-how-to-retrieve-all-information-on-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!