有没有办法在 IResultListener 方法之前运行 @after 方法? [英] Is there a way to run @after method before IResultListener methods?

查看:32
本文介绍了有没有办法在 IResultListener 方法之前运行 @after 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个监听器,它实现了 IResultListener2 的 onTestSuccess 和 onTestFailure 方法.在我的测试中,我在 @after 注释方法中创建了屏幕截图,这是侦听器需要的.但是 testng 在 @after 方法之前调用侦听器中的方法.

I have an listener which implements the methods onTestSuccess and onTestFailure of IResultListener2. In my test I create screenshots in an @after annotated method, which were needed by the listener. But testng calls the methods in the listener before the @after method.

有没有参数先运行@after方法?

Is there a parameter to run the @after method first?

推荐答案

AFAIK,没有这种参数.after 方法将特定于一组特定的情况.您是否不希望为您的所有案例而不是特定集执行捕获屏幕截图的逻辑?在这种情况下,您的屏幕截图捕获逻辑应该在您的侦听器方法中,并且您的特定案例集的任何清理逻辑都应该在方法之后.
如果你想在你的 aftermethods 之后做一些特定的事情,那么你可以尝试实现 IconfigurationListener,并在检查调用方法是一个 aftermethod 之后实现这些方法,比如..

AFAIK, there is no parameter of such kind. An after method would be specific to a particular set of cases. Wouldn't you want that the logic to capture your screenshots be executed for all your cases and not a specific set? In which case, your screenshot capturing logic should be in your listener methods and any cleanup logic for your specific set of cases should be in after methods.
If there is something specific that you want to do after your aftermethods, then you can try implementing IconfigurationListener, and implement those methods after checking that the invoking method is an aftermethod, something like..

public void onConfigurationSuccess(ITestResult arg0) {
    if(arg0.getMethod().isAfterMethodConfiguration())...do something;

}

希望有帮助..

这篇关于有没有办法在 IResultListener 方法之前运行 @after 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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