TestNG:如何获取当前执行的组 [英] TestNG: How to get the current executed group
本文介绍了TestNG:如何获取当前执行的组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法获取当前正在执行的组的名称?
Is there a way to get the name of the group that is being currently executed?
我试过了:
@BeforeMethod
public void beforeMethod(ITestContext context) {
groups = context.getCurrentXmlTest().getIncludedGroups();
}
但这给了我当前运行方法支持的所有组,而不是当前正在执行的组.
but this gives me all the groups that the current running method supports, not the current one being executed.
推荐答案
现在回答这个问题,因为这个问题在一个类似的问题中被标记,但具有不同的用例.因此,这可能对任何寻找答案的人都有帮助:
Answering now as this question was tagged in a similar question but with a different use-case. So this might be helpful to anyone searching for an answer:
这是一种解决方法:不要获取 getIncludedGroups
,而是使用 getName
并执行以下操作:
This is kind of a workaround:
Instead of getting getIncludedGroups
, use getName
and do the following:
@BeforeMethod(groups = {"one", "two"} )
public void beforeMethod(ITestContext ctx) {
String name = ctx.getCurrentXmlTest().getName();
if(name.contains("GRP")) {
String grpName = name.split("GRP-")[1];
if(grpName.equals("one")) {
// ......
} else {
// .....
}
}
}
这篇关于TestNG:如何获取当前执行的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文