CasperJs + jenkins:当测试失败时,如何检索关于该测试的所有信息 [英] CasperJs + jenkins : when a test fails, how to retrieve all information on this test

查看:137
本文介绍了CasperJs + jenkins:当测试失败时,如何检索关于该测试的所有信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我想知道如何获取詹金斯考试失败的信息.

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

这是我的文件夹(fr)的结果(显示22分钟,但同时显示3分钟):

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

此处描述的测试失败-jenkins-:

Here the description of the test failed -jenkins- :

此处测试描述失败-casper-:

Here the description of the test failed -casper- :

所以我的问题是jenkins仅显示测试失败的消息,并且我还希望获得一些有用的信息,例如行和代码(实际上有控制台输出,但并不方便->我改变了我的想法,请参见使用Jenkins的xUnit:如何在构建控制台输出中显示颜色?,但我仍然希望在'Pile d'execution'/execution堆栈中显示信息.

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

推荐答案

我找到了解决方案,只需更改消息...:

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

错误恢复堆栈(带有test.begin)也被修改了.但是我不在乎詹金斯,所以我们可以使用if casper.cli.get('xunit') { casper.test.on('fail'){...} ;}这样的条件.

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

等等:

实际上相当简单……我应该有更好的搜索.

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

对于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
});

没有错误事件,但是此失败事件中具有不同的objects-properties-(与错误类型相比).因此,您可以按照自己的方式操作它们.但是我个人对消息,代码和行感兴趣(默认情况下,jenkins会以未定义的错误来管理它们).

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/

好吧,我做到了: https://github. com/n1k0/casperjs/pull/920

目的是单击jenkins中的链接并使用浏览器直接显示屏幕:)

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

这篇关于CasperJs + jenkins:当测试失败时,如何检索关于该测试的所有信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆